[feat-560] delay song details cache loading after user setup is done

added check if ElectronStore is null
This commit is contained in:
silentrald
2024-08-24 00:40:10 +08:00
parent 5e6837b8cd
commit d3c797041f
3 changed files with 18 additions and 4 deletions
@@ -1,6 +1,7 @@
import ElectronStore from "electron-store";
import fs from "fs-extra";
import { InstallationLocationService } from "./installation-location.service";
import { CustomError } from "shared/models/exceptions/custom-error.class";
export class ConfigurationService {
private static instance: ConfigurationService;
@@ -14,6 +15,7 @@ export class ConfigurationService {
private readonly locations: InstallationLocationService;
private contentPath: string;
private store: ElectronStore;
private constructor() {
@@ -29,6 +31,7 @@ export class ConfigurationService {
return;
}
this.contentPath = contentPath;
this.store = new ElectronStore({
cwd: contentPath,
name: "config",
@@ -37,15 +40,25 @@ export class ConfigurationService {
});
}
private checkStore(): void {
// Can be null if config.cfg does not exist or corrupted
if (!this.store) {
throw CustomError.fromError(new Error(`Can't read config.cfg on ${this.contentPath}`));
}
}
public set(key: string, value: unknown): void {
this.checkStore();
this.store.set(key, value);
}
public get<T>(key: string): T {
this.checkStore();
return this.store.get(key) as T;
}
public delete(key: string): void {
this.checkStore();
this.store.delete(key);
}
}
@@ -77,7 +77,7 @@ export const AskInstallPathModal: ModalComponent<{ installPath: string }, {}> =
<BsmButton
onClick={selectInstallPath}
className="shrink-1 whitespace-nowrap mr-2 px-2 font-bold italic text-sm rounded-md"
text={"modals.ask-install-path.choose-folder"}
text="modals.ask-install-path.choose-folder"
withBar={false}
/>
</div>
@@ -88,14 +88,14 @@ export const AskInstallPathModal: ModalComponent<{ installPath: string }, {}> =
className="col-start-3 rounded-md text-center transition-all"
onClick={onDefaultButtonPressed}
withBar={false}
text={"modals.ask-install-path.default"}
text="modals.ask-install-path.default"
/>
<BsmButton
typeColor="primary"
className="col-start-4 z-0 px-1 rounded-md text-center transition-all"
type="submit"
withBar={false}
text={"misc.confirm"}
text="misc.confirm"
/>
</div>
</form>
+2 -1
View File
@@ -33,6 +33,7 @@ export class SetupService {
public async check(): Promise<void> {
try {
// NOTE: for modal sequencing
await this.checkInstallationPath();
} catch (error) {
logRenderError(error);
@@ -57,7 +58,7 @@ export class SetupService {
await lastValueFrom(this.steamDownloaderService.setInstallationFolder(modalResponse.data.installPath));
// Refresh the versions tab
await this.versionManagerService.askInstalledVersions()
await this.versionManagerService.askInstalledVersions();
} catch (error) {
logRenderError(error);
}