From 8d868ef1ef0ff44876c19609ea18f8e7ea7460b0 Mon Sep 17 00:00:00 2001 From: jliddev Date: Tue, 9 Mar 2021 12:40:22 -0600 Subject: [PATCH] Fix migration Make migration smarter Make the auto update checks into a normal window interval --- wowup-electron/package.json | 2 +- .../src/app/addon-providers/addon-provider.ts | 4 +++ .../addon-providers/curse-addon-provider.ts | 4 +++ .../addon-providers/wowup-addon-provider.ts | 4 +++ wowup-electron/src/app/app.component.ts | 19 ++++++----- .../src/app/pages/home/home.component.ts | 32 +++++++++++-------- .../src/app/services/addons/addon.service.ts | 18 +++++++++++ 7 files changed, 59 insertions(+), 24 deletions(-) diff --git a/wowup-electron/package.json b/wowup-electron/package.json index f214748b..a83e89a8 100644 --- a/wowup-electron/package.json +++ b/wowup-electron/package.json @@ -1,7 +1,7 @@ { "name": "wowup", "productName": "WowUp", - "version": "2.2.0-beta.7", + "version": "2.2.0-beta.8", "description": "World of Warcraft addon updater", "homepage": "https://wowup.io", "author": { diff --git a/wowup-electron/src/app/addon-providers/addon-provider.ts b/wowup-electron/src/app/addon-providers/addon-provider.ts index f2981f7c..b4addb6c 100644 --- a/wowup-electron/src/app/addon-providers/addon-provider.ts +++ b/wowup-electron/src/app/addon-providers/addon-provider.ts @@ -38,6 +38,10 @@ export abstract class AddonProvider { return Promise.resolve([]); } + public shouldMigrate(addon: Addon): boolean { + return false; + } + public searchByQuery( query: string, installation: WowInstallation, diff --git a/wowup-electron/src/app/addon-providers/curse-addon-provider.ts b/wowup-electron/src/app/addon-providers/curse-addon-provider.ts index 1ce7d644..153ba15f 100644 --- a/wowup-electron/src/app/addon-providers/curse-addon-provider.ts +++ b/wowup-electron/src/app/addon-providers/curse-addon-provider.ts @@ -108,6 +108,10 @@ export class CurseAddonProvider extends AddonProvider { return ""; } + public shouldMigrate(addon: Addon): boolean { + return !addon.installedExternalReleaseId; + } + public async scan( installation: WowInstallation, addonChannelType: AddonChannelType, diff --git a/wowup-electron/src/app/addon-providers/wowup-addon-provider.ts b/wowup-electron/src/app/addon-providers/wowup-addon-provider.ts index d2230e84..1a3c48ee 100644 --- a/wowup-electron/src/app/addon-providers/wowup-addon-provider.ts +++ b/wowup-electron/src/app/addon-providers/wowup-addon-provider.ts @@ -72,6 +72,10 @@ export class WowUpAddonProvider extends AddonProvider { return ""; } + public shouldMigrate(addon: Addon): boolean { + return !addon.installedExternalReleaseId; + } + public async getAll(installation: WowInstallation, addonIds: string[]): Promise { const gameType = this.getWowGameType(installation.clientType); const url = new URL(`${API_URL}/addons/batch/${gameType}`); diff --git a/wowup-electron/src/app/app.component.ts b/wowup-electron/src/app/app.component.ts index 1d378cb7..4ea74dad 100644 --- a/wowup-electron/src/app/app.component.ts +++ b/wowup-electron/src/app/app.component.ts @@ -55,7 +55,7 @@ import { SnackbarService } from "./services/snackbar/snackbar.service"; changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent implements OnInit, OnDestroy, AfterViewInit { - private _autoUpdateInterval?: Subscription; + private _autoUpdateInterval?: number; // @HostListener("document:fullscreenchange", ["$event"]) // handleKeyboardEvent(event: Event) { @@ -128,7 +128,7 @@ export class AppComponent implements OnInit, OnDestroy, AfterViewInit { this._electronService.powerMonitor$.pipe(filter((evt) => !!evt)).subscribe((evt) => { console.log("Stopping auto update..."); - this._autoUpdateInterval?.unsubscribe(); + window.clearInterval(this._autoUpdateInterval); this._autoUpdateInterval = undefined; if (evt === IPC_POWER_MONITOR_RESUME || evt === IPC_POWER_MONITOR_UNLOCK) { @@ -190,17 +190,16 @@ export class AppComponent implements OnInit, OnDestroy, AfterViewInit { } private async initializeAutoUpdate() { - if (this._autoUpdateInterval) { + if (this._autoUpdateInterval !== undefined) { + console.warn(`Auto addon update interval already exists`); return; } + + this._autoUpdateInterval = window.setInterval(() => { + this.onAutoUpdateInterval().catch((e) => console.error(e)); + }, AppConfig.autoUpdateIntervalMs); + await this.onAutoUpdateInterval(); - this._autoUpdateInterval = interval(AppConfig.autoUpdateIntervalMs) - .pipe( - tap(() => { - this.onAutoUpdateInterval().catch((e) => console.error(e)); - }) - ) - .subscribe(); } private onAutoUpdateInterval = async () => { diff --git a/wowup-electron/src/app/pages/home/home.component.ts b/wowup-electron/src/app/pages/home/home.component.ts index 75548c0a..b67d27f2 100644 --- a/wowup-electron/src/app/pages/home/home.component.ts +++ b/wowup-electron/src/app/pages/home/home.component.ts @@ -1,5 +1,5 @@ -import { interval, Subscription } from "rxjs"; -import { filter, first, tap } from "rxjs/operators"; +import { from, interval } from "rxjs"; +import { filter, first, map, switchMap, tap } from "rxjs/operators"; import { AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, NgZone, OnDestroy } from "@angular/core"; import { MatSnackBar } from "@angular/material/snack-bar"; @@ -22,7 +22,7 @@ import { WowUpService } from "../../services/wowup/wowup.service"; changeDetection: ChangeDetectionStrategy.OnPush, }) export class HomeComponent implements AfterViewInit, OnDestroy { - private _appUpdateInterval: Subscription; + private _appUpdateInterval?: number; public selectedIndex = 0; public hasWowClient = false; @@ -64,7 +64,12 @@ export class HomeComponent implements AfterViewInit, OnDestroy { this.initAppUpdateCheck(); this._warcraftInstallationService.wowInstallations$ - .pipe(first((installations) => installations.length > 0)) + .pipe( + first((installations) => installations.length > 0), + switchMap((installations) => { + return from(this.migrateAddons(installations)).pipe(map(() => installations)); + }) + ) .subscribe(() => { this.appReady = true; this.detectChanges(); @@ -72,24 +77,25 @@ export class HomeComponent implements AfterViewInit, OnDestroy { } public ngOnDestroy(): void { - this._appUpdateInterval?.unsubscribe(); + window.clearInterval(this._appUpdateInterval); } private initAppUpdateCheck() { + if (this._appUpdateInterval !== undefined) { + console.warn(`App update interval already exists`); + return; + } + // check for an app update every so often - this._appUpdateInterval = interval(AppConfig.appUpdateIntervalMs) - .pipe( - tap(() => { - this.checkForAppUpdate().catch((e) => console.error(e)); - }) - ) - .subscribe(); + this._appUpdateInterval = window.setInterval(() => { + this.checkForAppUpdate().catch((e) => console.error(e)); + }, AppConfig.appUpdateIntervalMs); this.checkForAppUpdate().catch((e) => console.error(e)); } private destroyAppUpdateCheck() { - this._appUpdateInterval?.unsubscribe(); + window.clearInterval(this._appUpdateInterval); this._appUpdateInterval = undefined; } diff --git a/wowup-electron/src/app/services/addons/addon.service.ts b/wowup-electron/src/app/services/addons/addon.service.ts index 8cc3d9ee..c03f2892 100644 --- a/wowup-electron/src/app/services/addons/addon.service.ts +++ b/wowup-electron/src/app/services/addons/addon.service.ts @@ -1073,12 +1073,30 @@ export class AddonService { return; } + const needsMigration = _.some(existingAddons, (addon) => this.needsMigration(addon)); + if (!needsMigration) { + console.log(`No addons needed to be migrated: ${installation.label}`); + return; + } + const scannedAddons = await this.scanAddons(installation); for (const addon of existingAddons) { this.migrateAddon(addon, scannedAddons); } } + private needsMigration(addon: Addon) { + const provider = this.getProvider(addon.providerName); + + const migrationNeeded = + addon.providerName === ADDON_PROVIDER_HUB_LEGACY || + !addon.installedFolderList || + !addon.externalChannel || + (provider?.shouldMigrate(addon) ?? false); + + return migrationNeeded; + } + private migrateAddon(addon: Addon, scannedAddons: Addon[]): void { if (addon.providerName === ADDON_PROVIDER_HUB_LEGACY) { console.log(`Updating legacy hub name: ${addon.name}`);