From c37f439fb04a33c1d15b5ca14e2ff1bdd260ac6d Mon Sep 17 00:00:00 2001 From: Richard Park Date: Mon, 16 Dec 2019 02:33:40 +0900 Subject: [PATCH] bug of updater is fixed --- .../ucap-webmessenger-electron/src/index.ts | 27 +++++++++++++------ .../store/account/authentication/effects.ts | 2 +- .../lib/services/browser-native.service.ts | 2 +- .../lib/services/electron-native.service.ts | 6 +++-- .../src/lib/services/native.service.ts | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/electron-projects/ucap-webmessenger-electron/src/index.ts b/electron-projects/ucap-webmessenger-electron/src/index.ts index ae04d919..b81617e2 100644 --- a/electron-projects/ucap-webmessenger-electron/src/index.ts +++ b/electron-projects/ucap-webmessenger-electron/src/index.ts @@ -268,11 +268,6 @@ app.on(ElectronAppChannel.Ready, () => { } }); - updateWindowService.options.webPreferences.preload = path.join( - __dirname, - 'resources/update-window/preload.js' - ); - updateWindowService.templatePath = path.join( __dirname, 'resources/update-window/template.html' @@ -319,12 +314,28 @@ function onDidLoad(fn: OnDidLoadFn) { } ipcMain.on(UpdaterChannel.Check, (event: IpcMainEvent, ...args: any[]) => { + // if (__DEV__) { + // event.returnValue = false; + // return; + // } + const ver = args[0]; + if (semver.lt(app.getVersion(), ver)) { - autoUpdater.checkForUpdatesAndNotify(); - return true; + autoUpdater + .checkForUpdatesAndNotify() + .then(result => { + if (!result) { + event.returnValue = false; + } else { + event.returnValue = true; + } + }) + .catch(reason => { + event.returnValue = false; + }); } else { - return false; + event.returnValue = false; } }); diff --git a/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts b/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts index 69109fae..e3a550c8 100644 --- a/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts @@ -119,7 +119,7 @@ export class Effects { params => new Observable(subscriber => { this.nativeService - .checkForUpdates() + .checkForUpdates(params.login2Response.version) .then((update: boolean) => { if (!update) { this.appAuthenticationService.login( diff --git a/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts b/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts index ba62d3e4..c4bf9ec0 100644 --- a/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts +++ b/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts @@ -70,7 +70,7 @@ export class BrowserNativeService extends NativeService { } closeAllNotify(): void {} - checkForUpdates(): Promise { + checkForUpdates(currentVersion: string): Promise { return new Promise((resolve, reject) => { resolve(false); }); diff --git a/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts b/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts index e4f7fdff..9d4dbe6f 100644 --- a/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts +++ b/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts @@ -105,10 +105,12 @@ export class ElectronNativeService implements NativeService { this.ipcRenderer.send(NotificationChannel.CloseAllNotify); } - checkForUpdates(): Promise { + checkForUpdates(currentVersion: string): Promise { return new Promise((resolve, reject) => { try { - resolve(this.ipcRenderer.sendSync(UpdaterChannel.Check)); + resolve( + this.ipcRenderer.sendSync(UpdaterChannel.Check, currentVersion) + ); } catch (error) { reject(error); } diff --git a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts index c49870ef..21459187 100644 --- a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts +++ b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts @@ -17,7 +17,7 @@ export abstract class NativeService { abstract notify(noti: NotificationRequest): void; abstract closeAllNotify(): void; - abstract checkForUpdates(): Promise; + abstract checkForUpdates(currentVersion: string): Promise; abstract checkForInstantUpdates( config: UpdateCheckConfig ): Observable;