import { useSearch } from "@tanstack/react-router"; import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"; import { type } from "@tauri-apps/plugin-os"; import { useLicense } from "@yaakapp-internal/license"; import { pluginsAtom, settingsAtom } from "@yaakapp-internal/models"; import classNames from "classnames"; import { useAtomValue } from "jotai"; import { useKeyPressEvent } from "react-use"; import { appInfo } from "../../lib/appInfo"; import { capitalize } from "../../lib/capitalize"; import { CountBadge } from "../core/CountBadge"; import { Icon } from "../core/Icon"; import { HStack } from "../core/Stacks"; import { TabContent, type TabItem, Tabs } from "../core/Tabs/Tabs"; import { HeaderSize } from "../HeaderSize"; import { SettingsCertificates } from "./SettingsCertificates"; import { SettingsGeneral } from "./SettingsGeneral"; import { SettingsHotkeys } from "./SettingsHotkeys"; import { SettingsInterface } from "./SettingsInterface"; import { SettingsLicense } from "./SettingsLicense"; import { SettingsPlugins } from "./SettingsPlugins"; import { SettingsProxy } from "./SettingsProxy"; import { SettingsTheme } from "./SettingsTheme"; interface Props { hide?: () => void; } const TAB_GENERAL = "general"; const TAB_INTERFACE = "interface"; const TAB_THEME = "theme"; const TAB_SHORTCUTS = "shortcuts"; const TAB_PROXY = "proxy"; const TAB_CERTIFICATES = "certificates"; const TAB_PLUGINS = "plugins"; const TAB_LICENSE = "license"; const tabs = [ TAB_GENERAL, TAB_THEME, TAB_INTERFACE, TAB_SHORTCUTS, TAB_PLUGINS, TAB_CERTIFICATES, TAB_PROXY, TAB_LICENSE, ] as const; export type SettingsTab = (typeof tabs)[number]; export default function Settings({ hide }: Props) { const { tab: tabFromQuery } = useSearch({ from: "/workspaces/$workspaceId/settings" }); // Parse tab and subtab (e.g., "plugins:installed") const [mainTab, subtab] = tabFromQuery?.split(":") ?? []; const settings = useAtomValue(settingsAtom); const plugins = useAtomValue(pluginsAtom); const licenseCheck = useLicense(); // Close settings window on escape // TODO: Could this be put in a better place? Eg. in Rust key listener when creating the window useKeyPressEvent("Escape", async () => { if (hide != null) { // It's being shown in a dialog, so close the dialog hide(); } else { // It's being shown in a window, so close the window await getCurrentWebviewWindow().close(); } }); return (
{hide ? ( ) : (
Settings
)} ({ value, label: capitalize(value), hidden: !appInfo.featureLicense && value === TAB_LICENSE, leftSlot: value === TAB_GENERAL ? ( ) : value === TAB_THEME ? ( ) : value === TAB_INTERFACE ? ( ) : value === TAB_SHORTCUTS ? ( ) : value === TAB_CERTIFICATES ? ( ) : value === TAB_PROXY ? ( ) : value === TAB_PLUGINS ? ( ) : value === TAB_LICENSE ? ( ) : null, rightSlot: value === TAB_CERTIFICATES ? ( ) : value === TAB_PLUGINS ? ( p.source !== "bundled").length} /> ) : value === TAB_PROXY && settings.proxy?.type === "enabled" ? ( ) : value === TAB_LICENSE && licenseCheck.check.data?.status === "personal_use" ? ( ) : null, }), )} >
); }