'use client' import { ChangeEvent } from 'react' import { AppConfiguration } from '@janhq/core' import { ScrollArea, Switch, Button } from '@janhq/joi' import { useAtom, useAtomValue, useSetAtom } from 'jotai' import { ArrowRightIcon } from 'lucide-react' import { useDebouncedCallback } from 'use-debounce' import { toaster } from '@/containers/Toast' import { useConfigurations } from '@/hooks/useConfigurations' import ModalDeleteAllThreads from '@/screens/Thread/ThreadLeftPanel/ModalDeleteAllThreads' import DataFolder from './DataFolder' import FactoryReset from './FactoryReset' import { experimentalFeatureEnabledAtom, proxyEnabledAtom, quickAskEnabledAtom, } from '@/helpers/atoms/AppConfig.atom' import { showScrollBarAtom } from '@/helpers/atoms/Setting.atom' import { ThreadModalAction } from '@/helpers/atoms/Thread.atom' import { modalActionThreadAtom } from '@/helpers/atoms/Thread.atom' /** * Advanced Settings Screen * @returns */ const Advanced = ({ setSubdir }: { setSubdir: (subdir: string) => void }) => { const [experimentalEnabled, setExperimentalEnabled] = useAtom( experimentalFeatureEnabledAtom ) const showScrollBar = useAtomValue(showScrollBarAtom) const [proxyEnabled, setProxyEnabled] = useAtom(proxyEnabledAtom) const quickAskEnabled = useAtomValue(quickAskEnabledAtom) const { configurePullOptions } = useConfigurations() const setModalActionThread = useSetAtom(modalActionThreadAtom) /** * There could be a case where the state update is not synced * so that retrieving state value from other hooks would not be accurate * there is also a case where state update persist everytime user type in the input */ const updatePullOptions = useDebouncedCallback( () => configurePullOptions(), 300 ) /** * Update Quick Ask Enabled * @param e * @param relaunch * @returns void */ const updateQuickAskEnabled = async ( e: boolean, relaunch: boolean = true ) => { const appConfiguration: AppConfiguration = await window.core?.api?.getAppConfigurations() appConfiguration.quick_ask = e await window.core?.api?.updateAppConfiguration(appConfiguration) if (relaunch) window.core?.api?.relaunch() } /** * Update Experimental Enabled * @param e * @returns */ const updateExperimentalEnabled = async ( e: ChangeEvent ) => { setExperimentalEnabled(e.target.checked) // If it checked, we don't need to do anything else // Otherwise have to reset other settings if (e.target.checked) return // It affects other settings, so we need to reset them const isRelaunch = quickAskEnabled if (quickAskEnabled) await updateQuickAskEnabled(false, false) if (isRelaunch) window.core?.api?.relaunch() } return (
{/* Experimental */}
Experimental Mode

New features that are still unstable and could affect app performance. Enable with caution.

{/* Proxy Settings Link */}
HTTPS Proxy

Optional proxy server for internet connections.

{ e.stopPropagation() setProxyEnabled(!proxyEnabled) updatePullOptions() }} /> setSubdir('proxy')} />
{experimentalEnabled && (
Jan Quick Ask

Enable Quick Ask to be triggered via the default hotkey {isMac ? '⌘' : 'Ctrl'} + J {' '} .

{ toaster({ title: 'Reload', description: 'Quick Ask settings updated. Reload now to apply the changes.', }) updateQuickAskEnabled(!quickAskEnabled) }} />
)} {/* Delete All Threads */}
Delete All Threads

Delete all threads and associated chat history.

{/* Factory Reset */}
) } export default Advanced