From daad003ceb9927153f36f4e8ec4e8d957dda0ef0 Mon Sep 17 00:00:00 2001 From: richard-loafle <44828666+richard-loafle@users.noreply.github.com> Date: Wed, 29 Jan 2020 15:03:48 +0900 Subject: [PATCH] bug of auto updater is fixed --- docker/docker-compose.yml | 6 +++--- .../electron-update-window.service.ts | 9 ++------- .../assets/update-window/preload.js | 19 ++++++++++++------ .../ucap-webmessenger-electron/src/index.ts | 20 +++++++++++++------ 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 4a910294..437d36fb 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,9 +2,9 @@ version: '3.1' services: nginx: - image: nginx:1.17.5-alpine + image: nginx:1.17.8-alpine volumes: - - ../dist/web:/usr/share/nginx/html:ro + - ./html:/usr/share/nginx/html:ro - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro ports: - - 8099:80 + - 80:80 diff --git a/electron-projects/ucap-webmessenger-electron-update-window/src/lib/services/electron-update-window.service.ts b/electron-projects/ucap-webmessenger-electron-update-window/src/lib/services/electron-update-window.service.ts index 951dbc33..648f107b 100644 --- a/electron-projects/ucap-webmessenger-electron-update-window/src/lib/services/electron-update-window.service.ts +++ b/electron-projects/ucap-webmessenger-electron-update-window/src/lib/services/electron-update-window.service.ts @@ -15,11 +15,6 @@ export class ElectronUpdateWindowService { private browserWindow: BrowserWindow; private templateUrl: string; - versionInfo: { - installed?: string; - latest?: string; - }; - constructor(options: ElectronUpdateWindowOptions) { this.customOptions = { ...DefaultElectronUpdateWindowOptions @@ -59,7 +54,7 @@ export class ElectronUpdateWindowService { return this.templateUrl; } - show() { + show(versionInfo: { installed: string; latest: string }) { this.browserWindow = new BrowserWindow(this.customOptions); this.browserWindow.loadURL(this.templatePath); @@ -78,7 +73,7 @@ export class ElectronUpdateWindowService { this.browserWindow.webContents.send( Channel.browserWindowSetContents, - this.versionInfo + versionInfo ); } ); diff --git a/electron-projects/ucap-webmessenger-electron/assets/update-window/preload.js b/electron-projects/ucap-webmessenger-electron/assets/update-window/preload.js index 15f28fe0..4d2dd393 100644 --- a/electron-projects/ucap-webmessenger-electron/assets/update-window/preload.js +++ b/electron-projects/ucap-webmessenger-electron/assets/update-window/preload.js @@ -42,13 +42,17 @@ downloadingCancel && }); function setContents(event, versionInfo) { - let updateDoc = global.window.document; + const updateDoc = global.window.document; - let latestVersion = updateDoc.getElementById('latestVersion'); - latestVersion.innerHTML = versionInfo.latest || ''; + const latestVersion = updateDoc.getElementById('latestVersion'); + if (!!latestVersion) { + latestVersion.innerHTML = versionInfo.latest || ''; + } - let installedVersion = updateDoc.getElementById('installedVersion'); - installedVersion.innerHTML = versionInfo.installed || ''; + const installedVersion = updateDoc.getElementById('installedVersion'); + if (!!installedVersion) { + installedVersion.innerHTML = versionInfo.installed || ''; + } } ipcRenderer.on( @@ -67,4 +71,7 @@ ipcRenderer.on( } ); -ipc.on('UCAP::ElectronUpdateWindow::BrowserWindowSetContents', setContents); +ipcRenderer.on( + 'UCAP::ElectronUpdateWindow::BrowserWindowSetContents', + setContents +); diff --git a/electron-projects/ucap-webmessenger-electron/src/index.ts b/electron-projects/ucap-webmessenger-electron/src/index.ts index c2f5b955..dcfc113a 100644 --- a/electron-projects/ucap-webmessenger-electron/src/index.ts +++ b/electron-projects/ucap-webmessenger-electron/src/index.ts @@ -6,7 +6,7 @@ import { Menu, shell, dialog, - webFrame + BrowserWindow } from 'electron'; import path from 'path'; import fse from 'fs-extra'; @@ -359,10 +359,6 @@ ipcMain.on(UpdaterChannel.Apply, (event: IpcMainEvent, ...args: any[]) => { const ver = args[0]; if (semver.lt(app.getVersion(), ver)) { - updateWindowService.versionInfo = { - latest: ver, - installed: app.getVersion() - }; autoUpdater .checkForUpdatesAndNotify() .then(result => {}) @@ -718,7 +714,10 @@ autoUpdater.on('update-available', info => { log.info(info); log.info('Update available.'); - updateWindowService.show(); + updateWindowService.show({ + latest: info.version, + installed: app.getVersion() + }); }); autoUpdater.on('update-not-available', info => { log.info('Update not available.'); @@ -743,6 +742,15 @@ autoUpdater.on('update-downloaded', info => { updateWindowService.setDownloadComplete(); + app.removeAllListeners('window-all-closed'); + const browserWindows = BrowserWindow.getAllWindows(); + + // https://github.com/electron-userland/electron-builder/issues/1604#issuecomment-372091881 + browserWindows.forEach(browserWindow => { + browserWindow.removeAllListeners('close'); + browserWindow.removeAllListeners('closed'); + }); + setTimeout(() => { autoUpdater.quitAndInstall(true, true); }, 2000);