A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io
Rust ai-toolsclaude-codecodexdeepseek-harnessdesktop-appgrokgrokbuildhermeskimi-codemcpopen-sourceopencodepiprovider-managementrustskillsskills-managementtauriwsl-support
fix(qoder): refresh the provider list and tray when the edition changes
Jasonda3076f2aca1
diff --git a/src-tauri/src/commands/settings.rs b/src-tauri/src/commands/settings.rsindex 18062bb97..a19ea704c 100644--- a/src-tauri/src/commands/settings.rs+++ b/src-tauri/src/commands/settings.rs@@ -137,9 +137,10 @@ pub async fn save_settings(// 原生托盘菜单 / 托盘面板当场切换,不用重启。if tray_style_changed {crate::tray::apply_tray_style(&app);- } else if visible_apps_changed {+ } else if visible_apps_changed || qoder_edition_changed {// 托盘只列应用页里开着的应用:不管从哪条路径保存(侧栏「从侧栏隐藏」不会再调- // update_tray_menu),开关一变就重建托盘。+ // update_tray_menu),开关一变就重建托盘。Qoder 的「已添加」按当前版本的文件现算,+ // 换了版本也要重建。crate::tray::refresh_tray_menu(&app);}diff --git a/src/lib/query/mutations.ts b/src/lib/query/mutations.tsindex ea50c6559..546c0af20 100644--- a/src/lib/query/mutations.ts+++ b/src/lib/query/mutations.ts@@ -27,6 +27,7 @@ import {} from "@/lib/query/subscription";import { GROKBUILD_OFFICIAL_PROVIDER_ID } from "@/utils/providerCapabilities";import { appHas } from "@/config/appSpecs";+import { qoderEdition } from "@/config/qoder";export const useAddProviderMutation = (appId: AppId) => {const queryClient = useQueryClient();@@ -549,16 +550,29 @@ export const useDeleteSessionMutation = () => {export const useSaveSettingsMutation = () => {const queryClient = useQueryClient();+ const { i18n } = useTranslation();return useMutation({mutationFn: async (settings: Settings) => {+ // 保存前的版本要在保存前从缓存里取:没选版本时改界面语言也会换版本+ const previous = queryClient.getQueryData<Settings>(["settings"]);await settingsApi.save(settings);+ return (+ qoderEdition(previous, i18n.language) !==+ qoderEdition(settings, i18n.language)+ );},- onSuccess: async () => {+ onSuccess: async (qoderEditionChanged) => {await queryClient.invalidateQueries({ queryKey: ["settings"] });await queryClient.invalidateQueries({queryKey: ["opencode", "runtime-models"],});+ // 供应商列表的键不带版本:换了版本不重读,就还显示上一个版本的「已添加 / 默认」+ if (qoderEditionChanged) {+ await queryClient.invalidateQueries({+ queryKey: ["providers", "qoder"],+ });+ }},});};diff --git a/tests/hooks/useSaveSettingsMutation.test.tsx b/tests/hooks/useSaveSettingsMutation.test.tsxnew file mode 100644index 000000000..260935ce2--- /dev/null+++ b/tests/hooks/useSaveSettingsMutation.test.tsx@@ -0,0 +1,55 @@+import type { ReactNode } from "react";+import { act, renderHook } from "@testing-library/react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { describe, expect, it, vi } from "vitest";+import { useSaveSettingsMutation } from "@/lib/query/mutations";+import type { Settings } from "@/types";++function setup(saved: Partial<Settings>) {+ const queryClient = new QueryClient({+ defaultOptions: { queries: { retry: false }, mutations: { retry: false } },+ });+ queryClient.setQueryData(["settings"], saved as Settings);+ const invalidate = vi.spyOn(queryClient, "invalidateQueries");+ const wrapper = ({ children }: { children: ReactNode }) => (+ <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>+ );+ const { result } = renderHook(() => useSaveSettingsMutation(), { wrapper });+ const qoderInvalidated = () =>+ invalidate.mock.calls.some(+ ([filters]) =>+ JSON.stringify(filters?.queryKey) ===+ JSON.stringify(["providers", "qoder"]),+ );+ return { result, qoderInvalidated };+}++describe("useSaveSettingsMutation", () => {+ it("re-reads the Qoder provider list when the edition changes", async () => {+ const { result, qoderInvalidated } = setup({ qoderEdition: "global" });+ await act(() =>+ result.current.mutateAsync({ qoderEdition: "cn" } as Settings),+ );+ expect(qoderInvalidated()).toBe(true);+ });++ it("treats a language change as an edition change when no edition was chosen", async () => {+ const { result, qoderInvalidated } = setup({ language: "zh" });+ await act(() => result.current.mutateAsync({ language: "en" } as Settings));+ expect(qoderInvalidated()).toBe(true);+ });++ it("leaves the Qoder provider list alone when the edition stays the same", async () => {+ const { result, qoderInvalidated } = setup({+ qoderEdition: "cn",+ language: "zh",+ });+ await act(() =>+ result.current.mutateAsync({+ qoderEdition: "cn",+ language: "en",+ } as Settings),+ );+ expect(qoderInvalidated()).toBe(false);+ });+});