fix: auto launch

This commit is contained in:
wonfen
2025-03-17 13:51:52 +08:00
parent 70b0f9a03a
commit 530669d288
3 changed files with 56 additions and 8 deletions

View File

@@ -45,9 +45,10 @@ const SettingSystem = ({ onError }: Props) => {
// 当实际自启动状态与配置不同步时更新配置
useEffect(() => {
if (autoLaunchEnabled !== undefined && verge && verge.enable_auto_launch !== autoLaunchEnabled) {
patchVerge({ enable_auto_launch: autoLaunchEnabled });
// 静默更新配置不触发UI刷新
mutateVerge({ ...verge, enable_auto_launch: autoLaunchEnabled }, false);
}
}, [autoLaunchEnabled, verge]);
}, [autoLaunchEnabled]);
// 是否以sidecar模式运行
const isSidecarMode = runningMode === "sidecar";
@@ -190,7 +191,20 @@ const SettingSystem = ({ onError }: Props) => {
onCatch={onError}
onFormat={onSwitchFormat}
onChange={(e) => onChangeData({ enable_auto_launch: e })}
onGuard={(e) => patchVerge({ enable_auto_launch: e })}
onGuard={async (e) => {
try {
// 在应用更改之前先触发UI更新让用户立即看到反馈
onChangeData({ enable_auto_launch: e });
await patchVerge({ enable_auto_launch: e });
// 更新实际状态
await mutate("getAutoLaunchStatus");
return Promise.resolve();
} catch (error) {
// 如果出错,恢复原始状态
onChangeData({ enable_auto_launch: !e });
return Promise.reject(error);
}
}}
>
<Switch edge="end" />
</GuardState>

View File

@@ -119,7 +119,13 @@ export async function getAutotemProxy() {
}
export async function getAutoLaunchStatus() {
return invoke<boolean>("get_auto_launch_status");
try {
return await invoke<boolean>("get_auto_launch_status");
} catch (error) {
console.error("获取自启动状态失败:", error);
// 出错时返回false作为默认值
return false;
}
}
export async function changeClashCore(clashCore: string) {