import * as Switch from '@radix-ui/react-switch'; import { invoke } from '@tauri-apps/api/primitives'; import { getCurrent } from '@tauri-apps/api/window'; import { disable, enable, isEnabled } from '@tauri-apps/plugin-autostart'; import { isPermissionGranted, requestPermission } from '@tauri-apps/plugin-notification'; import { useEffect, useState } from 'react'; import { twMerge } from 'tailwind-merge'; import { useStorage } from '@libs/storage/provider'; import { DarkIcon, LightIcon, SystemModeIcon } from '@shared/icons'; export function GeneralSettingScreen() { const { db } = useStorage(); const [settings, setSettings] = useState({ autoupdate: false, autolaunch: false, outbox: false, media: true, hashtag: true, notification: true, appearance: 'system', }); const changeTheme = async (theme: 'light' | 'dark' | 'auto') => { await invoke('plugin:theme|set_theme', { theme }); // update state setSettings((prev) => ({ ...prev, appearance: theme })); }; const toggleAutolaunch = async () => { if (!settings.autolaunch) { await enable(); // update state setSettings((prev) => ({ ...prev, autolaunch: true })); } else { await disable(); // update state setSettings((prev) => ({ ...prev, autolaunch: false })); } }; const toggleOutbox = async () => { await db.createSetting('outbox', String(+!settings.outbox)); // update state setSettings((prev) => ({ ...prev, outbox: !settings.outbox })); }; const toggleMedia = async () => { await db.createSetting('media', String(+!settings.media)); db.settings.media = !settings.media; // update state setSettings((prev) => ({ ...prev, media: !settings.media })); }; const toggleHashtag = async () => { await db.createSetting('hashtag', String(+!settings.hashtag)); db.settings.hashtag = !settings.hashtag; // update state setSettings((prev) => ({ ...prev, hashtag: !settings.hashtag })); }; const toggleAutoupdate = async () => { await db.createSetting('autoupdate', String(+!settings.autoupdate)); db.settings.autoupdate = !settings.autoupdate; // update state setSettings((prev) => ({ ...prev, autoupdate: !settings.autoupdate })); }; const toggleNofitication = async () => { if (settings.notification) return; await requestPermission(); // update state setSettings((prev) => ({ ...prev, notification: !settings.notification })); }; useEffect(() => { async function loadSettings() { const theme = await getCurrent().theme(); setSettings((prev) => ({ ...prev, appearance: theme })); const autostart = await isEnabled(); setSettings((prev) => ({ ...prev, autolaunch: autostart })); const permissionGranted = await isPermissionGranted(); setSettings((prev) => ({ ...prev, notification: permissionGranted })); const data = await db.getAllSettings(); if (!data) return; data.forEach((item) => { if (item.key === 'autoupdate') setSettings((prev) => ({ ...prev, autoupdate: !!parseInt(item.value), })); if (item.key === 'outbox') setSettings((prev) => ({ ...prev, outbox: !!parseInt(item.value), })); if (item.key === 'media') setSettings((prev) => ({ ...prev, media: !!parseInt(item.value), })); if (item.key === 'hashtag') setSettings((prev) => ({ ...prev, hashtag: !!parseInt(item.value), })); }); } loadSettings(); }, []); return (
Updater
Auto download new update at Login
toggleAutoupdate()} className="relative h-7 w-12 cursor-default rounded-full bg-neutral-200 outline-none data-[state=checked]:bg-blue-500 dark:bg-neutral-800" >
Startup
Launch Lume at Login
toggleAutolaunch()} className="relative h-7 w-12 cursor-default rounded-full bg-neutral-200 outline-none data-[state=checked]:bg-blue-500 dark:bg-neutral-800" >
Gossip
Use Outbox model
toggleOutbox()} className="relative h-7 w-12 cursor-default rounded-full bg-neutral-200 outline-none data-[state=checked]:bg-blue-500 dark:bg-neutral-800" >
Media
Automatically load media
toggleMedia()} className="relative h-7 w-12 cursor-default rounded-full bg-neutral-200 outline-none data-[state=checked]:bg-blue-500 dark:bg-neutral-800" >
Hashtag
Hide all hashtags in content
toggleHashtag()} className="relative h-7 w-12 cursor-default rounded-full bg-neutral-200 outline-none data-[state=checked]:bg-blue-500 dark:bg-neutral-800" >
Notification
Automatically send notification
toggleNofitication()} className="relative h-7 w-12 cursor-default rounded-full bg-neutral-200 outline-none data-[state=checked]:bg-blue-500 dark:bg-neutral-800" >
Appearance
); }