From e4a894f75af1a56977f48dc02ae17785d3fe0f42 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Mon, 16 Sep 2024 22:06:59 +0200 Subject: [PATCH] [bugfix] Choose content folder was asked after each restart of BSM + add a log --- src/main/services/folder-linker.service.ts | 3 ++- .../services/static-configuration.service.ts | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/services/folder-linker.service.ts b/src/main/services/folder-linker.service.ts index 134be320..3aa79353 100644 --- a/src/main/services/folder-linker.service.ts +++ b/src/main/services/folder-linker.service.ts @@ -28,8 +28,9 @@ export class FolderLinkerService { this.staticConfig = StaticConfigurationService.getInstance(); this.linkingType = this.staticConfig.get("use-symlinks") === true ? "symlink" : "junction"; + log.info(`Linking type is set to ${this.linkingType}`); - this.staticConfig.$watch("use-symlinks").subscribe(({ newValue: useSymlink }) => { + this.staticConfig.$watch("use-symlinks").subscribe((useSymlink) => { this.linkingType = useSymlink === true ? "symlink" : "junction"; log.info(`Linking type set to ${this.linkingType}`); }); diff --git a/src/main/services/static-configuration.service.ts b/src/main/services/static-configuration.service.ts index 907feda0..87f6f2f1 100644 --- a/src/main/services/static-configuration.service.ts +++ b/src/main/services/static-configuration.service.ts @@ -1,5 +1,5 @@ import ElectronStore from "electron-store"; -import { Observable } from "rxjs"; +import { Observable, Subject } from "rxjs"; import { BSVersion } from "shared/bs-version.interface"; export class StaticConfigurationService { @@ -14,8 +14,12 @@ export class StaticConfigurationService { private readonly store: ElectronStore; + private readonly watchers: { + [K in StaticConfigKeys]?: Subject; + } = {}; + private constructor() { - this.store = new ElectronStore({ watch: true }); + this.store = new ElectronStore(); } public has(key: K): boolean { @@ -32,6 +36,10 @@ export class StaticConfigurationService { public set(key: K, value: StaticConfigKeyValues[K]): void { this.store.set(key, value); + + if (this.watchers[key]) { + this.watchers[key].next(value); // update watchers if any + } } public delete(key: K): void { @@ -42,14 +50,12 @@ export class StaticConfigurationService { return this.store; } - public $watch(key: K): Observable<{ newValue: StaticConfigKeyValues[K], oldValue: StaticConfigKeyValues[K] }> { - return new Observable(obs => { - const unsub = this.store.onDidChange(key, (newValue, oldValue) => { - obs.next({ newValue, oldValue } as { newValue: StaticConfigKeyValues[K], oldValue: StaticConfigKeyValues[K] }); - }); + public $watch(key: K): Observable { + if (!this.watchers[key]) { + this.watchers[key] = new Subject() as any; // avoid type error here, the essential is that it work using the function + } - return () => unsub(); - }) + return this.watchers[key]; } }