import { platform } from "@yaakapp-internal/platform"; import { useLicense } from "@yaakapp-internal/license"; import { pluginsAtom, settingsAtom } from "@yaakapp-internal/models"; import { HeaderSize, HStack, Icon } from "@yaakapp-internal/ui"; 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 { TabContent, type TabItem, Tabs } from "../core/Tabs/Tabs"; 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 { tab?: SettingsTabWithSubtab | null; /** Set when Settings is in a dialog rather than owning a window. */ 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 type SettingsTabWithSubtab = SettingsTab | `${SettingsTab}:${string}`; export default function Settings({ tab, hide }: Props) { // Parse tab and subtab (e.g., "plugins:installed") const [mainTab, subtab] = tab?.split(":") ?? []; const settings = useAtomValue(settingsAtom); const plugins = useAtomValue(pluginsAtom); const licenseCheck = useLicense(); // Close settings window on escape. In a dialog, the dialog handles Escape itself. // TODO: Could this be put in a better place? Eg. in Rust key listener when creating the window useKeyPressEvent("Escape", async () => { if (hide == null) await platform.window.close(); }); return (