From c6971297d3e94cfc79126ba3e6d84c8c032ca3f4 Mon Sep 17 00:00:00 2001 From: Alexander Drozdov Date: Wed, 25 Mar 2020 16:59:41 +0200 Subject: [PATCH] show update notification --- src/ipc/ipc-event.ts | 2 ++ src/ipc/main-process-bindings.ts | 6 ++++++ src/main/updates.ts | 6 +++++- src/web/price-check/AppBootstrap.vue | 23 +++++++++++++++++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/ipc/ipc-event.ts b/src/ipc/ipc-event.ts index a4fddade..90b44388 100644 --- a/src/ipc/ipc-event.ts +++ b/src/ipc/ipc-event.ts @@ -10,3 +10,5 @@ export const OPEN_LINK = 'open-link' export const OPEN_LINK_EXTERNAL = 'open-link-external' export const CLOSE_SETTINGS_WINDOW = 'close-settings-window' + +export const UPDATE_AVAILABLE = 'update-available' diff --git a/src/ipc/main-process-bindings.ts b/src/ipc/main-process-bindings.ts index a1661f13..f4a1bfbd 100644 --- a/src/ipc/main-process-bindings.ts +++ b/src/ipc/main-process-bindings.ts @@ -27,6 +27,12 @@ class MainProcessBinding extends EventTarget { detail: cfg })) }) + + electron.ipcRenderer.on(ipcEvent.UPDATE_AVAILABLE, (e, updateInfo) => { + this.dispatchEvent(new CustomEvent(ipcEvent.UPDATE_AVAILABLE, { + detail: updateInfo + })) + }) } } diff --git a/src/main/updates.ts b/src/main/updates.ts index c5da89c0..6cd629e0 100644 --- a/src/main/updates.ts +++ b/src/main/updates.ts @@ -1,6 +1,8 @@ import { autoUpdater } from 'electron-updater' import { logger } from './logger' import { rebuildContextMenu } from './tray' +import { win } from './window' +import { UPDATE_AVAILABLE } from '@/ipc/ipc-event' export const UpdateState = { canCheck: true, @@ -12,7 +14,8 @@ autoUpdater.on('update-available', (info: { version: string }) => { if (autoUpdater.autoDownload) { UpdateState.status = `Downloading v${info.version} ...` } else { - UpdateState.status = `Update v${info.version} available on Github` + UpdateState.status = `Update v${info.version} available on GitHub` + win.webContents.send(UPDATE_AVAILABLE, { auto: false, version: info.version }) } rebuildContextMenu() }) @@ -33,6 +36,7 @@ autoUpdater.on('update-downloaded', (info: { version: string }) => { UpdateState.canCheck = false UpdateState.status = `v${info.version} will be installed on exit` rebuildContextMenu() + win.webContents.send(UPDATE_AVAILABLE, { auto: true, version: info.version }) }) // on('download-progress') https://github.com/electron-userland/electron-builder/issues/2521 diff --git a/src/web/price-check/AppBootstrap.vue b/src/web/price-check/AppBootstrap.vue index 0c6abd87..00596c47 100644 --- a/src/web/price-check/AppBootstrap.vue +++ b/src/web/price-check/AppBootstrap.vue @@ -1,9 +1,17 @@