import { Button, Input, Spinner, Tab, Tabs, Tooltip, cn } from '@heroui/react' import { useQuery } from '@tanstack/react-query' import { getVersion as getUiVersion } from '@tauri-apps/api/app' import { message } from '@tauri-apps/plugin-dialog' import { openUrl } from '@tauri-apps/plugin-opener' import { platform } from '@tauri-apps/plugin-os' import { BellIcon, CodeIcon, CogIcon, EyeIcon, GlobeIcon, InfoIcon, MedalIcon, PackageIcon, SatelliteDishIcon, ServerIcon, TabletSmartphoneIcon, } from 'lucide-react' import { useEffect, useMemo, useState } from 'react' import { useSearchParams } from 'react-router-dom' import { LOCAL_HOST_ID } from '../../../lib/hosts' import { useIsPreview } from '../../../lib/preview' import rclone from '../../../lib/rclone/client' import { useStore } from '../../../store/memory' import { useCurrentHost, usePersistedStore } from '../../../store/persisted' import AboutSection from './AboutSection' import BinarySection from './BinarySection' import ConfigSection from './ConfigSection' import GeneralSection from './GeneralSection' import HostsSection from './HostsSection' import LicenseSection from './LicenseSection' import MobileSection from './MobileSection' import NotificationsSection from './NotificationsSection' import ProxySection from './ProxySection' import RemotesSection from './RemotesSection' export default function Settings() { const [searchParams] = useSearchParams() const isPreview = useIsPreview() const settingsPass = usePersistedStore((state) => state.settingsPass) const currentHost = useCurrentHost() const isRestartingRclone = useStore((state) => state.isRestartingRclone) const isLocalHost = useMemo(() => currentHost?.id === LOCAL_HOST_ID, [currentHost?.id]) const defaultSelectedTab = useMemo(() => searchParams.get('tab') || 'general', [searchParams]) const [passwordCheckInput, setPasswordCheckInput] = useState('') const [passwordCheckPassed, setPasswordCheckPassed] = useState(false) const [passwordVisible, setPasswordVisible] = useState(false) const { data: uiVersion } = useQuery({ queryKey: ['versions', 'ui'], queryFn: async () => { const uiVersion = await getUiVersion() return uiVersion.endsWith('.0') ? uiVersion.slice(0, -2) : uiVersion }, }) const cliVersionQuery = useQuery({ queryKey: ['versions', 'cli'], queryFn: async () => { const cliVersion = await rclone('/core/version') return cliVersion.version.replace('v', '') }, }) useEffect(() => { console.log('[Settings] cliVersionQuery', 'CHANGED') console.log('[Settings] cliVersionQuery.data', cliVersionQuery.data) console.log('[Settings] cliVersionQuery.isLoading', cliVersionQuery.isLoading) console.log('[Settings] cliVersionQuery.isError', cliVersionQuery.isError) console.log('[Settings] cliVersionQuery.isFetching', cliVersionQuery.isFetching) console.log('[Settings] cliVersionQuery.error?.message', cliVersionQuery.error?.message) }, [cliVersionQuery]) const cliVersion = useMemo(() => { return cliVersionQuery.data }, [cliVersionQuery.data]) if (!defaultSelectedTab) return null if (isRestartingRclone) { return (

Restarting rclone...

) } const checkPassword = async () => { if (passwordCheckInput === settingsPass) { setPasswordCheckPassed(true) return } await message('The password you entered is incorrect.', { title: 'Login failed', kind: 'error', }) } if (settingsPass && !passwordCheckPassed) { return (
setPasswordCheckInput(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') checkPassword() }} autoCapitalize="none" autoComplete="off" autoCorrect="off" spellCheck="false" type={passwordVisible ? 'text' : 'password'} fullWidth={false} size="lg" endContent={ } />
) } return (
General
} data-focus-visible="false" className="w-full max-h-screen p-0 overflow-scroll overscroll-none" > Remotes } data-focus-visible="false" className="w-full max-h-screen p-0 overflow-scroll overscroll-none" > Notifications } data-focus-visible="false" className="w-full max-h-screen p-0 overflow-scroll overscroll-none" >
Mobile
} data-focus-visible="false" className="w-full max-h-screen p-0 overflow-scroll overscroll-none" >
Hosts } data-focus-visible="false" className="w-full max-h-screen p-0 overflow-scroll overscroll-none" >
Config
} data-focus-visible="false" isDisabled={currentHost?.id !== 'local'} className="w-full max-h-screen p-0 overflow-scroll overscroll-none" >
Binary
} data-focus-visible="false" isDisabled={currentHost?.id !== 'local'} className="w-full max-h-screen p-0 overflow-scroll overscroll-none" >
Proxy
// } data-focus-visible="false" className="w-full max-h-screen p-0 overflow-scroll overscroll-none" >
{!isPreview && ( License } data-focus-visible="false" className="w-full max-h-screen p-0 overflow-scroll overscroll-none" > )} About } data-focus-visible="false" className="w-full max-h-screen p-0 overflow-scroll overscroll-none" > {!isLocalHost && (

Connected to {currentHost?.name}

)}

openUrl('https://github.com/rclone-ui/rclone-ui')} > {isPreview ? 'rcloneui.com' : `UI v${uiVersion}, CLI v${cliVersion}`}

) }