fix(failover): switch to P1 immediately when enabling auto failover

Previously, enabling auto failover kept using the current provider until
the first failure, causing inconsistency when the current provider was
not in the failover queue. When stopping proxy, the restored config
would not match user expectations.

New behavior:
- Enable auto failover = immediately switch to queue P1
- Subsequent routing follows queue order (P1→P2→...)
- Auto-add current provider to queue if queue is empty

Changes:
- Add switch_proxy_target() for hot-switching during proxy mode
- Update provider_router to use queue order when failover enabled
- Sync tray menu Auto click with the same logic
- Update UI tooltips to reflect new semantics
- Add tests for queue-only routing scenario
This commit is contained in:
Jason
2026-01-21 11:27:44 +08:00
parent b993b1f664
commit a187380d6f
12 changed files with 357 additions and 28 deletions
+15
View File
@@ -268,6 +268,21 @@ export function useSetAutoFailoverEnabled() {
queryClient.invalidateQueries({
queryKey: ["autoFailoverEnabled", variables.appType],
});
// 启用/关闭故障转移可能触发:
// - 立即切到队列 P1(当前供应商变化)
// - 队列为空时自动把当前供应商加入队列(队列内容变化)
queryClient.invalidateQueries({
queryKey: ["failoverQueue", variables.appType],
});
queryClient.invalidateQueries({
queryKey: ["availableProvidersForFailover", variables.appType],
});
queryClient.invalidateQueries({
queryKey: ["providers", variables.appType],
});
queryClient.invalidateQueries({
queryKey: ["proxyStatus"],
});
},
});
}