Skip to content

Commit

Permalink
fix: 修复config导致的白屏问题
Browse files Browse the repository at this point in the history
  • Loading branch information
maotoumao committed Dec 23, 2024
1 parent 51bc117 commit b341271
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/shared/app-config/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AppConfig {
throw new Error("Not a valid path");
}
} catch {
await fs.writeFile(this.configPath, "{}", "utf-8");
await fs.writeFile(this.configPath, JSON.stringify(_defaultAppConfig, undefined, 4), "utf-8");
}
}

Expand Down Expand Up @@ -88,7 +88,6 @@ class AppConfig {
try {
const oldConfig = this.config as any;
const newConfig = {
..._defaultAppConfig,
"normal.closeBehavior": oldConfig.normal?.closeBehavior === "exit" ? "exit_app" : oldConfig.normal?.closeBehavior,
"normal.maxHistoryLength": oldConfig.normal?.maxHistoryLength,
"normal.checkUpdate": oldConfig.normal?.checkUpdate,
Expand Down Expand Up @@ -157,12 +156,16 @@ class AppConfig {
async loadConfig() {
try {
if (this.config) {
return this.config;
return {..._defaultAppConfig, ...this.config};
} else {
const rawConfig = await fs.readFile(this.configPath, "utf8");
this.config = JSON.parse(rawConfig);
// 升级旧版设置
await this.migrateOldVersionConfig();
this.config = {
..._defaultAppConfig,
...this.config,
}
}
} catch (e) {
if (e.message === "Unexpected end of JSON input" || e.code === "EISDIR") {
Expand Down

0 comments on commit b341271

Please sign in to comment.