import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { AppWindowMac, ArrowUpWideNarrow, MessageSquareMore, PanelTopClose, Search, ShieldCheck, Unplug, } from "lucide-react"; import { useMount } from "ahooks"; import { isNil } from "lodash-es"; import Shortcuts from "./components/Shortcuts"; import SettingsItem from "../SettingsItem"; import { useStartupStore } from "@/stores/startupStore"; import { useConnectStore } from "@/stores/connectStore"; import Appearance from "./components/Appearance"; import SettingsInput from "@/components//Settings/SettingsInput"; import platformAdapter from "@/utils/platformAdapter"; import UpdateSettings from "./components/UpdateSettings"; import SettingsToggle from "../SettingsToggle"; // import SelectionSettings from "./components/Selection"; // import { isMac } from "@/utils/platform"; import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue, } from "@/components/ui/select"; const Advanced = () => { const { t } = useTranslation(); const defaultStartupWindow = useStartupStore((state) => { return state.defaultStartupWindow; }); const setDefaultStartupWindow = useStartupStore((state) => { return state.setDefaultStartupWindow; }); const defaultContentForSearchWindow = useStartupStore((state) => { return state.defaultContentForSearchWindow; }); const setDefaultContentForSearchWindow = useStartupStore((state) => { return state.setDefaultContentForSearchWindow; }); const defaultContentForChatWindow = useStartupStore((state) => { return state.defaultContentForChatWindow; }); const setDefaultContentForChatWindow = useStartupStore((state) => { return state.setDefaultContentForChatWindow; }); const connectionTimeout = useConnectStore((state) => { return state.connectionTimeout; }); const setConnectionTimeout = useConnectStore((state) => { return state.setConnectionTimeout; }); const queryTimeout = useConnectStore((state) => { return state.querySourceTimeout; }); const setQueryTimeout = useConnectStore((state) => { return state.setQuerySourceTimeout; }); const allowSelfSignature = useConnectStore((state) => { return state.allowSelfSignature; }); const setAllowSelfSignature = useConnectStore((state) => { return state.setAllowSelfSignature; }); const { searchDelay, setSearchDelay, compactModeAutoCollapseDelay, setCompactModeAutoCollapseDelay, } = useConnectStore(); const [localSearchResultWeight, setLocalSearchResultWeight] = useState(1); useMount(async () => { const allowSelfSignature = await platformAdapter.invokeBackend( "get_allow_self_signature" ); setAllowSelfSignature(allowSelfSignature); const weight = await platformAdapter.invokeBackend( "get_local_query_source_weight" ); setLocalSearchResultWeight(weight); }); useEffect(() => { const unsubscribeStartup = useStartupStore.subscribe((state) => { platformAdapter.emitEvent("change-startup-store", state); }); return () => { unsubscribeStartup(); }; }, []); const startupList = [ { icon: AppWindowMac, title: "settings.advanced.startup.defaultStartupWindow.title", description: "settings.advanced.startup.defaultStartupWindow.description", value: defaultStartupWindow, items: [ { label: "settings.advanced.startup.defaultStartupWindow.select.searchMode", value: "searchMode", }, { label: "settings.advanced.startup.defaultStartupWindow.select.chatMode", value: "chatMode", }, ], onChange: setDefaultStartupWindow, }, { icon: Search, title: "settings.advanced.startup.defaultContentForSearchWindow.title", description: "settings.advanced.startup.defaultContentForSearchWindow.description", value: defaultContentForSearchWindow, items: [ { label: "settings.advanced.startup.defaultContentForSearchWindow.select.systemDefault", value: "systemDefault", }, ], onChange: setDefaultContentForSearchWindow, }, { icon: MessageSquareMore, title: "settings.advanced.startup.defaultContentForChatWindow.title", description: "settings.advanced.startup.defaultContentForChatWindow.description", value: defaultContentForChatWindow, items: [ { label: "settings.advanced.startup.defaultContentForChatWindow.select.newChat", value: "newChat", }, { label: "settings.advanced.startup.defaultContentForChatWindow.select.oldChat", value: "oldChat", }, ], onChange: setDefaultContentForChatWindow, }, ]; return (

{t("settings.advanced.startup.title")}

{startupList.map((item) => { const { icon, title, description, value, items, onChange } = item; return ( ); })}
{/* {isMac && } */}

{t("settings.advanced.other.title")}

{ setConnectionTimeout(!value ? void 0 : Number(value)); }} /> { setQueryTimeout(!value ? void 0 : Number(value)); }} /> { setSearchDelay(isNil(value) ? 0 : Number(value)); }} /> { setAllowSelfSignature(value); platformAdapter.invokeBackend("set_allow_self_signature", { value, }); }} /> { setCompactModeAutoCollapseDelay(!value ? 0 : Number(value)); }} />
); }; export default Advanced;