diff --git a/wowup-electron/src/app/components/options/wow-client-options/wow-client-options.component.ts b/wowup-electron/src/app/components/options/wow-client-options/wow-client-options.component.ts index 2b357c32..5e3cd19c 100644 --- a/wowup-electron/src/app/components/options/wow-client-options/wow-client-options.component.ts +++ b/wowup-electron/src/app/components/options/wow-client-options/wow-client-options.component.ts @@ -1,6 +1,6 @@ import { dirname } from "path"; import { BehaviorSubject, from, of, Subscription } from "rxjs"; -import { filter, map, switchMap } from "rxjs/operators"; +import { filter, first, map, switchMap } from "rxjs/operators"; import { Component, Input, OnDestroy, OnInit } from "@angular/core"; import { MatDialog } from "@angular/material/dialog"; @@ -118,13 +118,19 @@ export class WowClientOptionsComponent implements OnInit, OnDestroy { throw new Error(`Failed to find installation: ${this.installationId}`); } - this.installationModel = { ...this.installation }; + this.resetInstallationModel(); + this.selectedAddonChannelType = this.installation.defaultAddonChannelType; this.clientAutoUpdate = this.installation.defaultAutoUpdate; this.clientTypeName = `COMMON.CLIENT_TYPES.${getEnumName( WowClientType, this.installation.clientType ).toUpperCase()}`; + + // `COMMON.CLIENT_TYPES.${getEnumName( + // WowClientType, + // this.installation.clientType + // ).toUpperCase()}`; this.clientFolderName = this.installation.label; this.clientLocation = this.installation.location; } @@ -170,10 +176,7 @@ export class WowClientOptionsComponent implements OnInit, OnDestroy { } public onClickCancel(): void { - if (this.installation) { - this.installationModel = { ...this.installation }; - } - + this.resetInstallationModel(); this._editModeSrc.next(false); } @@ -229,6 +232,22 @@ export class WowClientOptionsComponent implements OnInit, OnDestroy { .subscribe(); } + private resetInstallationModel() { + if (this.installation === undefined) { + return; + } + + this.installationModel = { ...this.installation }; + this._warcraftInstallationService + .getInstallationDisplayName(this.installation) + .then((name) => { + this.installationModel.label = name; + }) + .catch((e) => { + console.error(e); + }); + } + private getAddonChannelInfos(): { type: AddonChannelType; name: string }[] { return getEnumList(AddonChannelType).map((type: any) => { const channelName = getEnumName(AddonChannelType, type as number).toUpperCase(); diff --git a/wowup-electron/src/app/services/warcraft/warcraft-installation.service.ts b/wowup-electron/src/app/services/warcraft/warcraft-installation.service.ts index 8db92fd5..8889511c 100644 --- a/wowup-electron/src/app/services/warcraft/warcraft-installation.service.ts +++ b/wowup-electron/src/app/services/warcraft/warcraft-installation.service.ts @@ -17,6 +17,8 @@ import { WarcraftService } from "./warcraft.service"; import { AddonChannelType, WowClientGroup, WowClientType } from "wowup-lib-core"; import { WowInstallation } from "wowup-lib-core/lib/models"; +const DEFAULT_NAME_TOKEN = "{defaultName}"; + @Injectable({ providedIn: "root", }) @@ -89,9 +91,7 @@ export class WarcraftInstallationService { } public async getWowInstallationsAsync(): Promise { - const results = await this._preferenceStorageService.getObjectAsync( - WOW_INSTALLATIONS_KEY - ); + const results = await this._preferenceStorageService.getObjectAsync(WOW_INSTALLATIONS_KEY); return results || []; } @@ -136,6 +136,11 @@ export class WarcraftInstallationService { await this.setWowInstallations(allInstallations); } + public async getInstallationDisplayName(wowInstallation: WowInstallation): Promise { + const typeName = getEnumName(WowClientType, wowInstallation.clientType); + return await this.getDisplayName(wowInstallation.label, typeName); + } + public async updateWowInstallation(wowInstallation: WowInstallation): Promise { const typeName = getEnumName(WowClientType, wowInstallation.clientType); wowInstallation.displayName = await this.getDisplayName(wowInstallation.label, typeName); @@ -216,7 +221,10 @@ export class WarcraftInstallationService { const typeName = getEnumName(WowClientType, clientType); const currentInstallations = await this.getWowInstallationsByClientType(clientType); - const label = currentInstallations.length ? `{defaultName} ${currentInstallations.length + 1}` : "{defaultName}"; + const label = currentInstallations.length + ? `${DEFAULT_NAME_TOKEN} ${currentInstallations.length + 1}` + : DEFAULT_NAME_TOKEN; + const displayName = await this.getDisplayName(label, typeName); const installation: WowInstallation = { @@ -247,7 +255,7 @@ export class WarcraftInstallationService { const typeName = getEnumName(WowClientType, product.clientType); const currentInstallations = await this.getWowInstallationsByClientType(product.clientType); - const label = currentInstallations.length ? `{defaultName} ${currentInstallations.length + 1}` : "{defaultName}"; + const label = currentInstallations.length ? `${DEFAULT_NAME_TOKEN} ${currentInstallations.length + 1}` : DEFAULT_NAME_TOKEN; const displayName = await this.getDisplayName(label, typeName); const fullProductPath = this.getFullProductPath(product.location, product.clientType); @@ -282,7 +290,7 @@ export class WarcraftInstallationService { const defaultName: string = await firstValueFrom( this._translateService.get(`COMMON.CLIENT_TYPES.${typeName.toUpperCase()}`) ); - return label.replace("{defaultName}", defaultName); + return label.replace(DEFAULT_NAME_TOKEN, defaultName); } private getFullProductPath(location: string, clientType: WowClientType): string {