import { createSignal, onMount } from "solid-js"; import { Trans, useLingui } from "@lingui-solid/solid/macro"; import { CategoryButton, Checkbox, Column } from "@revolt/ui"; import { Symbol } from "@revolt/ui/components/utils/Symbol"; declare type DesktopConfig = { firstLaunch: boolean; customFrame: boolean; minimiseToTray: boolean; spellchecker: boolean; hardwareAcceleration: boolean; discordRpc: boolean; windowState: { isMaximised: boolean; }; }; declare global { interface Window { native: { versions: { node(): string; chrome(): string; electron(): string; desktop(): string; }; minimise(): void; maximise(): void; close(): void; }; desktopConfig: { get(): DesktopConfig; set(config: Partial): void; getAutostart(): Promise; setAutostart(value: boolean): Promise; }; } } /** * Desktop Configuration Page */ export default function Native() { const { t } = useLingui(); const [autostart, setAutostart] = createSignal(false); const [config, setConfig] = createSignal(window.desktopConfig.get()); function set(config: Partial) { window.desktopConfig.set(config); setConfig((conf) => ({ ...conf, ...config })); } onMount(async () => { const value = await window.desktopConfig.getAutostart(); setAutostart(value); }); async function toggleAutostart() { const newValue = !autostart(); const savedValue = await window.desktopConfig.setAutostart(newValue); setAutostart(savedValue); } const toggles: Partial void>> = { minimiseToTray: () => set({ minimiseToTray: !config().minimiseToTray }), customFrame: () => set({ customFrame: !config().customFrame }), discordRpc: () => set({ discordRpc: !config().discordRpc }), spellchecker: () => set({ spellchecker: !config().spellchecker }), hardwareAcceleration: () => set({ hardwareAcceleration: !config().hardwareAcceleration }), }; function CheckboxButton( key: K, icon: string, label: string, description: string, ) { return ( e.stopPropagation()} onChange={(e) => { e.stopPropagation(); toggles[key]!(); }} /> } onClick={toggles[key]} icon={{icon}} description={description} > {label} ); } return ( e.stopPropagation()} onChange={toggleAutostart} /> } onClick={toggleAutostart} icon={exit_to_app} description={ Launch Stoat when you log into your computer. } > Start with Computer {CheckboxButton( "minimiseToTray", "cancel_presentation", t`Minimise to Tray`, t`Instead of closing, Stoat will hide in your tray.`, )} {CheckboxButton( "customFrame", "web_asset", t`Custom window frame`, t`Let Stoat use its own custom titlebar.`, )} {CheckboxButton( "discordRpc", "groups_2", t`Discord RPC`, t`Rep Stoat using Discord rich presence.`, )} {CheckboxButton( "spellchecker", "spellcheck", t`Spellchecker`, t`Show corrections and suggestions as you type.`, )} {CheckboxButton( "hardwareAcceleration", "speed", t`Hardware Acceleration`, t`Use the graphics card to improve performance.`, )} desktop_windows} description={ <> Version: {window.native.versions.desktop()} } > Stoat for Desktop ); }