Fix an issue with the auto updating of the my addons tab

Add some triggers for power state to disable the auto check loop to see if it helps with fullscreen sleep issue.
This commit is contained in:
jliddev
2021-01-11 00:14:41 -06:00
parent 6bac9e4d55
commit de948d2faf
6 changed files with 74 additions and 8 deletions

View File

@@ -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;

View File

@@ -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();
}
};

View File

@@ -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();
});

View File

@@ -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<LoginItemSettings> {
return this.invoke("get-login-item-settings");
}
@@ -226,7 +263,6 @@ export class ElectronService {
}
public async invoke(channel: RendererChannels, ...args: any[]): Promise<any> {
console.debug("invoke", channel);
return await window.wowup.rendererInvoke(channel, ...args);
}

View File

@@ -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";

View File

@@ -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 =