diff --git a/src/main/appWindow.ts b/src/main/appWindow.ts new file mode 100644 index 0000000..3aae38c --- /dev/null +++ b/src/main/appWindow.ts @@ -0,0 +1,43 @@ +import { app, BrowserWindow } from 'electron' +import { join } from 'path' + +export function createUpdaterWindow(): BrowserWindow { + const win = new BrowserWindow({ + width: 500, + height: 250, + frame: false, + transparent: true, + alwaysOnTop: true, + x: 0, + y: 0, + webPreferences: { + preload: join(__dirname, './../preload/index.js'), + nodeIntegration: false, + webSecurity: true, + sandbox: false, + contextIsolation: true + } + }) + + const updaterScreenSrc = app.isPackaged + ? join(process.resourcesPath, 'updaterScreen.html') + : join(__dirname, './../../', 'updaterScreen.html') + + win.loadFile(updaterScreenSrc) + + // 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 +} diff --git a/src/main/index.ts b/src/main/index.ts index 15a5000..28826c2 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -30,9 +30,11 @@ import { updateCommands, updateCommandUtils } from './db' +import { createUpdaterWindow } from './appWindow' const isMac = process.platform === 'darwin' let mainWindow: BrowserWindow | null = null +let updaterWindow: BrowserWindow | null = null const appVersion = `v${app.getVersion()}` // disable auto-update download @@ -80,6 +82,8 @@ function createSplashWindow(): BrowserWindow { return win } +// updater window + // main window const createWindow = async (): Promise => { mainWindow = new BrowserWindow({ @@ -392,15 +396,24 @@ app.whenReady().then(async () => { } } ) + + // Updater Window + ipcMain.handle('updater:CLOSE_WINDOW', (_event) => { + try { + if (updaterWindow) updaterWindow.destroy() + } catch (error) {} + }) //@ Disappering splash screen and show main screen after 3 seconds. try { const splashScreen: BrowserWindow = createSplashWindow() + updaterWindow = createUpdaterWindow() const mainScreen: BrowserWindow = await createWindow() + updaterWindow.show() mainScreen.once('ready-to-show', () => { setTimeout( () => { - mainScreen.show() + // mainScreen.show() splashScreen.destroy() }, app.isPackaged ? 3000 : 0 diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts index cbbd524..d7ce642 100644 --- a/src/preload/index.d.ts +++ b/src/preload/index.d.ts @@ -38,7 +38,11 @@ interface ApiInterface { ) => Promise> //! DELETE deleteCommandConfig: (id: number) => Promise> + + // updater-window + updaterWindowClose: () => void } + declare global { interface Window { electron: ElectronAPI diff --git a/src/preload/index.ts b/src/preload/index.ts index c01e083..d9676c0 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -51,7 +51,10 @@ const api = { ipcRenderer.invoke('database:UPDATE_COMMAND_UTILS', id, image), //! DELETE deleteCommandConfig: (id: number): Promise> => - ipcRenderer.invoke('database:DELETE_COMMAND_CONFIG', id) + ipcRenderer.invoke('database:DELETE_COMMAND_CONFIG', id), + + // Updater Window + updaterWindowClose: () => ipcRenderer.invoke('updater:CLOSE_WINDOW') } // Use `contextBridge` APIs to expose Electron APIs to diff --git a/updaterScreen.html b/updaterScreen.html new file mode 100644 index 0000000..90abae0 --- /dev/null +++ b/updaterScreen.html @@ -0,0 +1,232 @@ + + + + + + Robotics Academy + + + + +
+ +
+ + Robotics Academy Desktop Update Available +
+ + + +
+
+ +
+ +
+ + + +
+ +
+

A new version of Robotics Academy Desktop Available.

+

Do you want to download version 2.0.1 ?

+

Current Version 2.0.0

+
+
+ + +
+ + + +