diff --git a/wowup-electron/src/app/addon-providers/curse-addon-v2-provider.ts b/wowup-electron/src/app/addon-providers/curse-addon-v2-provider.ts index 1552baf4..0be1f1ee 100644 --- a/wowup-electron/src/app/addon-providers/curse-addon-v2-provider.ts +++ b/wowup-electron/src/app/addon-providers/curse-addon-v2-provider.ts @@ -485,7 +485,6 @@ export class CurseAddonV2Provider extends AddonProvider { ): Promise { const searchResults: AddonSearchResult[] = []; - const gameVersionType = this.getGameVersionTypeId(installation.clientType); const response = await this.getSearchResults(query, installation.clientType); await this.removeBlockedItems(response); @@ -614,7 +613,7 @@ export class CurseAddonV2Provider extends AddonProvider { return from(this.getClient()).pipe( switchMap((client) => from( - this._circuitBreaker.fire(() => client.getModFile(parseInt(addonId as any, 10), parseInt(fileId as any, 10))) + this._circuitBreaker.fire(() => client.getModFile(parseInt(`${addonId}`, 10), parseInt(`${fileId}`, 10))) ) ), map((response) => response.data.data) @@ -1037,7 +1036,7 @@ export class CurseAddonV2Provider extends AddonProvider { case WowClientGroup.Retail: return CF2WowGameVersionType.Retail; default: - throw new Error(`invalid game type: ${clientGroup}`); + throw new Error(`invalid game type: ${clientGroup as string}`); } } diff --git a/wowup-electron/src/app/components/common/vertical-tabs/vertical-tabs.component.ts b/wowup-electron/src/app/components/common/vertical-tabs/vertical-tabs.component.ts index 69ed9f08..194e6bd9 100644 --- a/wowup-electron/src/app/components/common/vertical-tabs/vertical-tabs.component.ts +++ b/wowup-electron/src/app/components/common/vertical-tabs/vertical-tabs.component.ts @@ -1,4 +1,4 @@ -import { BehaviorSubject, combineLatest, Observable, of, Subject } from "rxjs"; +import { BehaviorSubject, combineLatest, Observable, Subject } from "rxjs"; import { map, takeUntil } from "rxjs/operators"; import { Component, OnDestroy, OnInit } from "@angular/core"; diff --git a/wowup-electron/src/app/components/options/options-addon-section/options-addon-section.component.ts b/wowup-electron/src/app/components/options/options-addon-section/options-addon-section.component.ts index 5f18ff7a..b495602a 100644 --- a/wowup-electron/src/app/components/options/options-addon-section/options-addon-section.component.ts +++ b/wowup-electron/src/app/components/options/options-addon-section/options-addon-section.component.ts @@ -1,9 +1,9 @@ -import { Component, OnInit } from "@angular/core"; +import { Component, OnDestroy, OnInit } from "@angular/core"; import { AddonProviderState } from "../../../models/wowup/addon-provider-state"; import { MatSelectionListChange } from "@angular/material/list"; import { AddonProviderFactory } from "../../../services/addons/addon.provider.factory"; import { AddonProviderType } from "../../../addon-providers/addon-provider"; -import { BehaviorSubject, catchError, debounceTime, first, from, map, of } from "rxjs"; +import { BehaviorSubject, catchError, debounceTime, first, from, map, of, Subject, switchMap, takeUntil } from "rxjs"; import { PreferenceStorageService } from "../../../services/storage/preference-storage.service"; import { PREF_CF2_API_KEY } from "../../../../common/constants"; import { FormControl, FormGroup } from "@angular/forms"; @@ -18,7 +18,9 @@ interface AddonProviderStateModel extends AddonProviderState { templateUrl: "./options-addon-section.component.html", styleUrls: ["./options-addon-section.component.scss"], }) -export class OptionsAddonSectionComponent implements OnInit { +export class OptionsAddonSectionComponent implements OnInit, OnDestroy { + private destroy$: Subject = new Subject(); + public addonProviderStates$ = new BehaviorSubject([]); public preferenceForm = new FormGroup({ @@ -33,15 +35,22 @@ export class OptionsAddonSectionComponent implements OnInit { this.loadProviderStates(); }); - this.preferenceForm.valueChanges.pipe(debounceTime(300)).subscribe(async (ch) => { - try { - if (ch.cfV2ApiKey) { - this._preferenceStorageService.setAsync(PREF_CF2_API_KEY, ch.cfV2ApiKey); - } - } catch (e) { - console.error(e); - } - }); + this.preferenceForm.valueChanges + .pipe( + takeUntil(this.destroy$), + debounceTime(300), + switchMap((ch) => { + if (ch.cfV2ApiKey) { + return from(this._preferenceStorageService.setAsync(PREF_CF2_API_KEY, ch.cfV2ApiKey)); + } + return of(undefined); + }), + catchError((e) => { + console.error(e); + return of(undefined); + }) + ) + .subscribe(); } public ngOnInit(): void { @@ -49,6 +58,11 @@ export class OptionsAddonSectionComponent implements OnInit { this.loadCfV2ApiKey(); } + public ngOnDestroy(): void { + this.destroy$.next(true); + this.destroy$.unsubscribe(); + } + public async onProviderStateSelectionChange(event: MatSelectionListChange): Promise { for (const option of event.options) { const providerName: AddonProviderType = option.value;