diff --git a/wowup-electron/main.ts b/wowup-electron/main.ts index 4e7d4bc2..b5e5bf88 100644 --- a/wowup-electron/main.ts +++ b/wowup-electron/main.ts @@ -13,6 +13,9 @@ import { CURRENT_THEME_KEY, DEFAULT_BG_COLOR, DEFAULT_LIGHT_BG_COLOR, + POWER_MONITOR_LOCK, + POWER_MONITOR_RESUME, + POWER_MONITOR_UNLOCK, USE_HARDWARE_ACCELERATION_PREFERENCE_KEY, WINDOW_DEFAULT_HEIGHT, WINDOW_DEFAULT_WIDTH, @@ -151,18 +154,22 @@ app.on("child-process-gone", (e, details) => { powerMonitor.on("resume", () => { log.info("powerMonitor resume"); + win?.webContents?.send(POWER_MONITOR_RESUME); }); powerMonitor.on("suspend", () => { log.info("powerMonitor suspend"); + win?.webContents?.send(POWER_MONITOR_RESUME); }); powerMonitor.on("lock-screen", () => { log.info("powerMonitor lock-screen"); + win?.webContents?.send(POWER_MONITOR_LOCK); }); powerMonitor.on("unlock-screen", () => { log.info("powerMonitor unlock-screen"); + win?.webContents?.send(POWER_MONITOR_UNLOCK); }); let lastCrash = 0; diff --git a/wowup-electron/src/app/app.component.ts b/wowup-electron/src/app/app.component.ts index 1081fcba..86488a27 100644 --- a/wowup-electron/src/app/app.component.ts +++ b/wowup-electron/src/app/app.component.ts @@ -105,6 +105,12 @@ export class AppComponent implements OnInit, OnDestroy, AfterViewInit { this.quitEnabled = appOptions.quit; this._cdRef.detectChanges(); }); + + this._electronService.powerMonitor$.pipe(filter((evt) => !!evt)).subscribe(() => { + this._autoUpdateInterval?.unsubscribe(); + this._autoUpdateInterval = undefined; + this.initializeAutoUpdate(); + }); } ngAfterViewInit(): void { @@ -117,10 +123,7 @@ export class AppComponent implements OnInit, OnDestroy, AfterViewInit { this._analyticsService.trackStartup(); } - this.onAutoUpdateInterval(); - this._autoUpdateInterval = interval(AppConfig.autoUpdateIntervalMs) - .pipe(tap(async () => await this.onAutoUpdateInterval())) - .subscribe(); + this.initializeAutoUpdate(); } ngOnDestroy(): void { @@ -154,6 +157,17 @@ export class AppComponent implements OnInit, OnDestroy, AfterViewInit { }); } + private async initializeAutoUpdate() { + if (this._autoUpdateInterval) { + return; + } + + await this.onAutoUpdateInterval(); + this._autoUpdateInterval = interval(AppConfig.autoUpdateIntervalMs) + .pipe(tap(async () => await this.onAutoUpdateInterval())) + .subscribe(); + } + private onAutoUpdateInterval = async () => { try { console.log("onAutoUpdateInterval"); @@ -174,10 +188,10 @@ export class AppComponent implements OnInit, OnDestroy, AfterViewInit { } else { this.checkQuitEnabled(); } - - this._sessionService.autoUpdateComplete(); } catch (e) { console.error("Error during auto update", e); + } finally { + this._sessionService.autoUpdateComplete(); } }; diff --git a/wowup-electron/src/app/pages/my-addons/my-addons.component.ts b/wowup-electron/src/app/pages/my-addons/my-addons.component.ts index 845aadb0..a9a4ba3c 100644 --- a/wowup-electron/src/app/pages/my-addons/my-addons.component.ts +++ b/wowup-electron/src/app/pages/my-addons/my-addons.component.ts @@ -194,6 +194,7 @@ export class MyAddonsComponent implements OnInit, OnDestroy, AfterViewInit { public ngAfterViewInit(): void { this._sessionService.autoUpdateComplete$.subscribe(() => { + console.log("Checking for addon updates..."); this._cdRef.markForCheck(); this.onRefresh(); }); diff --git a/wowup-electron/src/app/services/electron/electron.service.ts b/wowup-electron/src/app/services/electron/electron.service.ts index ef6780f9..5ef4d835 100644 --- a/wowup-electron/src/app/services/electron/electron.service.ts +++ b/wowup-electron/src/app/services/electron/electron.service.ts @@ -7,6 +7,10 @@ import { CLOSE_WINDOW, MAXIMIZE_WINDOW, MINIMIZE_WINDOW, + POWER_MONITOR_LOCK, + POWER_MONITOR_RESUME, + POWER_MONITOR_SUSPEND, + POWER_MONITOR_UNLOCK, QUIT_APP, RESTART_APP, WINDOW_MAXIMIZED, @@ -38,6 +42,7 @@ export class ElectronService { private readonly _windowMinimizedSrc = new BehaviorSubject(false); private readonly _ipcEventReceivedSrc = new BehaviorSubject(""); private readonly _zoomFactorChangeSrc = new BehaviorSubject(1.0); + private readonly _powerMonitorSrc = new BehaviorSubject(""); private _appVersion = ""; @@ -45,6 +50,7 @@ export class ElectronService { public readonly windowMinimized$ = this._windowMinimizedSrc.asObservable(); public readonly ipcEventReceived$ = this._ipcEventReceivedSrc.asObservable(); public readonly zoomFactor$ = this._zoomFactorChangeSrc.asObservable(); + public readonly powerMonitor$ = this._powerMonitorSrc.asObservable(); public readonly isWin = process.platform === "win32"; public readonly isMac = process.platform === "darwin"; public readonly isLinux = process.platform === "linux"; @@ -62,6 +68,9 @@ export class ElectronService { console.log("Platform", process.platform, this.isLinux); + window.addEventListener("online", this.onWindowOnline); + window.addEventListener("offline", this.onWindowOffline); + this.invoke("get-app-version") .then((version) => { this._appVersion = version; @@ -98,6 +107,26 @@ export class ElectronService { this._windowMaximizedSrc.next(false); }); + this.onRendererEvent(POWER_MONITOR_LOCK, () => { + console.log("POWER_MONITOR_LOCK received"); + this._powerMonitorSrc.next(POWER_MONITOR_LOCK); + }); + + this.onRendererEvent(POWER_MONITOR_UNLOCK, () => { + console.log("POWER_MONITOR_UNLOCK received"); + this._powerMonitorSrc.next(POWER_MONITOR_UNLOCK); + }); + + this.onRendererEvent(POWER_MONITOR_SUSPEND, () => { + console.log("POWER_MONITOR_SUSPEND received"); + this._powerMonitorSrc.next(POWER_MONITOR_SUSPEND); + }); + + this.onRendererEvent(POWER_MONITOR_RESUME, () => { + console.log("POWER_MONITOR_RESUME received"); + this._powerMonitorSrc.next(POWER_MONITOR_RESUME); + }); + this.invoke("set-zoom-limits", 1, 1).catch((e) => { console.error("Failed to set zoom limits", e); }); @@ -120,6 +149,14 @@ export class ElectronService { .catch((e) => console.error("Failed to set initial zoom")); } + private onWindowOnline(evt: Event) { + console.log("Window online..."); + } + + private onWindowOffline(evt: Event) { + console.warn("Window offline..."); + } + public getLoginItemSettings(): Promise { return this.invoke("get-login-item-settings"); } @@ -226,7 +263,6 @@ export class ElectronService { } public async invoke(channel: RendererChannels, ...args: any[]): Promise { - console.debug("invoke", channel); return await window.wowup.rendererInvoke(channel, ...args); } diff --git a/wowup-electron/src/common/constants.ts b/wowup-electron/src/common/constants.ts index 9abb7d37..563a227c 100644 --- a/wowup-electron/src/common/constants.ts +++ b/wowup-electron/src/common/constants.ts @@ -39,6 +39,10 @@ export const WINDOW_MINIMIZED = "window-minimized"; export const CLOSE_WINDOW = "close-window"; export const RESTART_APP = "restart-app"; export const QUIT_APP = "quit-app"; +export const POWER_MONITOR_RESUME = "power-monitor-resume"; +export const POWER_MONITOR_SUSPEND = "power-monitor-suspend"; +export const POWER_MONITOR_LOCK = "power-monitor-lock"; +export const POWER_MONITOR_UNLOCK = "power-monitor-unlock"; // PREFERENCES export const ENABLE_SYSTEM_NOTIFICATIONS_PREFERENCE_KEY = "enable_system_notifications"; diff --git a/wowup-electron/src/common/wowup.d.ts b/wowup-electron/src/common/wowup.d.ts index bdd1b82f..8fce5514 100644 --- a/wowup-electron/src/common/wowup.d.ts +++ b/wowup-electron/src/common/wowup.d.ts @@ -20,7 +20,11 @@ declare type MainChannels = | "app-update-not-available" | "window-minimized" | "window-unmaximized" - | "window-maximized"; + | "window-maximized" + | "power-monitor-resume" + | "power-monitor-suspend" + | "power-monitor-lock" + | "power-monitor-unlock"; // Events that can be sent from renderer to main declare type RendererChannels =