bug of auto updater is fixed

This commit is contained in:
richard-loafle 2020-01-29 15:03:48 +09:00
parent 121883a46c
commit daad003ceb
4 changed files with 32 additions and 22 deletions

View File

@ -2,9 +2,9 @@ version: '3.1'
services: services:
nginx: nginx:
image: nginx:1.17.5-alpine image: nginx:1.17.8-alpine
volumes: volumes:
- ../dist/web:/usr/share/nginx/html:ro - ./html:/usr/share/nginx/html:ro
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
ports: ports:
- 8099:80 - 80:80

View File

@ -15,11 +15,6 @@ export class ElectronUpdateWindowService {
private browserWindow: BrowserWindow; private browserWindow: BrowserWindow;
private templateUrl: string; private templateUrl: string;
versionInfo: {
installed?: string;
latest?: string;
};
constructor(options: ElectronUpdateWindowOptions) { constructor(options: ElectronUpdateWindowOptions) {
this.customOptions = { this.customOptions = {
...DefaultElectronUpdateWindowOptions ...DefaultElectronUpdateWindowOptions
@ -59,7 +54,7 @@ export class ElectronUpdateWindowService {
return this.templateUrl; return this.templateUrl;
} }
show() { show(versionInfo: { installed: string; latest: string }) {
this.browserWindow = new BrowserWindow(this.customOptions); this.browserWindow = new BrowserWindow(this.customOptions);
this.browserWindow.loadURL(this.templatePath); this.browserWindow.loadURL(this.templatePath);
@ -78,7 +73,7 @@ export class ElectronUpdateWindowService {
this.browserWindow.webContents.send( this.browserWindow.webContents.send(
Channel.browserWindowSetContents, Channel.browserWindowSetContents,
this.versionInfo versionInfo
); );
} }
); );

View File

@ -42,13 +42,17 @@ downloadingCancel &&
}); });
function setContents(event, versionInfo) { function setContents(event, versionInfo) {
let updateDoc = global.window.document; const updateDoc = global.window.document;
let latestVersion = updateDoc.getElementById('latestVersion'); const latestVersion = updateDoc.getElementById('latestVersion');
latestVersion.innerHTML = versionInfo.latest || ''; if (!!latestVersion) {
latestVersion.innerHTML = versionInfo.latest || '';
}
let installedVersion = updateDoc.getElementById('installedVersion'); const installedVersion = updateDoc.getElementById('installedVersion');
installedVersion.innerHTML = versionInfo.installed || ''; if (!!installedVersion) {
installedVersion.innerHTML = versionInfo.installed || '';
}
} }
ipcRenderer.on( ipcRenderer.on(
@ -67,4 +71,7 @@ ipcRenderer.on(
} }
); );
ipc.on('UCAP::ElectronUpdateWindow::BrowserWindowSetContents', setContents); ipcRenderer.on(
'UCAP::ElectronUpdateWindow::BrowserWindowSetContents',
setContents
);

View File

@ -6,7 +6,7 @@ import {
Menu, Menu,
shell, shell,
dialog, dialog,
webFrame BrowserWindow
} from 'electron'; } from 'electron';
import path from 'path'; import path from 'path';
import fse from 'fs-extra'; import fse from 'fs-extra';
@ -359,10 +359,6 @@ ipcMain.on(UpdaterChannel.Apply, (event: IpcMainEvent, ...args: any[]) => {
const ver = args[0]; const ver = args[0];
if (semver.lt(app.getVersion(), ver)) { if (semver.lt(app.getVersion(), ver)) {
updateWindowService.versionInfo = {
latest: ver,
installed: app.getVersion()
};
autoUpdater autoUpdater
.checkForUpdatesAndNotify() .checkForUpdatesAndNotify()
.then(result => {}) .then(result => {})
@ -718,7 +714,10 @@ autoUpdater.on('update-available', info => {
log.info(info); log.info(info);
log.info('Update available.'); log.info('Update available.');
updateWindowService.show(); updateWindowService.show({
latest: info.version,
installed: app.getVersion()
});
}); });
autoUpdater.on('update-not-available', info => { autoUpdater.on('update-not-available', info => {
log.info('Update not available.'); log.info('Update not available.');
@ -743,6 +742,15 @@ autoUpdater.on('update-downloaded', info => {
updateWindowService.setDownloadComplete(); 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(() => { setTimeout(() => {
autoUpdater.quitAndInstall(true, true); autoUpdater.quitAndInstall(true, true);
}, 2000); }, 2000);