import { useEffect, useState } from "react"; import { Button, CheckboxField, TextField } from "@renderer/components"; import * as styles from "./settings.css"; import { useTranslation } from "react-i18next"; import { UserPreferences } from "@types"; export function Settings() { const [form, setForm] = useState({ downloadsPath: "", downloadNotificationsEnabled: false, repackUpdatesNotificationsEnabled: false, telemetryEnabled: false, }); const { t } = useTranslation("settings"); useEffect(() => { Promise.all([ window.electron.getDefaultDownloadsPath(), window.electron.getUserPreferences(), ]).then(([path, userPreferences]) => { setForm({ downloadsPath: userPreferences?.downloadsPath || path, downloadNotificationsEnabled: userPreferences?.downloadNotificationsEnabled, repackUpdatesNotificationsEnabled: userPreferences?.repackUpdatesNotificationsEnabled, telemetryEnabled: userPreferences?.telemetryEnabled, }); }); }, []); const updateUserPreferences = ( field: T, value: UserPreferences[T] ) => { setForm((prev) => ({ ...prev, [field]: value })); window.electron.updateUserPreferences({ [field]: value, }); }; const handleChooseDownloadsPath = async () => { const { filePaths } = await window.electron.showOpenDialog({ defaultPath: form.downloadsPath, properties: ["openDirectory"], }); if (filePaths && filePaths.length > 0) { const path = filePaths[0]; updateUserPreferences("downloadsPath", path); } }; return (

{t("notifications")}

updateUserPreferences( "downloadNotificationsEnabled", !form.downloadNotificationsEnabled ) } /> updateUserPreferences( "repackUpdatesNotificationsEnabled", !form.repackUpdatesNotificationsEnabled ) } />

{t("telemetry")}

updateUserPreferences("telemetryEnabled", !form.telemetryEnabled) } />
); }