Skip to content

Commit

Permalink
dynamic splash screen version
Browse files Browse the repository at this point in the history
  • Loading branch information
codezerro committed Nov 8, 2024
1 parent 98f0813 commit b3a80a2
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "RoboticsAcademy",
"version": "2.0.0",
"version": "2.3.3",
"description": "Cross platform Desktop Application for Robotics Academy.",
"main": "./out/main/index.js",
"author": "Robotics Academy",
Expand Down
2 changes: 1 addition & 1 deletion splashscreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h2 style="margin: 0px">Robotics Academy</h2>
<p class="developer">by <span class="orginzationText">JdeRobot</span></p>
</div>
<img src="./resources/loading.svg" class="loading-dots" />
<p class="version">v2.0.0</p>
<p id="version" class="version">v2.0.0</p>
</div>
</body>
</html>
4 changes: 2 additions & 2 deletions src/main/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const insertCommandData = async (db: sqlite3.Database) => {
if (err) {
console.error('Error creating table: ' + err.message)
} else {
console.log('commands Table created or already exists.')
// console.log('commands Table created or already exists.')

try {
const checkTableExist = await isTableExit(db, `commands`)
Expand Down Expand Up @@ -248,7 +248,7 @@ export const insertCommandUtilsData = async (db: sqlite3.Database) => {
if (err) {
console.error('Error creating table: ' + err.message)
} else {
console.log('commands_utils Table created or already exists.')
// console.log('commands_utils Table created or already exists.')

try {
const checkTableExist = await isTableExit(db, `commands_utils`)
Expand Down
45 changes: 42 additions & 3 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { app, BrowserWindow, ipcMain, IpcMainInvokeEvent, shell } from 'electron
import { join } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import { Database } from 'sqlite3'
import { autoUpdater, AppUpdater } from 'electron-updater'
import { autoUpdater } from 'electron-updater'

import {
AllCommandConfigureInterface,
Expand Down Expand Up @@ -33,6 +33,7 @@ import {

const isMac = process.platform === 'darwin'
let mainWindow: BrowserWindow | null = null
const appVersion = `v${app.getVersion()}`

// disable auto-update download
autoUpdater.autoDownload = false
Expand All @@ -47,14 +48,35 @@ function createSplashWindow(): BrowserWindow {
height: 300,
frame: false,
transparent: true,
alwaysOnTop: true
alwaysOnTop: true,
webPreferences: {
nodeIntegration: false,
webSecurity: true,
sandbox: false,
contextIsolation: true
}
})

const splashScreenSrc = app.isPackaged
? join(process.resourcesPath, 'splashscreen.html')
: join(__dirname, './../../', 'splashscreen.html')

win.loadFile(splashScreenSrc)

win.webContents.on('did-finish-load', () => {
win.webContents
.executeJavaScript(
`
const version = document.getElementById('version')
version.textContent = '${appVersion}'
`
)
.then((result) => {
console.log('Executed in renderer:', result)
})
.catch(console.error)
})

return win
}

Expand Down Expand Up @@ -140,6 +162,23 @@ app.whenReady().then(async () => {
})

//* IPC COMMUNICATION
//@ Utils
// get api version
ipcMain.handle('app:APP_VERSION', async (_event: IpcMainInvokeEvent) => {
try {
return {
status: ResponseStatus.SUCCESS,
data: `${app.getVersion()}`,
msg: []
}
} catch (error: any) {
return {
status: ResponseStatus.SUCCESS,
data: null,
msg: ['something went wrong!', `${error.message}`]
}
}
})
//@ Stopping Docker RADI
ipcMain.handle('docker:CHECK_RADI_RUNNING', async (_event: IpcMainInvokeEvent) => {
try {
Expand Down Expand Up @@ -174,7 +213,7 @@ app.whenReady().then(async () => {
const res: ResponeInterface = await stopDockerRADIContainer()
return res
} catch (error) {
return { status: false, msg: ['something went wrong!'] }
return { status: ResponseStatus.ERROR, msg: ['something went wrong!'] }
}
})

Expand Down
9 changes: 8 additions & 1 deletion src/preload/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { PortsInterface } from './../renderer/src/utils/interfaces'
import { ElectronAPI } from '@electron-toolkit/preload'
import { AllCommandConfigureInterface, DatabaseFetching } from './../main/interfaces'
import {
AllCommandConfigureInterface,
DatabaseFetching,
ResponeInterface
} from './../main/interfaces'
interface ApiInterface {
// Util
getAppVersion: () => Promise<ResponeInterface>
// Docker
checkDockerAvailability: () => Promise<ResponeInterface>
checkDockerRADIAvailability: () => Promise<ResponeInterface>
startDockerRADIContainer: () => Promise<ResponeInterface>
Expand Down
3 changes: 3 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {

// Custom APIs for renderer
const api = {
// Utils
getAppVersion: (): Promise<ResponeInterface> => ipcRenderer.invoke('app:APP_VERSION'),
// Docker
checkDockerAvailability: (): Promise<ResponeInterface> =>
ipcRenderer.invoke('docker:CHECK_AVAILABILITY'),
checkDockerRADIAvailability: (): Promise<ResponeInterface> =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { RightArrowIcon, BackIcon, PowerIcon, GameConsoleIcon, PlayIcon } from '
import Loader from '../utlits/Loader'
import ButtonWrapper from '../buttons/ButtonWrapper'
import styles from '../../assets/styles/styles'
import { ActionEnums, ButtonEnums, ScreenStateEnums } from '@renderer/utils/enums'
import { ActionEnums, ButtonEnums, ResponseStatus, ScreenStateEnums } from '@renderer/utils/enums'
import { ReducerActionTypes } from '@renderer/utils/types'
import { ResponeInterface } from '@renderer/utils/interfaces'
interface StartScrrenButtonsInterface {
buttonState: string
dispatch: Dispatch<ReducerActionTypes>
Expand All @@ -27,9 +28,9 @@ const StartScreenButtons: FC<StartScrrenButtonsInterface> = ({

setIsStopping(true)
try {
const res: { status: boolean; msg: string[] } = await window.api.stopDockerRADIContainer()
const res: ResponeInterface = await window.api.stopDockerRADIContainer()

if (res.status) {
if (res.status == ResponseStatus.SUCCESS) {
dispatch({
type: ActionEnums.CHANGE_SCREEN,
payload: {
Expand Down

0 comments on commit b3a80a2

Please sign in to comment.