2025-05-15 08:54:42 +08:00
|
|
|
import { useAppearanceStore } from "@/stores/appearanceStore";
|
2025-04-22 18:32:20 +08:00
|
|
|
import { useConnectStore } from "@/stores/connectStore";
|
2025-04-15 20:13:42 +08:00
|
|
|
import { useShortcutsStore } from "@/stores/shortcutsStore";
|
|
|
|
|
import { useStartupStore } from "@/stores/startupStore";
|
|
|
|
|
import platformAdapter from "@/utils/platformAdapter";
|
2025-05-14 15:03:17 +08:00
|
|
|
import { isNumber } from "lodash-es";
|
2025-04-15 20:13:42 +08:00
|
|
|
import { useEffect } from "react";
|
|
|
|
|
|
|
|
|
|
export const useSyncStore = () => {
|
|
|
|
|
const setModifierKey = useShortcutsStore((state) => {
|
|
|
|
|
return state.setModifierKey;
|
|
|
|
|
});
|
|
|
|
|
const setModeSwitch = useShortcutsStore((state) => {
|
|
|
|
|
return state.setModeSwitch;
|
|
|
|
|
});
|
|
|
|
|
const setReturnToInput = useShortcutsStore((state) => {
|
|
|
|
|
return state.setReturnToInput;
|
|
|
|
|
});
|
|
|
|
|
const setVoiceInput = useShortcutsStore((state) => {
|
|
|
|
|
return state.setVoiceInput;
|
|
|
|
|
});
|
|
|
|
|
const setAddFile = useShortcutsStore((state) => {
|
|
|
|
|
return state.setAddFile;
|
|
|
|
|
});
|
|
|
|
|
const setDefaultStartupWindow = useStartupStore((state) => {
|
|
|
|
|
return state.setDefaultStartupWindow;
|
|
|
|
|
});
|
|
|
|
|
const setDefaultContentForSearchWindow = useStartupStore((state) => {
|
|
|
|
|
return state.setDefaultContentForSearchWindow;
|
|
|
|
|
});
|
|
|
|
|
const setDefaultContentForChatWindow = useStartupStore((state) => {
|
|
|
|
|
return state.setDefaultContentForChatWindow;
|
|
|
|
|
});
|
|
|
|
|
const setDeepThinking = useShortcutsStore((state) => {
|
|
|
|
|
return state.setDeepThinking;
|
|
|
|
|
});
|
|
|
|
|
const setInternetSearch = useShortcutsStore((state) => {
|
|
|
|
|
return state.setInternetSearch;
|
|
|
|
|
});
|
|
|
|
|
const setInternetSearchScope = useShortcutsStore((state) => {
|
|
|
|
|
return state.setInternetSearchScope;
|
|
|
|
|
});
|
2025-04-25 14:47:34 +08:00
|
|
|
const setMcpSearch = useShortcutsStore((state) => {
|
|
|
|
|
return state.setMcpSearch;
|
|
|
|
|
});
|
|
|
|
|
const setMcpSearchScope = useShortcutsStore((state) => {
|
|
|
|
|
return state.setMcpSearchScope;
|
|
|
|
|
});
|
2025-04-15 20:13:42 +08:00
|
|
|
const setHistoricalRecords = useShortcutsStore((state) => {
|
|
|
|
|
return state.setHistoricalRecords;
|
|
|
|
|
});
|
2025-04-22 18:36:59 +08:00
|
|
|
const setAiAssistant = useShortcutsStore((state) => {
|
|
|
|
|
return state.setAiAssistant;
|
|
|
|
|
});
|
2025-04-15 20:13:42 +08:00
|
|
|
const setNewSession = useShortcutsStore((state) => {
|
|
|
|
|
return state.setNewSession;
|
|
|
|
|
});
|
|
|
|
|
const setFixedWindow = useShortcutsStore((state) => {
|
|
|
|
|
return state.setFixedWindow;
|
|
|
|
|
});
|
|
|
|
|
const setServiceList = useShortcutsStore((state) => {
|
|
|
|
|
return state.setServiceList;
|
|
|
|
|
});
|
|
|
|
|
const setExternal = useShortcutsStore((state) => {
|
|
|
|
|
return state.setExternal;
|
|
|
|
|
});
|
2025-04-18 16:17:05 +08:00
|
|
|
const fixedWindow = useShortcutsStore((state) => {
|
|
|
|
|
return state.fixedWindow;
|
|
|
|
|
});
|
|
|
|
|
const resetFixedWindow = useShortcutsStore((state) => {
|
|
|
|
|
return state.resetFixedWindow;
|
|
|
|
|
});
|
|
|
|
|
const setResetFixedWindow = useShortcutsStore((state) => {
|
|
|
|
|
return state.setResetFixedWindow;
|
|
|
|
|
});
|
2025-04-22 18:32:20 +08:00
|
|
|
const setConnectionTimeout = useConnectStore((state) => {
|
|
|
|
|
return state.setConnectionTimeout;
|
|
|
|
|
});
|
|
|
|
|
const setQueryTimeout = useConnectStore((state) => {
|
2025-04-27 20:10:54 +08:00
|
|
|
return state.setQuerySourceTimeout;
|
2025-04-22 18:32:20 +08:00
|
|
|
});
|
2025-04-29 17:08:01 +08:00
|
|
|
const setOpacity = useAppearanceStore((state) => state.setOpacity);
|
2025-05-07 16:43:44 +08:00
|
|
|
const setSnapshotUpdate = useAppearanceStore((state) => {
|
|
|
|
|
return state.setSnapshotUpdate;
|
|
|
|
|
});
|
2025-05-14 16:00:40 +08:00
|
|
|
const setAllowSelfSignature = useConnectStore((state) => {
|
|
|
|
|
return state.setAllowSelfSignature;
|
|
|
|
|
});
|
2025-04-15 20:13:42 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2025-04-18 16:17:05 +08:00
|
|
|
if (!resetFixedWindow) {
|
|
|
|
|
if (fixedWindow === "F") {
|
|
|
|
|
setFixedWindow("P");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setResetFixedWindow(true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-15 20:13:42 +08:00
|
|
|
const unListeners = Promise.all([
|
|
|
|
|
platformAdapter.listenEvent("change-shortcuts-store", ({ payload }) => {
|
|
|
|
|
const {
|
|
|
|
|
modifierKey,
|
|
|
|
|
modeSwitch,
|
|
|
|
|
returnToInput,
|
|
|
|
|
voiceInput,
|
|
|
|
|
addFile,
|
|
|
|
|
deepThinking,
|
|
|
|
|
internetSearch,
|
|
|
|
|
internetSearchScope,
|
2025-04-25 14:47:34 +08:00
|
|
|
mcpSearch,
|
|
|
|
|
mcpSearchScope,
|
2025-04-15 20:13:42 +08:00
|
|
|
historicalRecords,
|
2025-04-22 18:36:59 +08:00
|
|
|
aiAssistant,
|
2025-04-15 20:13:42 +08:00
|
|
|
newSession,
|
|
|
|
|
fixedWindow,
|
|
|
|
|
serviceList,
|
|
|
|
|
external,
|
|
|
|
|
} = payload;
|
|
|
|
|
setModifierKey(modifierKey);
|
|
|
|
|
setModeSwitch(modeSwitch);
|
|
|
|
|
setReturnToInput(returnToInput);
|
|
|
|
|
setVoiceInput(voiceInput);
|
|
|
|
|
setAddFile(addFile);
|
|
|
|
|
setDeepThinking(deepThinking);
|
|
|
|
|
setInternetSearch(internetSearch);
|
|
|
|
|
setInternetSearchScope(internetSearchScope);
|
2025-04-25 14:47:34 +08:00
|
|
|
setMcpSearch(mcpSearch);
|
|
|
|
|
setMcpSearchScope(mcpSearchScope);
|
2025-04-15 20:13:42 +08:00
|
|
|
setHistoricalRecords(historicalRecords);
|
2025-04-22 18:36:59 +08:00
|
|
|
setAiAssistant(aiAssistant);
|
2025-04-15 20:13:42 +08:00
|
|
|
setNewSession(newSession);
|
|
|
|
|
setFixedWindow(fixedWindow);
|
|
|
|
|
setServiceList(serviceList);
|
|
|
|
|
setExternal(external);
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
platformAdapter.listenEvent("change-startup-store", ({ payload }) => {
|
|
|
|
|
const {
|
|
|
|
|
defaultStartupWindow,
|
|
|
|
|
defaultContentForSearchWindow,
|
|
|
|
|
defaultContentForChatWindow,
|
|
|
|
|
} = payload;
|
|
|
|
|
setDefaultStartupWindow(defaultStartupWindow);
|
|
|
|
|
setDefaultContentForSearchWindow(defaultContentForSearchWindow);
|
|
|
|
|
setDefaultContentForChatWindow(defaultContentForChatWindow);
|
|
|
|
|
}),
|
2025-04-22 18:32:20 +08:00
|
|
|
|
|
|
|
|
platformAdapter.listenEvent("change-connect-store", ({ payload }) => {
|
2025-05-14 16:00:40 +08:00
|
|
|
const { connectionTimeout, querySourceTimeout, allowSelfSignature } =
|
|
|
|
|
payload;
|
2025-05-14 15:03:17 +08:00
|
|
|
if (isNumber(connectionTimeout)) {
|
|
|
|
|
setConnectionTimeout(connectionTimeout);
|
|
|
|
|
}
|
|
|
|
|
if (isNumber(querySourceTimeout)) {
|
|
|
|
|
setQueryTimeout(querySourceTimeout);
|
|
|
|
|
}
|
2025-05-14 16:00:40 +08:00
|
|
|
setAllowSelfSignature(allowSelfSignature);
|
2025-04-22 18:32:20 +08:00
|
|
|
}),
|
2025-04-29 17:08:01 +08:00
|
|
|
|
|
|
|
|
platformAdapter.listenEvent("change-appearance-store", ({ payload }) => {
|
2025-05-07 16:43:44 +08:00
|
|
|
const { opacity, snapshotUpdate } = payload;
|
2025-04-29 17:08:01 +08:00
|
|
|
|
2025-05-14 15:03:17 +08:00
|
|
|
if (isNumber(opacity)) {
|
|
|
|
|
setOpacity(opacity);
|
|
|
|
|
}
|
2025-05-07 16:43:44 +08:00
|
|
|
setSnapshotUpdate(snapshotUpdate);
|
2025-04-29 17:08:01 +08:00
|
|
|
}),
|
2025-04-15 20:13:42 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
unListeners.then((fns) => {
|
|
|
|
|
fns.forEach((fn) => fn());
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
};
|