diff --git a/electron/main.ts b/electron/main.ts index abe2a48d2..5ff47409b 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -1,6 +1,7 @@ import { app, BrowserWindow, protocol, screen } from 'electron' import { join } from 'path' +import { setupAutoUpdater } from './services/auto-update' import { setupNetworkService } from './services/network' export const ROOT_PATH = { @@ -25,11 +26,6 @@ function createWindow(): void { height, }) - // Test active push message to Renderer-process. - mainWindow.webContents.on('did-finish-load', () => { - mainWindow?.webContents.send('main-process-message', new Date().toLocaleString()) - }) - if (process.env.VITE_DEV_SERVER_URL) { mainWindow.loadURL(process.env.VITE_DEV_SERVER_URL) } else { @@ -63,7 +59,17 @@ protocol.registerSchemesAsPrivileged([ setupNetworkService() -app.whenReady().then(createWindow) +app.whenReady().then(async () => { + console.log('Electron app is ready.') + console.log(`Cockpit version: ${app.getVersion()}`) + + console.log('Creating window...') + createWindow() + + setTimeout(() => { + setupAutoUpdater(mainWindow as BrowserWindow) + }, 5000) +}) app.on('before-quit', () => { // @ts-ignore: import.meta.env does not exist in the types diff --git a/electron/preload.ts b/electron/preload.ts index 4312004c1..08977a09b 100644 --- a/electron/preload.ts +++ b/electron/preload.ts @@ -2,4 +2,16 @@ import { contextBridge, ipcRenderer } from 'electron' contextBridge.exposeInMainWorld('electronAPI', { getInfoOnSubnets: () => ipcRenderer.invoke('get-info-on-subnets'), + onUpdateAvailable: (callback: (info: any) => void) => + ipcRenderer.on('update-available', (_event, info) => callback(info)), + onUpdateDownloaded: (callback: (info: any) => void) => + ipcRenderer.on('update-downloaded', (_event, info) => callback(info)), + onCheckingForUpdate: (callback: () => void) => ipcRenderer.on('checking-for-update', () => callback()), + onUpdateNotAvailable: (callback: (info: any) => void) => + ipcRenderer.on('update-not-available', (_event, info) => callback(info)), + onDownloadProgress: (callback: (info: any) => void) => + ipcRenderer.on('download-progress', (_event, info) => callback(info)), + downloadUpdate: () => ipcRenderer.send('download-update'), + installUpdate: () => ipcRenderer.send('install-update'), + cancelUpdate: () => ipcRenderer.send('cancel-update'), }) diff --git a/src/App.vue b/src/App.vue index 94af043d2..f50106e6c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -316,6 +316,7 @@ + diff --git a/src/libs/cosmos.ts b/src/libs/cosmos.ts index ab113a515..2be10c48a 100644 --- a/src/libs/cosmos.ts +++ b/src/libs/cosmos.ts @@ -191,6 +191,38 @@ declare global { * @returns Promise containing subnet information */ getInfoOnSubnets: () => Promise + /** + * Register callback for update available event + */ + onUpdateAvailable: (callback: (info: any) => void) => void + /** + * Register callback for update downloaded event + */ + onUpdateDownloaded: (callback: (info: any) => void) => void + /** + * Trigger update download + */ + downloadUpdate: () => void + /** + * Trigger update installation + */ + installUpdate: () => void + /** + * Cancel ongoing update + */ + cancelUpdate: () => void + /** + * Register callback for checking for update event + */ + onCheckingForUpdate: (callback: () => void) => void + /** + * Register callback for update not available event + */ + onUpdateNotAvailable: (callback: (info: any) => void) => void + /** + * Register callback for download progress event + */ + onDownloadProgress: (callback: (info: any) => void) => void } } }