import { commands } from "@/commands.gen"; import { appSettings } from "@/commons"; import { Spinner } from "@/components"; import * as Switch from "@radix-ui/react-switch"; import { createLazyFileRoute } from "@tanstack/react-router"; import { useStore } from "@tanstack/react-store"; import { invoke } from "@tauri-apps/api/core"; import { message } from "@tauri-apps/plugin-dialog"; import { useCallback, useEffect, useState, useTransition } from "react"; type Theme = "auto" | "light" | "dark"; export const Route = createLazyFileRoute("/$account/_settings/general")({ component: Screen, }); function Screen() { const [theme, setTheme] = useState(null); const [isPending, startTransition] = useTransition(); const changeTheme = useCallback(async (theme: string) => { if (theme === "auto" || theme === "light" || theme === "dark") { invoke("plugin:theme|set_theme", { theme: theme, }).then(() => setTheme(theme)); } }, []); const updateSettings = () => { startTransition(async () => { const newSettings = JSON.stringify(appSettings.state); const res = await commands.setSettings(newSettings); if (res.status === "error") { await message(res.error, { kind: "error" }); } return; }); }; useEffect(() => { invoke("plugin:theme|get_theme").then((data) => setTheme(data as Theme)); }, []); return (

General

Appearance

Appearance

Change app theme

Privacy & Performance

); } function Setting({ label, name, description, }: { label: string; name: string; description: string }) { const state = useStore(appSettings, (state) => state[label]); const toggle = useCallback(() => { appSettings.setState((state) => { return { ...state, [label]: !state[label], }; }); }, []); return (

{name}

{description}

toggle()} className="relative h-7 w-12 shrink-0 cursor-default rounded-full bg-black/10 outline-none data-[state=checked]:bg-blue-500 dark:bg-white/10" >
); }