refactor: structure config validation outcomes

- Replace boolean/string validation results with structured ValidationOutcome values across config validation, profile switching, DNS validation, and script validation. Callers can now distinguish valid, invalid, skipped, and busy states, with invalid results carrying an error kind and message.

- Route core config updates through structured outcomes and checked forced updates. Generation and validation failures now discard runtime drafts and surface validation failures instead of relying on empty success messages.

- Preserve existing frontend ergonomics by keeping boolean service wrappers where callers only need success, while direct DNS and script validation consumers receive ValidationOutcome. Failed profile editor saves reload the backend-restored file content and synchronize Monaco models so reopened editors show the restored state.
This commit is contained in:
Tunglies
2026-04-25 13:31:08 +08:00
parent 5882722031
commit b85b435e00
26 changed files with 612 additions and 482 deletions
+16 -4
View File
@@ -14,11 +14,16 @@ export async function getProfiles() {
}
export async function enhanceProfiles() {
return invoke<void>('enhance_profiles')
return (
(await invoke<ValidationOutcome>('enhance_profiles')).status === 'valid'
)
}
export async function patchProfilesConfig(profiles: IProfilesConfig) {
return invoke<boolean>('patch_profiles_config', { profiles })
return (
(await invoke<ValidationOutcome>('patch_profiles_config', { profiles }))
.status === 'valid'
)
}
export async function createProfile(
@@ -37,7 +42,14 @@ export async function readProfileFile(index: string) {
}
export async function saveProfileFile(index: string, fileData: string) {
return invoke<void>('save_profile_file', { index, fileData })
return (
(
await invoke<ValidationOutcome>('save_profile_file', {
index,
fileData,
})
).status === 'valid'
)
}
export async function importProfile(url: string, option?: IProfileOption) {
@@ -492,7 +504,7 @@ export async function scriptValidateNotice(status: string, msg: string) {
}
export async function validateScriptFile(filePath: string) {
return invoke<boolean>('validate_script_file', { filePath })
return invoke<ValidationOutcome>('validate_script_file', { filePath })
}
// 获取当前运行模式