import { useForm } from 'react-hook-form'; import { useEffect, useState } from 'react'; import { FilePen, FolderOpen, RefreshCw, ScrollText, ShieldAlert, ShieldCheck } from 'lucide-react'; import { PreferencesSchema } from '~common/schemas'; import { api } from '~renderer/utils/api'; import zodResolver from '~renderer/utils/zodResolver'; import { useT } from '~renderer/i18n'; import TextButton from './styled/TextButton'; import CheckboxInput from './form/CheckboxInput'; import DialogButton from './styled/DialogButton'; import ClientDirDialog from './ClientDirDialog'; import CloseButton from './styled/CloseButton'; const MirrorStatus = () => { const t = useT(); const [state, setState] = useState('verifying'); api.updater.observe.useSubscription(undefined, { onData: ({ state }) => setState(state) }); if (state === 'serverUnreachable') return {t('prefs.mirrorOffline')}; if (state === 'verifying' || state === 'updating') return ( {t('prefs.mirrorChecking')} ); return {t('prefs.mirrorOnline')}; }; type Props = { close: () => void }; const isLinux = typeof window !== 'undefined' && window.electron?.process?.platform === 'linux'; const PreferencesDialog = ({ close }: Props) => { const t = useT(); const { data: pref } = api.preferences.get.useQuery(); const setPref = api.preferences.set.useMutation(); const { data: protonVersions = [] } = api.general.protonVersions.useQuery( undefined, { enabled: isLinux } ); const verify = api.updater.verify.useMutation(); const repair = api.mods.repair.useMutation(); const openInstallFolder = api.general.openInstallFolder.useMutation(); const openLogFile = api.general.openLogFile.useMutation(); const addExclusion = api.general.addDefenderExclusion.useMutation(); const { handleSubmit, watch, setValue, reset } = useForm({ defaultValues: pref ?? {}, resolver: zodResolver(PreferencesSchema) }); useEffect(() => { pref && reset(pref); }, [reset, pref]); const setBool = (key: keyof PreferencesSchema) => (v: boolean) => setValue(key, v, { shouldTouch: true, shouldDirty: true, shouldValidate: true }); const useProton = !!watch('useProton'); const protonPath = watch('protonPath'); useEffect(() => { if (!useProton || !protonVersions.length) return; const stillValid = protonVersions.some(v => v.path === protonPath); if (!stillValid) setValue('protonPath', protonVersions[0].path, { shouldDirty: true, shouldValidate: true }); }, [useProton, protonVersions, protonPath, setValue]); return (
{ await setPref.mutateAsync({ cleanWdb: v.cleanWdb, minimizeToTrayOnPlay: v.minimizeToTrayOnPlay, useProton: v.useProton, protonPath: v.protonPath }); close(); })} > { reset(); close(); }} />

{t('prefs.title')}


{t('prefs.installLocation')}

openInstallFolder.mutateAsync()} className="!p-1 text-blueGray" > {t('prefs.openFolder')}
{pref?.clientDir ?? t('prefs.notSelected')} ( { closeInner(); close(); }} /> )} clickAway={pref?.isPortable} > {open => ( {t('prefs.change')} )}

{t('prefs.downloadMirror')}

Iceland verify.mutateAsync()} title={t('prefs.recheck')} className="!p-0 text-blueGray" />

{t('prefs.troubleshooting')}

repair.mutateAsync().then(close)} className="!items-start text-left text-warmGreen" > {t('prefs.verifyGameFiles')} openLogFile.mutateAsync()} className="!items-start text-left text-pink" > {t('prefs.openLogFile')} addExclusion.mutateAsync()} loading={addExclusion.isLoading} className="!items-start text-left text-orange" > {t('prefs.allowThroughAntivirus')} {addExclusion.data?.ok === true && ( {t('prefs.exclusionAdded')} )} {addExclusion.data?.ok === false && ( {addExclusion.data.error} )}

{t('prefs.generalSettings')}

{isLinux && (

{t('prefs.proton')}

{useProton && ( <> {protonVersions.length === 0 && ( {t('prefs.protonNoneHint')} )} )}
)} {t('prefs.save')} ); }; export default PreferencesDialog;