From aa98d6d34a65b56a7f0b2ff59f063fa33ccf9da9 Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Mon, 27 Jul 2026 17:25:47 +0800 Subject: [PATCH] feat: add system theme to quick controls --- App.tsx | 6 +-- application/app/AppHandlers.ts | 23 --------- application/app/AppView.tsx | 5 +- application/i18n/locales/en/ai.ts | 1 + application/i18n/locales/ru/ai.ts | 1 + application/i18n/locales/zh-CN/ai.ts | 1 + application/i18n/locales/zh-TW/ai.ts | 1 + .../state/settingsStateDefaults.test.ts | 5 ++ application/state/settingsStateDefaults.ts | 2 +- components/TopTabs.test.ts | 14 ++++-- components/TopTabs.tsx | 12 +++-- components/TopTabsQuickControls.tsx | 47 ++++++++++++++----- 12 files changed, 67 insertions(+), 51 deletions(-) diff --git a/App.tsx b/App.tsx index 06e6813d5..b9f835fea 100755 --- a/App.tsx +++ b/App.tsx @@ -91,7 +91,7 @@ import { AppActiveTabChrome } from './application/app/AppActiveTabChrome'; import { AppView } from './application/app/AppView'; import { useAppStartupEffects } from './application/app/useAppStartupEffects'; import { LogViewWrapper, SftpViewMount, TerminalLayerMount, VaultViewContainer } from './application/app/AppMounts'; -import { handleTrayJumpToSessionImpl, handleTrayTogglePortForwardImpl, handleTrayPanelConnectImpl, handleTrayPanelConnectRequestImpl, flushQueuedTrayPanelConnectHostsImpl, handleGlobalHotkeyKeyDownImpl, handleEscapeKeyDownImpl, handleKeyboardInteractiveSubmitImpl, handleKeyboardInteractiveCancelImpl, handlePassphraseSubmitImpl, handlePassphraseCancelImpl, handlePassphraseSkipImpl, createLocalTerminalWithCurrentShellImpl, splitSessionWithCurrentShellImpl, copySessionWithCurrentShellImpl, copySessionToNewWindowWithCurrentShellImpl, confirmIfBusyLocalTerminalImpl, closeTabsBatchImpl, executeHotkeyActionImpl, handleCreateLocalTerminalImpl, handleConnectToHostImpl, handleTerminalDataCaptureImpl, hasMultipleProtocolsImpl, handleHostConnectWithProtocolCheckImpl, handleProtocolSelectImpl, handleToggleThemeImpl, handleRootContextMenuImpl } from './application/app/AppHandlers'; +import { handleTrayJumpToSessionImpl, handleTrayTogglePortForwardImpl, handleTrayPanelConnectImpl, handleTrayPanelConnectRequestImpl, flushQueuedTrayPanelConnectHostsImpl, handleGlobalHotkeyKeyDownImpl, handleEscapeKeyDownImpl, handleKeyboardInteractiveSubmitImpl, handleKeyboardInteractiveCancelImpl, handlePassphraseSubmitImpl, handlePassphraseCancelImpl, handlePassphraseSkipImpl, createLocalTerminalWithCurrentShellImpl, splitSessionWithCurrentShellImpl, copySessionWithCurrentShellImpl, copySessionToNewWindowWithCurrentShellImpl, confirmIfBusyLocalTerminalImpl, closeTabsBatchImpl, executeHotkeyActionImpl, handleCreateLocalTerminalImpl, handleConnectToHostImpl, handleTerminalDataCaptureImpl, hasMultipleProtocolsImpl, handleHostConnectWithProtocolCheckImpl, handleProtocolSelectImpl, handleRootContextMenuImpl } from './application/app/AppHandlers'; // Initialize fonts eagerly at app startup initializeFonts(); @@ -1475,8 +1475,6 @@ function App({ settings }: { settings: SettingsState }) { // Handle protocol selection from dialog const handleProtocolSelect = useCallback((protocol: HostProtocol, port: number) => { return handleProtocolSelectImpl(() => ({ handleConnectToHost, port, protocol, protocolSelectHost, setProtocolSelectHost }), protocol, port); }, [protocolSelectHost, handleConnectToHost]); - const handleToggleTheme = useCallback(() => { return handleToggleThemeImpl(() => ({ openSettingsWindow, resolvedTheme, setTheme, t, theme, toast })); }, [openSettingsWindow, resolvedTheme, setTheme, t, theme]); - const handleFollowAppTerminalThemeChange = useCallback((themeId: string) => { themeRuntime.pickTheme(themeId); }, [themeRuntime]); @@ -1576,7 +1574,7 @@ function App({ settings }: { settings: SettingsState }) { resolveSessionAppearance={themeRuntime.resolveFocusedAppearance} t={t} /> - + ); } diff --git a/application/app/AppHandlers.ts b/application/app/AppHandlers.ts index 04cf3536f..f3d58a3fc 100644 --- a/application/app/AppHandlers.ts +++ b/application/app/AppHandlers.ts @@ -1031,29 +1031,6 @@ export function handleProtocolSelectImpl(getCtx: AppContextGetter, protocol: Hos } } -export function handleToggleThemeImpl(getCtx: AppContextGetter) { - const { openSettingsWindow, resolvedTheme, setTheme, t, theme, toast } = getCtx(); -{ - if (theme === 'system') { - toast.info( - t('topTabs.toggleTheme.systemExitMessage'), - { - title: t('topTabs.toggleTheme.systemExitTitle'), - actionLabel: t('topTabs.toggleTheme.openSettings'), - onClick: () => { - void (async () => { - const opened = await openSettingsWindow(); - if (!opened) toast.error(t('toast.settingsUnavailable'), t('common.settings')); - })(); - }, - } - ); - return; - } - setTheme(resolvedTheme === 'dark' ? 'light' : 'dark'); - } -} - export function handleRootContextMenuImpl(getCtx: AppContextGetter, e: React.MouseEvent) { void getCtx; { diff --git a/application/app/AppView.tsx b/application/app/AppView.tsx index 2f1da8ebb..9856b0d13 100644 --- a/application/app/AppView.tsx +++ b/application/app/AppView.tsx @@ -106,7 +106,7 @@ export function AppView({ ctx }: { ctx: AppViewContext }) { groupConfigs, handleAddKnownHost, handleConnectSerial, handleConnectToHost, handleCreateLocalTerminal, handleDefaultTerminalThemeChange, handleDeleteHost, handleEndSessionDrag, handleFollowAppTerminalThemeChange, handleHostConnectWithProtocolCheck, handleHotkeyAction, handleKeyboardInteractiveCancel, handleKeyboardInteractiveSubmit, handleOpenHostFromVaultNote, handleOpenQuickSwitcher, handleOpenSettings, handleOpenVaultHostFromChat, handleOpenVaultNoteFromChat, handleOpenVaultSectionFromChat, handleOpenVaultSnippetFromChat, handleRootContextMenu, handlePassphraseCancel, handlePassphraseSkip, handlePassphraseSubmit, handleProtocolSelect, - handleRequestCloseEditorTabRef, handleSessionStatusChange, handleSyncNowManual, handleTerminalDataCapture, handleToggleTheme, handleUpdateHostFromTerminal, + handleRequestCloseEditorTabRef, handleSessionStatusChange, handleSyncNowManual, handleTerminalDataCapture, handleUpdateHostFromTerminal, hostById, hosts, terminalHosts, updateTerminalHosts, hotkeyScheme, identities, importOrReuseKey, isBroadcastEnabled, isCreateWorkspaceOpen, isMacClient, isQuickSwitcherOpen, keyBindings, keyboardInteractiveQueue, keys, logViews, managedSources, navigateToSection, noteGroups, notes, openLogView, openNoteRequest, orderedTabsWithEditors, orphanSessions, passphraseQueue, protocolSelectHost, proxyProfiles, portForwardingRules, quickResults, quickSearch, removeSessionFromWorkspace, reorderWorkTabs, reorderWorkspaceSessions, @@ -240,6 +240,7 @@ export function AppView({ ctx }: { ctx: AppViewContext }) {
{ return store; } +test("fresh installs follow the operating system color scheme by default", () => { + assert.equal(DEFAULT_THEME, "system"); +}); + test("migrateIncomingTerminalFontId rewrites deprecated ids to the auto sentinel, not menlo", () => { // menlo would put Windows/Linux upgrade users back into the #1647 path, // and a concrete id would leak across OSes via sync; auto resolves per device. diff --git a/application/state/settingsStateDefaults.ts b/application/state/settingsStateDefaults.ts index feb85c2b3..9509596d1 100644 --- a/application/state/settingsStateDefaults.ts +++ b/application/state/settingsStateDefaults.ts @@ -17,7 +17,7 @@ export { resolveReadableForegroundForHsl, } from '../../domain/colorContrast'; -export const DEFAULT_THEME: 'light' | 'dark' | 'system' = 'dark'; +export const DEFAULT_THEME: 'light' | 'dark' | 'system' = 'system'; export const DEFAULT_WINDOW_OPACITY = 1; export function clampWindowOpacity(opacity: unknown): number { const value = Number(opacity); diff --git a/components/TopTabs.test.ts b/components/TopTabs.test.ts index acc4d4ca0..b01e9807a 100644 --- a/components/TopTabs.test.ts +++ b/components/TopTabs.test.ts @@ -123,17 +123,18 @@ test("top tabs keep cloud sync separate from quick controls", () => { assert.match(topTabsSource, /onOpenSettings=\{onOpenSettings\}/); assert.match(topTabsSource, /onSyncNow=\{onSyncNow\}/); assert.match(topTabsSource, /theme=\{theme\}/); - assert.match(topTabsSource, /onToggleTheme=\{onToggleTheme\}/); + assert.match(topTabsSource, /themePreference=\{themePreference\}/); + assert.match(topTabsSource, /onThemeChange=\{onThemeChange\}/); assert.match(topTabsSource, /externalMcpEnabled=\{externalMcpEnabled\}/); assert.match(topTabsSource, /windowOpacity=\{windowOpacity\}/); assert.match(topTabsSource, /showExternalMcpToggle=\{showExternalMcpToggle\}/); assert.doesNotMatch(topTabsSource, /WindowOpacityButton/); - assert.doesNotMatch(topTabsSource, /onClick=\{onToggleTheme\}/); + assert.doesNotMatch(topTabsSource, /onToggleTheme/); const syncButtonUsage = topTabsSource.match(//); assert.ok(syncButtonUsage, 'expected a SyncStatusButton usage'); assert.doesNotMatch(syncButtonUsage[0], /externalMcpEnabled=/); assert.doesNotMatch(syncButtonUsage[0], /windowOpacity=/); - assert.doesNotMatch(syncButtonUsage[0], /onToggleTheme=/); + assert.doesNotMatch(syncButtonUsage[0], /onThemeChange=/); const quickControlsUsage = topTabsSource.match(//); assert.ok(quickControlsUsage, 'expected a TopTabsQuickControls usage'); assert.match(quickControlsUsage[0], /showExternalMcpToggle=\{showExternalMcpToggle\}/); @@ -142,13 +143,18 @@ test("top tabs keep cloud sync separate from quick controls", () => { test("quick controls panel hosts External MCP, opacity, and theme", () => { assert.match(topTabsQuickControlsSource, /data-section="top-tabs-quick-controls"/); + assert.match(topTabsQuickControlsSource, /className="w-72 p-0 app-no-drag"/); assert.match(topTabsQuickControlsSource, /topTabs\.controlPanel/); assert.doesNotMatch(topTabsQuickControlsSource, /topTabs\.controlPanel\.description/); assert.match(topTabsQuickControlsSource, /externalMcpEnabled/); assert.match(topTabsQuickControlsSource, /onToggleExternalMcp/); assert.match(topTabsQuickControlsSource, /windowOpacity/); assert.match(topTabsQuickControlsSource, /setWindowOpacity/); - assert.match(topTabsQuickControlsSource, /onToggleTheme/); + assert.match(topTabsQuickControlsSource, /themePreference/); + assert.match(topTabsQuickControlsSource, /onThemeChange/); + assert.match(topTabsQuickControlsSource, /topTabs\.controlPanel\.theme\.system/); + assert.match(topTabsQuickControlsSource, /aria-pressed=\{themePreference === option\.value\}/); + assert.match(topTabsQuickControlsSource, /onClick=\{\(\) => onThemeChange\(option\.value\)\}/); assert.match(topTabsQuickControlsSource, / void; onCloseTabsBatch: (targetIds: string[]) => void; onOpenQuickSwitcher: () => void; - onToggleTheme: () => void; + onThemeChange: (theme: 'dark' | 'light' | 'system') => void; onOpenSettings: () => void; externalMcpEnabled: boolean; onToggleExternalMcp: (enabled: boolean) => void; @@ -163,6 +164,7 @@ interface TopTabsProps { const TopTabsInner: React.FC = ({ theme, + themePreference, hosts, sessions, orphanSessions, @@ -180,7 +182,7 @@ const TopTabsInner: React.FC = ({ onCloseLogView, onCloseTabsBatch, onOpenQuickSwitcher, - onToggleTheme, + onThemeChange, onOpenSettings, externalMcpEnabled, onToggleExternalMcp, @@ -1113,7 +1115,8 @@ const TopTabsInner: React.FC = ({ /> { prev.windowOpacity === next.windowOpacity && prev.setWindowOpacity === next.setWindowOpacity && prev.onSyncNow === next.onSyncNow && - prev.onToggleTheme === next.onToggleTheme && + prev.themePreference === next.themePreference && + prev.onThemeChange === next.onThemeChange && prev.showSftpTab === next.showSftpTab && prev.showHostTreeSidebar === next.showHostTreeSidebar && prev.dynamicTabTitleMode === next.dynamicTabTitleMode diff --git a/components/TopTabsQuickControls.tsx b/components/TopTabsQuickControls.tsx index 5875da758..8097d7efb 100644 --- a/components/TopTabsQuickControls.tsx +++ b/components/TopTabsQuickControls.tsx @@ -2,6 +2,7 @@ import React, { useState } from 'react'; import { ChevronDown, Droplets, + Monitor, Moon, Plug, SlidersHorizontal, @@ -22,7 +23,8 @@ const OPACITY_PRESETS = [ export interface TopTabsQuickControlsProps { theme: 'dark' | 'light'; - onToggleTheme: () => void; + themePreference: 'dark' | 'light' | 'system'; + onThemeChange: (theme: 'dark' | 'light' | 'system') => void; externalMcpEnabled: boolean; onToggleExternalMcp: (enabled: boolean) => void; showExternalMcpToggle?: boolean; @@ -34,7 +36,8 @@ export interface TopTabsQuickControlsProps { export const TopTabsQuickControls: React.FC = ({ theme, - onToggleTheme, + themePreference, + onThemeChange, externalMcpEnabled, onToggleExternalMcp, showExternalMcpToggle = true, @@ -50,6 +53,11 @@ export const TopTabsQuickControls: React.FC = ({ const isPresetActive = (value: number) => Math.round(value * 100) === opacityPercent; const isDark = theme === 'dark'; const externalMcpLabelId = React.useId(); + const themeOptions = [ + { value: 'light' as const, label: t('topTabs.controlPanel.theme.light') }, + { value: 'dark' as const, label: t('topTabs.controlPanel.theme.dark') }, + { value: 'system' as const, label: t('topTabs.controlPanel.theme.system') }, + ]; return ( = ({ @@ -152,18 +160,31 @@ export const TopTabsQuickControls: React.FC = ({
- {isDark - ? - : } + {themePreference === 'system' + ? + : isDark + ? + : } {t('topTabs.controlPanel.theme')}
- +
+ {themeOptions.map((option) => ( + + ))} +