mirror of
https://github.com/WowUp/WowUp.git
synced 2026-04-23 07:17:00 -04:00
Fix migration
Make migration smarter Make the auto update checks into a normal window interval
This commit is contained in:
@@ -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": {
|
||||
|
||||
@@ -38,6 +38,10 @@ export abstract class AddonProvider {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
public shouldMigrate(addon: Addon): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public searchByQuery(
|
||||
query: string,
|
||||
installation: WowInstallation,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<GetAllResult> {
|
||||
const gameType = this.getWowGameType(installation.clientType);
|
||||
const url = new URL(`${API_URL}/addons/batch/${gameType}`);
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user