From 78f52b39f13d95cd30d437cd51d3e369cbff3756 Mon Sep 17 00:00:00 2001 From: Dean Campbell Date: Tue, 20 Oct 2020 13:28:01 -0700 Subject: [PATCH] Fix wow client locations being set on initial load --- .../wow-client-options.component.ts | 22 +++- .../pages/my-addons/my-addons.component.ts | 4 - .../app/pages/options/options.component.html | 13 -- .../app/pages/options/options.component.ts | 114 ------------------ .../src/app/services/addons/addon.service.ts | 2 +- .../app/services/warcraft/warcraft.service.ts | 8 +- 6 files changed, 24 insertions(+), 139 deletions(-) diff --git a/wowup-electron/src/app/components/wow-client-options/wow-client-options.component.ts b/wowup-electron/src/app/components/wow-client-options/wow-client-options.component.ts index 6a8f99a8..30b1bc25 100644 --- a/wowup-electron/src/app/components/wow-client-options/wow-client-options.component.ts +++ b/wowup-electron/src/app/components/wow-client-options/wow-client-options.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { Component, Input, OnDestroy, OnInit } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { WowClientType } from 'app/models/warcraft/wow-client-type'; import { ElectronService } from 'app/services'; @@ -11,16 +11,19 @@ import { AddonChannelType } from 'app/models/wowup/addon-channel-type'; import { WowUpService } from 'app/services/wowup/wowup.service'; import { MatSelectChange } from '@angular/material/select'; import { MatSlideToggleChange } from '@angular/material/slide-toggle'; +import { Subscription } from 'rxjs'; @Component({ selector: 'app-wow-client-options', templateUrl: './wow-client-options.component.html', styleUrls: ['./wow-client-options.component.scss'] }) -export class WowClientOptionsComponent implements OnInit { +export class WowClientOptionsComponent implements OnInit, OnDestroy { @Input('clientType') clientType: WowClientType; + private subscriptions: Subscription[] = []; + public clientTypeName: string; public clientFolderName: string; public clientLocation: string; @@ -34,7 +37,16 @@ export class WowClientOptionsComponent implements OnInit { private _electronService: ElectronService, private _warcraftService: WarcraftService, private _wowupService: WowUpService - ) { } + ) { + const warcraftProductSubscription = this._warcraftService.products$.subscribe(products => { + const product = products.find(p => p.clientType === this.clientType); + if (product) { + this.clientLocation = product.location; + } + }); + + this.subscriptions.push(warcraftProductSubscription); + } ngOnInit(): void { this.selectedAddonChannelType = this._wowupService.getDefaultAddonChannel(this.clientType); @@ -44,6 +56,10 @@ export class WowClientOptionsComponent implements OnInit { this.clientLocation = this._warcraftService.getClientLocation(this.clientType); } + ngOnDestroy(): void { + this.subscriptions.forEach((sub) => sub.unsubscribe()); + } + onDefaultAddonChannelChange(evt: MatSelectChange) { this._wowupService.setDefaultAddonChannel(this.clientType, evt.value); } 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 21119a5f..36c10608 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 @@ -30,7 +30,6 @@ import { getEnumName } from "app/utils/enum.utils"; import { MatTableDataSource } from "@angular/material/table"; import { MatSort } from "@angular/material/sort"; import { stringIncludes } from "app/utils/string.utils"; -import { GetAddonListItem } from "app/business-objects/get-addon-list-item"; import { AddonDetailComponent } from "app/components/addon-detail/addon-detail.component"; @Component({ @@ -51,7 +50,6 @@ export class MyAddonsComponent implements OnInit, OnDestroy { private readonly _displayAddonsSrc = new BehaviorSubject( [] ); - private readonly _destroyed$ = new Subject(); private subscriptions: Subscription[] = []; private isSelectedTab: boolean = false; @@ -203,8 +201,6 @@ export class MyAddonsComponent implements OnInit, OnDestroy { ngOnDestroy(): void { this.subscriptions.forEach((sub) => sub.unsubscribe()); - this._destroyed$.next(); - this._destroyed$.complete(); } onRefresh() { diff --git a/wowup-electron/src/app/pages/options/options.component.html b/wowup-electron/src/app/pages/options/options.component.html index a9ec67d1..2799d800 100644 --- a/wowup-electron/src/app/pages/options/options.component.html +++ b/wowup-electron/src/app/pages/options/options.component.html @@ -21,19 +21,6 @@ {{'PAGES.OPTIONS.APPLICATION.TITLE' | translate}} -

{{'PAGES.OPTIONS.APPLICATION.TELEMETRY_LABEL' | translate}}

diff --git a/wowup-electron/src/app/pages/options/options.component.ts b/wowup-electron/src/app/pages/options/options.component.ts index 16b4356a..c2fb3380 100644 --- a/wowup-electron/src/app/pages/options/options.component.ts +++ b/wowup-electron/src/app/pages/options/options.component.ts @@ -11,17 +11,13 @@ import { WowClientType } from "app/models/warcraft/wow-client-type"; import { ElectronService } from "app/services"; import { WarcraftService } from "app/services/warcraft/warcraft.service"; import { WowUpService } from "app/services/wowup/wowup.service"; -import { filter, map } from "rxjs/operators"; import * as _ from "lodash"; -import * as path from "path"; import { MatDialog } from "@angular/material/dialog"; -import { AlertDialogComponent } from "app/components/alert-dialog/alert-dialog.component"; import { getEnumList, getEnumName } from "app/utils/enum.utils"; import { WowUpReleaseChannelType } from "app/models/wowup/wowup-release-channel-type"; import { MatSelectChange } from "@angular/material/select"; import { AnalyticsService } from "app/services/analytics/analytics.service"; import { AddonService } from "app/services/addons/addon.service"; -import { GET_ASSET_FILE_PATH } from "common/constants"; import { TranslateService } from "@ngx-translate/core"; @Component({ @@ -32,11 +28,6 @@ import { TranslateService } from "@ngx-translate/core"; export class OptionsComponent implements OnInit, OnChanges { @Input("tabIndex") tabIndex: number; - public retailLocation = ""; - public classicLocation = ""; - public retailPtrLocation = ""; - public classicPtrLocation = ""; - public betaLocation = ""; public collapseToTray = false; public telemetryEnabled = false; public wowClientTypes: WowClientType[] = getEnumList(WowClientType).filter( @@ -67,9 +58,7 @@ export class OptionsComponent implements OnInit, OnChanges { private _analyticsService: AnalyticsService, private warcraft: WarcraftService, private _electronService: ElectronService, - private _warcraftService: WarcraftService, public wowupService: WowUpService, - private _dialog: MatDialog, private zone: NgZone, public electronService: ElectronService, private _translateService: TranslateService @@ -118,113 +107,10 @@ export class OptionsComponent implements OnInit, OnChanges { await this._addonService.logDebugData(); } - async onSelectRetailClientPath() { - const selectedPath = await this.selectWowClientPath(WowClientType.Retail); - if (selectedPath) { - this.retailLocation = selectedPath; - } - } - - async onSelectRetailPtrClientPath() { - const selectedPath = await this.selectWowClientPath( - WowClientType.RetailPtr - ); - if (selectedPath) { - this.retailPtrLocation = selectedPath; - } - } - - async onSelectClassicClientPath() { - const selectedPath = await this.selectWowClientPath(WowClientType.Classic); - if (selectedPath) { - this.classicLocation = selectedPath; - } - } - - async onSelectClassicPtrClientPath() { - const selectedPath = await this.selectWowClientPath( - WowClientType.ClassicPtr - ); - if (selectedPath) { - this.classicPtrLocation = selectedPath; - } - } - - async onSelectBetaClientPath() { - const selectedPath = await this.selectWowClientPath(WowClientType.Beta); - if (selectedPath) { - this.betaLocation = selectedPath; - } - } - - private async selectWowClientPath( - clientType: WowClientType - ): Promise { - const dialogResult = await this._electronService.remote.dialog.showOpenDialog( - { - properties: ["openDirectory"], - } - ); - - if (dialogResult.canceled) { - return ""; - } - - const selectedPath = _.first(dialogResult.filePaths); - if (!selectedPath) { - console.warn("No path selected"); - return ""; - } - - console.log("dialogResult", selectedPath); - - if (this._warcraftService.setWowFolderPath(clientType, selectedPath)) { - return selectedPath; - } - - const clientFolderName = this._warcraftService.getClientFolderName( - clientType - ); - const clientExecutableName = this._warcraftService.getExecutableName( - clientType - ); - const clientExecutablePath = path.join( - selectedPath, - clientFolderName, - clientExecutableName - ); - const dialogRef = this._dialog.open(AlertDialogComponent, { - data: { - title: `Alert`, - message: `Unable to set "${selectedPath}" as your ${getEnumName( - WowClientType, - clientType - )} folder.\nPath not found: "${clientExecutablePath}".`, - }, - }); - - await dialogRef.afterClosed().toPromise(); - - return ""; - } - private loadData() { this.zone.run(() => { this.telemetryEnabled = this._analyticsService.telemetryEnabled; this.collapseToTray = this.wowupService.collapseToTray; - this.retailLocation = this.warcraft.getClientLocation( - WowClientType.Retail - ); - this.classicLocation = this.warcraft.getClientLocation( - WowClientType.Classic - ); - this.retailPtrLocation = this.warcraft.getClientLocation( - WowClientType.RetailPtr - ); - this.classicPtrLocation = this.warcraft.getClientLocation( - WowClientType.ClassicPtr - ); - this.betaLocation = this.warcraft.getClientLocation(WowClientType.Beta); }); } } diff --git a/wowup-electron/src/app/services/addons/addon.service.ts b/wowup-electron/src/app/services/addons/addon.service.ts index 93dd26c8..f49934d6 100644 --- a/wowup-electron/src/app/services/addons/addon.service.ts +++ b/wowup-electron/src/app/services/addons/addon.service.ts @@ -422,7 +422,7 @@ export class AddonService { rescan = false ): Promise { let addons = this._addonStorage.getAllForClientType(clientType); - if (rescan) { + if (rescan || addons.length === 0) { const newAddons = await this.scanAddons(clientType); console.log(newAddons); diff --git a/wowup-electron/src/app/services/warcraft/warcraft.service.ts b/wowup-electron/src/app/services/warcraft/warcraft.service.ts index 9661d7ec..99cf22a6 100644 --- a/wowup-electron/src/app/services/warcraft/warcraft.service.ts +++ b/wowup-electron/src/app/services/warcraft/warcraft.service.ts @@ -9,7 +9,6 @@ import * as path from "path"; import * as fs from "fs"; import { map, filter, delay, switchMap } from "rxjs/operators"; import { WowClientType } from "app/models/warcraft/wow-client-type"; -import { StorageService } from "../storage/storage.service"; import { WarcraftServiceMac } from "./warcraft.service.mac"; import { WarcraftServiceLinux } from "./warcraft.service.linux"; import { AddonFolder } from "app/models/wowup/addon-folder"; @@ -17,6 +16,7 @@ import { ElectronService } from ".."; import { TocService } from "../toc/toc.service"; import { getEnumList, getEnumName } from "app/utils/enum.utils"; import { FileService } from "../files/file.service"; +import { PreferenceStorageService } from "../storage/preference-storage.service"; // WOW STRINGS const CLIENT_RETAIL_FOLDER = "_retail_"; @@ -56,7 +56,7 @@ export class WarcraftService { constructor( private _electronService: ElectronService, private _fileService: FileService, - private storage: StorageService, + private _preferenceStorageService: PreferenceStorageService, private _tocService: TocService ) { this._impl = this.getImplementation(); @@ -225,12 +225,12 @@ export class WarcraftService { public getClientLocation(clientType: WowClientType) { const clientLocationKey = this.getClientLocationKey(clientType); - return this.storage.getPreference(clientLocationKey) || ""; + return this._preferenceStorageService.get(clientLocationKey) || ""; } public setClientLocation(clientType: WowClientType, clientPath: string) { const clientLocationKey = this.getClientLocationKey(clientType); - return this.storage.setPreference(clientLocationKey, clientPath); + return this._preferenceStorageService.set(clientLocationKey, clientPath); } public setWowFolderPath(