/** * @file AutostartSettings — Settings → About's "Start automatically" switch: * whether the dashboard starts at boot/login through the per-user service * (systemd `--user` unit, or a LaunchAgent on macOS), over * `GET/PUT /api/settings/autostart`. Off by default; a change never starts or * stops the running server. * @author Nguyễn Ngọc Trí Vĩ */ import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { api, type AutostartStatus } from "../../lib/api"; import { toast } from "../../lib/toast"; import { SettingsSection, SettingsSwitchRow } from "./SettingsRow"; export function AutostartSettings() { const { t } = useTranslation("settings"); const [status, setStatus] = useState(null); const [saving, setSaving] = useState(false); useEffect(() => { api.settings.autostart .get() .then(setStatus) .catch(() => {}); }, []); const change = async (enabled: boolean) => { setSaving(true); try { setStatus(await api.settings.autostart.set(enabled)); } catch (err) { toast.error(err instanceof Error ? err.message : String(err)); } finally { setSaving(false); } }; const note = !status ? undefined : !status.available ? t("autostart.unavailable") : status.foreign ? t("autostart.foreign") : t(`autostart.desc_${status.kind}`); return ( void change(v)} /> ); }