Fix wow client locations being set on initial load

This commit is contained in:
Dean Campbell
2020-10-20 13:28:01 -07:00
parent 999505f5a3
commit 78f52b39f1
6 changed files with 24 additions and 139 deletions

View File

@@ -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);
}

View File

@@ -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<AddonViewModel[]>(
[]
);
private readonly _destroyed$ = new Subject<void>();
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() {

View File

@@ -21,19 +21,6 @@
<mat-card-title>{{'PAGES.OPTIONS.APPLICATION.TITLE' | translate}}</mat-card-title>
</mat-card-header>
<mat-card-content>
<!-- <div class="row hover">
<div class="grow">
<p>WowUp Release Channel</p>
<small class="hint">Select Stable for a cleaner less buggy build. Select Beta to see the next wave of
features as they come.</small>
</div>
<mat-form-field class="light-select">
<mat-label>Release Channel</mat-label>
<mat-select [(value)]="wowUpReleaseChannel" (selectionChange)="onWowUpChannelChange($event)">
<mat-option *ngFor="let channel of wowUpReleaseChannels" [value]="channel.type" >{{channel.name}}</mat-option>
</mat-select>
</mat-form-field>
</div> -->
<div class="row ">
<div class="grow">
<p>{{'PAGES.OPTIONS.APPLICATION.TELEMETRY_LABEL' | translate}}</p>

View File

@@ -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<string> {
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);
});
}
}

View File

@@ -422,7 +422,7 @@ export class AddonService {
rescan = false
): Promise<Addon[]> {
let addons = this._addonStorage.getAllForClientType(clientType);
if (rescan) {
if (rescan || addons.length === 0) {
const newAddons = await this.scanAddons(clientType);
console.log(newAddons);

View File

@@ -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<string>(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(