Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
try to fix unknown error
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Sep 14, 2024
1 parent 5f1a46b commit c8ae4d8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export async function getAppConfig(force = false): Promise<IAppConfig> {
const data = await readFile(appConfigPath(), 'utf-8')
appConfig = yaml.parse(data) || defaultConfig
}
if (typeof appConfig !== 'object') appConfig = defaultConfig
return appConfig
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/config/controledMihomo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export async function getControledMihomoConfig(force = false): Promise<Partial<I
const data = await readFile(controledMihomoConfigPath(), 'utf-8')
controledMihomoConfig = yaml.parse(data) || defaultControledMihomoConfig
}
if (typeof controledMihomoConfig !== 'object')
controledMihomoConfig = defaultControledMihomoConfig
return controledMihomoConfig
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/config/override.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ let overrideConfig: IOverrideConfig // override.yaml
export async function getOverrideConfig(force = false): Promise<IOverrideConfig> {
if (force || !overrideConfig) {
const data = await readFile(overrideConfigPath(), 'utf-8')
overrideConfig = yaml.parse(data) || {}
overrideConfig = yaml.parse(data) || { items: [] }
}
if (typeof overrideConfig !== 'object') overrideConfig = { items: [] }
return overrideConfig
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/config/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ let profileConfig: IProfileConfig // profile.yaml
export async function getProfileConfig(force = false): Promise<IProfileConfig> {
if (force || !profileConfig) {
const data = await readFile(profileConfigPath(), 'utf-8')
profileConfig = yaml.parse(data)
profileConfig = yaml.parse(data) || { items: [] }
}
if (typeof profileConfig !== 'object') profileConfig = { items: [] }
return profileConfig
}

Expand Down Expand Up @@ -168,7 +169,9 @@ export async function setProfileStr(id: string, content: string): Promise<void>

export async function getProfile(id: string | undefined): Promise<IMihomoConfig> {
const profile = await getProfileStr(id)
return yaml.parse(profile) || {}
let result = yaml.parse(profile) || {}
if (typeof result !== 'object') result = {}
return result
}

// attachment;filename=xxx.yaml; filename*=UTF-8''%xx%xx%xx
Expand Down
3 changes: 2 additions & 1 deletion src/main/core/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ async function overrideProfile(
profile = runOverrideScript(profile, content, item)
break
case 'yaml': {
const patch = yaml.parse(content) || {}
let patch = yaml.parse(content) || {}
if (typeof patch !== 'object') patch = {}
profile = deepMerge(profile, patch)
break
}
Expand Down

0 comments on commit c8ae4d8

Please sign in to comment.