diff --git a/src/main/services/liv/liv-shortcut.service.ts b/src/main/services/liv/liv-shortcut.service.ts index 71ce0997..85cc92f3 100644 --- a/src/main/services/liv/liv-shortcut.service.ts +++ b/src/main/services/liv/liv-shortcut.service.ts @@ -8,6 +8,7 @@ import { debounceTime, distinctUntilChanged, map } from "rxjs"; import equal from "fast-deep-equal"; import sanitize from "sanitize-filename"; import { tryit } from "../../../shared/helpers/error.helpers"; +import log from "electron-log" export class LivShortcut { @@ -20,7 +21,7 @@ export class LivShortcut { return LivShortcut.instance; } - private readonly LIB_ID_PREFIX = "BSManager"; + private readonly LIV_ID_PREFIX = "BSManager"; private readonly liv: LivService; private readonly launcher: BSLauncherService; @@ -34,15 +35,18 @@ export class LivShortcut { this.liv.isLivInstalled().then(installed => { if(!installed){ return; } - this.versionManager.loadedVersions$.pipe(debounceTime(1000), distinctUntilChanged((prev, curr) => equal(prev, curr)), map(versions => versions.filter(v => !v.steam))).subscribe(async versions => { - const clearedLaunchOptions = (await this.clearLivShortcuts().catch(() => [] as LivEntry[])).map(entry => { - return tryit(() => this.launcher.shortcutLinkToLaunchOptions(entry.arguments)).result; - }); - versions.forEach(version => this.createLivShortcut({ - ...(clearedLaunchOptions.find(launchOpt => launchOpt.version.ino === version.ino) ?? {}), - version, - skipAlreadyRunning: true - })); + this.versionManager.loadedVersions$.pipe(debounceTime(1000), distinctUntilChanged((prev, curr) => equal(prev, curr)), map(versions => versions.filter(v => !v.steam))).subscribe(versions => { + (async () => { + const clearedLaunchOptions = (await this.clearLivShortcuts().catch(() => [] as LivEntry[]))?.map(entry => { + return tryit(() => this.launcher.shortcutLinkToLaunchOptions(entry.arguments)).result; + }); + + versions.forEach(version => this.createLivShortcut({ + ...(clearedLaunchOptions?.find(launchOpt => launchOpt.version.ino === version.ino) ?? {}), + version, + skipAlreadyRunning: true + })); + })().catch(err => log.error("Error while creating LIV shortcuts", err)); }); }); } @@ -53,7 +57,7 @@ export class LivShortcut { if(version.oculus){ return "Oculus"; } return version.name; })(); - return sanitize([this.LIB_ID_PREFIX, name, version.BSVersion].filter(Boolean).join("-").replaceAll(".", "-").replaceAll(" ", "-")); + return sanitize([this.LIV_ID_PREFIX, name, version.BSVersion].filter(Boolean).join("-").replaceAll(".", "-").replaceAll(" ", "-")); } private buildShortcutName(version: BSVersion): string { @@ -79,13 +83,9 @@ export class LivShortcut { return this.buildLivEntry(launchOptions).then(entry => this.liv.createLivShortcut(entry)); } - private async deleteLivShortcut(bsVersion: BSVersion): Promise{ - return this.liv.deleteLivShortcut(this.buildShortcutId(bsVersion)); - } - private async clearLivShortcuts(): Promise{ const bsmShortcuts = (await this.liv.getLivShortcuts()).reduce((acc, shortcut) => { - if(shortcut.id?.startsWith(this.LIB_ID_PREFIX)){ + if(shortcut.id?.startsWith(this.LIV_ID_PREFIX)){ acc.push(shortcut); } return acc; diff --git a/src/main/services/liv/liv.service.ts b/src/main/services/liv/liv.service.ts index 4460d91d..7c60825e 100644 --- a/src/main/services/liv/liv.service.ts +++ b/src/main/services/liv/liv.service.ts @@ -58,15 +58,6 @@ export class LivService { }); } - public async deleteLivShortcut(id: string): Promise { - return execOnOs({ - win32: async () => { - const livExternalAppRegeditKey = path.join(this.livExternalAppsRegeditKey, id); - return regedit.promisified.deleteKey([livExternalAppRegeditKey]); - } - }); - } - public async deleteLivShortcuts(ids: string[]): Promise { return execOnOs({ win32: async () => {