/* eslint-disable react-hooks/exhaustive-deps */ 'use client' import { useContext, useEffect, useState, useCallback, ChangeEvent, } from 'react' import { fs, AppConfiguration } from '@janhq/core' import { Switch, Button, Input } from '@janhq/uikit' import ShortcutModal from '@/containers/ShortcutModal' import { toaster } from '@/containers/Toast' import { FeatureToggleContext } from '@/context/FeatureToggle' import { useSettings } from '@/hooks/useSettings' const Advanced = () => { const { experimentalFeature, setExperimentalFeature, ignoreSSL, setIgnoreSSL, proxy, setProxy, } = useContext(FeatureToggleContext) const [partialProxy, setPartialProxy] = useState(proxy) const [gpuEnabled, setGpuEnabled] = useState(false) const { readSettings, saveSettings, validateSettings, setShowNotification } = useSettings() const onProxyChange = useCallback( (event: ChangeEvent) => { const value = event.target.value || '' setPartialProxy(value) if (value.trim().startsWith('http')) { setProxy(value.trim()) } else { setProxy('') } }, [setPartialProxy, setProxy] ) // TODO: remove me later. const [currentPath, setCurrentPath] = useState('') useEffect(() => { window.core?.api ?.getAppConfigurations() ?.then((appConfig: AppConfiguration) => { setCurrentPath(appConfig.data_folder) }) }, []) useEffect(() => { readSettings().then((settings) => { setGpuEnabled(settings.run_mode === 'gpu') }) }, []) const clearLogs = async () => { if (await fs.existsSync(`file://logs`)) { await fs.rmdirSync(`file://logs`, { recursive: true }) } toaster({ title: 'Logs cleared', description: 'All logs have been cleared.', }) } const onJanVaultDirectoryClick = async () => { const destFolder = await window.core?.api?.selectDirectory() if (destFolder) { console.debug(`Destination folder selected: ${destFolder}`) try { const appConfiguration: AppConfiguration = await window.core?.api?.getAppConfigurations() const currentJanDataFolder = appConfiguration.data_folder if (currentJanDataFolder === destFolder) { console.debug( `Destination folder is the same as current folder. Ignore..` ) return } appConfiguration.data_folder = destFolder await fs.syncFile(currentJanDataFolder, destFolder) await window.core?.api?.updateAppConfiguration(appConfiguration) console.debug( `File sync finished from ${currentJanDataFolder} to ${destFolder}` ) await window.core?.api?.relaunch() } catch (e) { console.error(`Error: ${e}`) } } } return (
{/* CPU / GPU switching */} {!isMac && (
NVidia GPU

Enable GPU acceleration for NVidia GPUs.

{ if (e === true) { saveSettings({ runMode: 'gpu' }) setGpuEnabled(true) setShowNotification(false) setTimeout(() => { validateSettings() }, 300) } else { saveSettings({ runMode: 'cpu' }) setGpuEnabled(false) } }} />
)} {/* Experimental */}
Experimental Mode

Enable experimental features that may be unstable tested.

{ if (e === true) { setExperimentalFeature(true) } else { setExperimentalFeature(false) } }} />
{/* Proxy */}
HTTPS Proxy

Specify the HTTPS proxy or leave blank (proxy auto-configuration and SOCKS not supported).

:@:'} value={partialProxy} onChange={onProxyChange} />
{/* Ignore SSL certificates */}
Ignore SSL certificates

Allow self-signed or unverified certificates - may be required for certain proxies.

{ if (e === true) { setIgnoreSSL(true) } else { setIgnoreSSL(false) } }} />
{window.electronAPI && (
Open App Directory

Open the directory where your app data, like conversation history and model configurations, is located.

)}
Clear logs

Clear all logs from Jan app.

{experimentalFeature && (
Jan Data Folder

Where messages, model configurations, and other user data is placed.

{`${currentPath}`}

)}
Keyboard Shortcuts

Shortcuts that you might find useful in Jan app.

) } export default Advanced