import { useSearch } from '@tanstack/react-router'; import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'; import { type } from '@tauri-apps/plugin-os'; import classNames from 'classnames'; import React, { useState } from 'react'; import { useKeyPressEvent } from 'react-use'; import { appInfo } from '../../lib/appInfo'; import { capitalize } from '../../lib/capitalize'; import { HStack } from '../core/Stacks'; import type { TabItem } from '../core/Tabs/Tabs'; import { TabContent, Tabs } from '../core/Tabs/Tabs'; import { HeaderSize } from '../HeaderSize'; import { SettingsInterface } from './SettingsInterface'; import { SettingsGeneral } from './SettingsGeneral'; 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_PROXY = 'proxy'; const TAB_PLUGINS = 'plugins'; const TAB_LICENSE = 'license'; const tabs = [TAB_GENERAL, TAB_THEME, TAB_INTERFACE, TAB_PROXY, TAB_PLUGINS, TAB_LICENSE] as const; export type SettingsTab = (typeof tabs)[number]; export default function Settings({ hide }: Props) { const { tab: tabFromQuery } = useSearch({ from: '/workspaces/$workspaceId/settings' }); const [tab, setTab] = useState(tabFromQuery); // 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, }), )} >
); }