[feat-560] ask user for installation folder/path

This commit is contained in:
silentrald
2024-08-23 22:09:32 +08:00
parent eba2b6fb03
commit 5e6837b8cd
22 changed files with 314 additions and 43 deletions
+8 -3
View File
@@ -1,4 +1,5 @@
import ElectronStore from "electron-store";
import fs from "fs-extra";
import { InstallationLocationService } from "./installation-location.service";
export class ConfigurationService {
@@ -17,13 +18,17 @@ export class ConfigurationService {
private constructor() {
this.locations = InstallationLocationService.getInstance();
this.initStore();
this.initStore(false);
this.locations.onInstallLocationUpdate(() => { this.initStore() });
this.locations.onInstallLocationUpdate(() => this.initStore(true));
}
private async initStore() {
private async initStore(createFolder: boolean) {
const contentPath = this.locations.installationDirectory();
if (!createFolder && !fs.pathExistsSync(contentPath)) {
return;
}
this.store = new ElectronStore({
cwd: contentPath,
name: "config",
@@ -59,6 +59,12 @@ export class InstallationLocationService {
this.updateListeners.add(fn);
}
public defaultInstallationDirectory(): string {
const { result: oldPath } = tryit(() => path.join(app.getPath("documents"), this.INSTALLATION_FOLDER));
const installationDirectory = (oldPath && pathExistsSync(oldPath)) ? app.getPath("documents") : app.getPath("home");
return path.join(installationDirectory, this.INSTALLATION_FOLDER);
}
public installationDirectory(): string {
const installParentPath = () => {