Skip to content

A full-featured download manager.

fix(window): align startup themes and fullscreen chrome (#2057)

Dr_rOot61f9dfde12ab
diff --git a/index.html b/index.html
index 5774d607..ab3606e2 100644
--- a/index.html
+++ b/index.html
@@ -2,6 +2,24 @@
<html lang="en-US">
<head>
<meta charset="UTF-8" />
+ <meta name="color-scheme" content="light dark" />
+ <style id="motrix-theme-bootstrap">
+ html,
+ body {
+ background: #ffffff;
+ color: #18181b;
+ color-scheme: light;
+ }
+
+ @media (prefers-color-scheme: dark) {
+ html,
+ body {
+ background: #09090b;
+ color: #fafafa;
+ color-scheme: dark;
+ }
+ }
+ </style>
<link rel="icon" href="/favicon.ico" sizes="32x32" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<title>Motrix</title>
diff --git a/src/main/index.ts b/src/main/index.ts
index 833bb09e..1992779b 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -133,6 +133,7 @@ import {
autoUpdater as nativeAutoUpdater,
powerMonitor,
shell,
+ systemPreferences,
} from 'electron'
import { autoUpdater } from 'electron-updater'
import { bootstrapBridge, createNativeMessagingInstaller } from './bridge'
@@ -168,6 +169,7 @@ import { i18n } from './lib/i18n'
import { setupLogger } from './logger'
import { MainProcessWorkCoordinator } from './main-process-work-coordinator'
import { installAllMenubarContributions } from './menu/contributions'
+import { suppressMacOSAutomaticFullscreenMenuItem } from './menu/macos-fullscreen-menu'
import { MenuManager } from './menu/menu-manager'
import { MenuRegistry } from './menu/menu-registry'
import { createNatManager } from './nat/nat-manager-factory'
@@ -207,6 +209,8 @@ import { resolveMainWindowStartupPlan } from './window/window-startup-plan'
// ─── Platform Early Setup ───────────────────────────────
+suppressMacOSAutomaticFullscreenMenuItem(process.platform, systemPreferences)
+
if (process.platform === 'win32') {
app.setAppUserModelId(APP_ID)
}
diff --git a/src/main/ipc/commands.test.ts b/src/main/ipc/commands.test.ts
index a5ab5fb2..59f3c3b1 100644
--- a/src/main/ipc/commands.test.ts
+++ b/src/main/ipc/commands.test.ts
@@ -749,6 +749,7 @@ describe('buildCommandHandlers', () => {
fromWebContentsMock
.mockReturnValueOnce({
isDestroyed: vi.fn(() => false),
+ isFullScreen: vi.fn(() => false),
isMaximizable: vi.fn(() => true),
isMaximized: vi.fn(() => false),
maximize,
@@ -756,6 +757,7 @@ describe('buildCommandHandlers', () => {
})
.mockReturnValueOnce({
isDestroyed: vi.fn(() => false),
+ isFullScreen: vi.fn(() => false),
isMaximizable: vi.fn(() => true),
isMaximized: vi.fn(() => true),
maximize,
@@ -778,6 +780,32 @@ describe('buildCommandHandlers', () => {
expect(unmaximize).toHaveBeenCalledOnce()
})
+ it('ignores maximize requests while the sender window is full-screen', async () => {
+ const maximize = vi.fn()
+ const unmaximize = vi.fn()
+ const isMaximizable = vi.fn(() => true)
+ const fakeSender = {} as never
+ fromWebContentsMock.mockReturnValueOnce({
+ isDestroyed: vi.fn(() => false),
+ isFullScreen: vi.fn(() => true),
+ isMaximizable,
+ isMaximized: vi.fn(() => false),
+ maximize,
+ unmaximize,
+ })
+ const ctx = fakeCtx()
+ // @ts-expect-error partial ctx
+ const handlers = buildCommandHandlers(ctx)
+
+ await expect(
+ handlers[Commands.ToggleMaximizeCurrentWindow]?.(fakeSender)
+ ).resolves.toEqual({ ok: true })
+
+ expect(isMaximizable).not.toHaveBeenCalled()
+ expect(maximize).not.toHaveBeenCalled()
+ expect(unmaximize).not.toHaveBeenCalled()
+ })
+
it('routes direct shell commands to their owning collaborators', async () => {
const ctx = fakeCtx()
// @ts-expect-error partial ctx
@@ -1107,6 +1135,7 @@ describe('buildCommandHandlers', () => {
await minimizeRegistration?.[1]({ sender })
fromWebContentsMock.mockReturnValueOnce({
isDestroyed: () => false,
+ isFullScreen: () => false,
isMaximizable: () => true,
isMaximized: () => false,
maximize: vi.fn(),
diff --git a/src/main/ipc/commands.ts b/src/main/ipc/commands.ts
index 6e4a0c67..eb8c8d9f 100644
--- a/src/main/ipc/commands.ts
+++ b/src/main/ipc/commands.ts
@@ -1137,7 +1137,12 @@ export function buildCommandHandlers(ctx: CommandContext): CommandHandlerMap {
[Commands.ToggleMaximizeCurrentWindow]: async (sender: WebContents) => {
const win = BrowserWindow.fromWebContents(sender)
- if (win && !win.isDestroyed() && win.isMaximizable()) {
+ if (
+ win &&
+ !win.isDestroyed() &&
+ !win.isFullScreen() &&
+ win.isMaximizable()
+ ) {
if (win.isMaximized()) {
win.unmaximize()
} else {
diff --git a/src/main/menu/application-menu-snapshot.test.ts b/src/main/menu/application-menu-snapshot.test.ts
index a651fbad..b0c060f3 100644
--- a/src/main/menu/application-menu-snapshot.test.ts
+++ b/src/main/menu/application-menu-snapshot.test.ts
@@ -141,7 +141,6 @@ function createManager(
title: 'menu.help.website',
run: hiddenRun,
})
-
menuRegistry.appendItem({
id: MenuItemIds.AppAbout,
type: 'normal',
@@ -244,6 +243,7 @@ function createManager(
})
return {
manager,
+ menuRegistry,
contextStore,
aboutRun,
protectedRun,
@@ -270,6 +270,39 @@ describe('MenuManager application-menu snapshot', () => {
electronMenu.setApplicationMenu.mockClear()
})
+ it('leaves the full-screen role label and accelerator to Electron', () => {
+ const { manager, menuRegistry } = createManager()
+ menuRegistry.appendItem({
+ id: MenuItemIds.WindowToggleFullscreen,
+ type: 'normal',
+ menuId: MenuIds.MenubarWindow,
+ group: '1_window',
+ order: 20,
+ role: 'togglefullscreen',
+ visible: false,
+ })
+
+ manager.install()
+
+ const applicationTemplate =
+ electronMenu.buildFromTemplate.mock.calls[0]?.[0]
+ const windowMenu = applicationTemplate?.find(
+ (item) => item.id === MenuIds.MenubarWindow
+ )
+ const windowSubmenu = Array.isArray(windowMenu?.submenu)
+ ? (windowMenu.submenu as Array<Record<string, unknown>>)
+ : []
+ const fullscreenItem = windowSubmenu.find(
+ (item) => item.id === MenuItemIds.WindowToggleFullscreen
+ )
+ expect(fullscreenItem).toMatchObject({
+ role: 'togglefullscreen',
+ visible: false,
+ })
+ expect(fullscreenItem).not.toHaveProperty('label')
+ expect(fullscreenItem).not.toHaveProperty('accelerator')
+ })
+
it('publishes an initially evaluated, stable dropdown projection', () => {
const { manager } = createManager()
const changed = vi.fn()
diff --git a/src/main/menu/contributions/index.test.ts b/src/main/menu/contributions/index.test.ts
index 119c82e5..24b2ca24 100644
--- a/src/main/menu/contributions/index.test.ts
+++ b/src/main/menu/contributions/index.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { MenuIds } from '../menu-ids'
+import { MenuIds, MenuItemIds } from '../menu-ids'
import { MenuRegistry } from '../menu-registry'
import { installAllMenubarContributions } from './index'
@@ -28,6 +28,21 @@ describe('installAllMenubarContributions', () => {
expect(reg.getItems(MenuIds.MenubarApp, 'win32')).not.toHaveLength(0)
})
+ it('registers exactly one hidden native full-screen role on every platform', () => {
+ const reg = new MenuRegistry()
+ installAllMenubarContributions(reg)
+
+ for (const platform of ['darwin', 'win32', 'linux'] as const) {
+ const items = reg.getItems(MenuIds.MenubarWindow, platform)
+ const fullscreenItems = items.filter(
+ (item) => item.role === 'togglefullscreen'
+ )
+ expect(fullscreenItems).toHaveLength(1)
+ expect(fullscreenItems[0]?.id).toBe(MenuItemIds.WindowToggleFullscreen)
+ expect(fullscreenItems[0]?.visible).toBe(false)
+ }
+ })
+
it('task menu starts with New/NewBt/OpenFile', () => {
const reg = new MenuRegistry()
installAllMenubarContributions(reg)
diff --git a/src/main/menu/contributions/shared.ts b/src/main/menu/contributions/shared.ts
index 21a3730c..fbd93378 100644
--- a/src/main/menu/contributions/shared.ts
+++ b/src/main/menu/contributions/shared.ts
@@ -215,7 +215,7 @@ export function contributeSharedMenubar(menuReg: MenuRegistry): void {
group: '1_basic',
order: 50,
role: 'togglefullscreen',
- titleOverride: 'menu.window.toggleFullscreen',
+ visible: false,
})
// Help menu
diff --git a/src/main/menu/macos-fullscreen-menu.test.ts b/src/main/menu/macos-fullscreen-menu.test.ts
new file mode 100644
index 00000000..ee9d55f7
--- /dev/null
+++ b/src/main/menu/macos-fullscreen-menu.test.ts
@@ -0,0 +1,31 @@
+import { describe, expect, it, vi } from 'vitest'
+import {
+ MACOS_AUTOMATIC_FULLSCREEN_MENU_ITEM_KEY,
+ suppressMacOSAutomaticFullscreenMenuItem,
+} from './macos-fullscreen-menu'
+
+describe('suppressMacOSAutomaticFullscreenMenuItem', () => {
+ it('disables the AppKit-injected full-screen row on macOS', () => {
+ const setUserDefault = vi.fn()
+
+ suppressMacOSAutomaticFullscreenMenuItem('darwin', { setUserDefault })
+
+ expect(setUserDefault).toHaveBeenCalledOnce()
+ expect(setUserDefault).toHaveBeenCalledWith(
+ MACOS_AUTOMATIC_FULLSCREEN_MENU_ITEM_KEY,
+ 'boolean',
+ false
+ )
+ })
+
+ it.each(['win32', 'linux'] as const)(
+ 'does not write macOS defaults on %s',
+ (platform) => {
+ const setUserDefault = vi.fn()
+
+ suppressMacOSAutomaticFullscreenMenuItem(platform, { setUserDefault })
+
+ expect(setUserDefault).not.toHaveBeenCalled()
+ }
+ )
+})
diff --git a/src/main/menu/macos-fullscreen-menu.ts b/src/main/menu/macos-fullscreen-menu.ts
new file mode 100644
index 00000000..bd52423b
--- /dev/null
+++ b/src/main/menu/macos-fullscreen-menu.ts
@@ -0,0 +1,23 @@
+export const MACOS_AUTOMATIC_FULLSCREEN_MENU_ITEM_KEY =
+ 'NSFullScreenMenuItemEverywhere'
+
+interface UserDefaultsWriter {
+ setUserDefault(key: string, type: 'boolean', value: boolean): void
+}
+
+/**
+ * AppKit can inject its own Globe-F full-screen item next to Electron's
+ * togglefullscreen role. Disable that automatic row for this app so Electron
+ * remains the single owner of the menu item, label, shortcut, and action.
+ */
+export function suppressMacOSAutomaticFullscreenMenuItem(
+ platform: NodeJS.Platform,
+ preferences: UserDefaultsWriter
+): void {
+ if (platform !== 'darwin') return
+ preferences.setUserDefault(
+ MACOS_AUTOMATIC_FULLSCREEN_MENU_ITEM_KEY,
+ 'boolean',
+ false
+ )
+}
diff --git a/src/main/menu/menu-manager.ts b/src/main/menu/menu-manager.ts
index 671df389..3d1c3db5 100644
--- a/src/main/menu/menu-manager.ts
+++ b/src/main/menu/menu-manager.ts
@@ -267,10 +267,11 @@ export class MenuManager {
platform: MenuPlatform
): MenuItemConstructorOptions {
const state = this.evaluateItem(item, this.deps.contextStore.get())
+ const label = this.resolveLabel(item)
const base: MenuItemConstructorOptions = {
id: item.id,
type: item.type,
- label: this.resolveLabel(item),
+ ...(label ? { label } : {}),
enabled: state.enabled,
visible: state.visible,
checked: state.checked,
@@ -334,13 +335,15 @@ export class MenuManager {
}
}
- private resolveLabel(item: MenuItem): string {
+ private resolveLabel(item: MenuItem): string | undefined {
if (item.titleOverride) return i18n.t(item.titleOverride)
if (item.commandId) {
const command = this.deps.commandRegistry.get(item.commandId)
return command ? i18n.t(command.title) : item.commandId
}
- return ''
+ // Role labels are intentionally omitted so Electron/AppKit can supply the
+ // platform-native label. Passing an empty string suppresses that default.
+ return undefined
}
private reevaluate(): void {
diff --git a/src/main/window/platform-options.test.ts b/src/main/window/platform-options.test.ts
index 328a2a12..98243bdb 100644
--- a/src/main/window/platform-options.test.ts
+++ b/src/main/window/platform-options.test.ts
@@ -14,6 +14,14 @@ describe('buildPlatformOptions', () => {
const opts = buildPlatformOptions('win32')
expect(opts.titleBarStyle).toBe('hidden')
expect(opts.titleBarOverlay).toBeUndefined()
+ expect(opts.backgroundColor).toBe('#ffffff')
+ })
+
+ it('uses a dark first-paint background for Windows', () => {
+ const opts = buildPlatformOptions('win32', {
+ shouldUseDarkColors: true,
+ })
+ expect(opts.backgroundColor).toBe('#09090b')
})
it('returns hidden titleBarStyle for Linux', () => {
@@ -21,6 +29,14 @@ describe('buildPlatformOptions', () => {
expect(opts.titleBarStyle).toBe('hidden')
expect(opts.titleBarOverlay).toBeUndefined()
expect(opts.vibrancy).toBeUndefined()
+ expect(opts.backgroundColor).toBe('#ffffff')
+ })
+
+ it('uses a dark first-paint background for Linux', () => {
+ const opts = buildPlatformOptions('linux', {
+ shouldUseDarkColors: true,
+ })
+ expect(opts.backgroundColor).toBe('#09090b')
})
it('omits vibrancy and uses solid backgroundColor on macOS when vibrancy: false', () => {
@@ -31,6 +47,14 @@ describe('buildPlatformOptions', () => {
expect(opts.backgroundColor).toBe('#ffffff')
})
+ it('uses a dark solid macOS background when vibrancy is unavailable', () => {
+ const opts = buildPlatformOptions('darwin', {
+ vibrancy: false,
+ shouldUseDarkColors: true,
+ })
+ expect(opts.backgroundColor).toBe('#09090b')
+ })
+
it('uses transparent macOS chrome without vibrancy for Liquid Glass', () => {
const opts = buildPlatformOptions('darwin', { liquidGlass: true })
expect(opts.titleBarStyle).toBe('hiddenInset')
diff --git a/src/main/window/platform-options.ts b/src/main/window/platform-options.ts
index c7694885..66e0785e 100644
--- a/src/main/window/platform-options.ts
+++ b/src/main/window/platform-options.ts
@@ -3,12 +3,26 @@ import type { BrowserWindowConstructorOptions } from 'electron'
export interface PlatformOptionsInput {
vibrancy?: boolean
liquidGlass?: boolean
+ shouldUseDarkColors?: boolean
}
+export const WINDOW_BACKGROUND = {
+ light: '#ffffff',
+ dark: '#09090b',
+} as const
+
export function buildPlatformOptions(
platform: string = process.platform,
- { vibrancy = true, liquidGlass = false }: PlatformOptionsInput = {}
+ {
+ vibrancy = true,
+ liquidGlass = false,
+ shouldUseDarkColors = false,
+ }: PlatformOptionsInput = {}
): BrowserWindowConstructorOptions {
+ const solidBackground = shouldUseDarkColors
+ ? WINDOW_BACKGROUND.dark
+ : WINDOW_BACKGROUND.light
+
switch (platform) {
case 'darwin':
if (liquidGlass) {
@@ -29,16 +43,18 @@ export function buildPlatformOptions(
}
: {
titleBarStyle: 'hiddenInset',
- backgroundColor: '#ffffff',
+ backgroundColor: solidBackground,
trafficLightPosition: { x: 20, y: 20 },
}
case 'win32':
return {
titleBarStyle: 'hidden',
+ backgroundColor: solidBackground,
}
default:
return {
titleBarStyle: 'hidden',
+ backgroundColor: solidBackground,
}
}
}
diff --git a/src/main/window/window-manager.test.ts b/src/main/window/window-manager.test.ts
index 29ea7d8a..b8816e03 100644
--- a/src/main/window/window-manager.test.ts
+++ b/src/main/window/window-manager.test.ts
@@ -53,6 +53,7 @@ vi.mock('electron', () => {
isVisible = vi.fn(() => this._visible)
isFocused = vi.fn(() => true)
isMaximized = vi.fn(() => false)
+ isFullScreen = vi.fn(() => false)
getBounds = vi.fn(() => ({ ...this._bounds }))
getNormalBounds = vi.fn(() => ({ ...this._bounds }))
maximize = vi.fn()
@@ -97,13 +98,14 @@ vi.mock('electron', () => {
return {
BrowserWindow: MockBrowserWindow,
+ nativeTheme: { shouldUseDarkColors: false },
screen: mockScreen,
shell: { openExternal: vi.fn() },
}
})
import type { SettingsManager } from '@core/settings/settings-manager'
-import { BrowserWindow } from 'electron'
+import { BrowserWindow, nativeTheme } from 'electron'
import type { LiquidGlassController } from './liquid-glass'
import { initializeRendererUrlPolicy } from './renderer-url-policy'
import { WINDOW_CONFIGS } from './window-configs'
@@ -127,6 +129,9 @@ function createMockSettingsManager(
describe('WindowManager', () => {
beforeEach(() => {
;(BrowserWindow as unknown as { instances: unknown[] }).instances.length = 0
+ ;(
+ nativeTheme as unknown as { shouldUseDarkColors: boolean }
+ ).shouldUseDarkColors = false
vi.clearAllMocks()
})
@@ -158,6 +163,23 @@ describe('WindowManager', () => {
expect(options.titleBarOverlay).toBeUndefined()
})
+ it('matches the first-paint window background to the resolved native theme', () => {
+ ;(
+ nativeTheme as unknown as { shouldUseDarkColors: boolean }
+ ).shouldUseDarkColors = true
+ const wm = new WindowManager({
+ settingsManager: createMockSettingsManager(),
+ preloadPath: '/fake/preload.cjs',
+ loadUrl: vi.fn(),
+ platform: 'win32',
+ })
+
+ const win = wm.open('main')
+ const options = (win as unknown as { options: Record<string, unknown> })
+ .options
+ expect(options.backgroundColor).toBe('#09090b')
+ })
+
it('publishes the owning window maximize state after load and on changes', () => {
const wm = new WindowManager({
settingsManager: createMockSettingsManager(),
@@ -181,6 +203,12 @@ describe('WindowManager', () => {
const unmaximize = windowListeners.find(
([event]) => event === 'unmaximize'
)?.[1] as (() => void) | undefined
+ const enterFullScreen = windowListeners.find(
+ ([event]) => event === 'enter-full-screen'
+ )?.[1] as (() => void) | undefined
+ const leaveFullScreen = windowListeners.find(
+ ([event]) => event === 'leave-full-screen'
+ )?.[1] as (() => void) | undefined
const resized = windowListeners.find(
([event]) => event === 'resized'
)?.[1] as (() => void) | undefined
@@ -188,14 +216,29 @@ describe('WindowManager', () => {
didFinishLoad?.()
expect(win.webContents.send).toHaveBeenLastCalledWith(
Events.WindowMaximizedChanged,
- { maximized: false }
+ { maximized: false, fullscreen: false }
)
vi.mocked(win.isMaximized).mockReturnValue(true)
maximize?.()
expect(win.webContents.send).toHaveBeenLastCalledWith(
Events.WindowMaximizedChanged,
- { maximized: true }
+ { maximized: true, fullscreen: false }
+ )
+
+ vi.mocked(win.isMaximized).mockReturnValue(false)
+ vi.mocked(win.isFullScreen).mockReturnValue(true)
+ enterFullScreen?.()
+ expect(win.webContents.send).toHaveBeenLastCalledWith(
+ Events.WindowMaximizedChanged,
+ { maximized: false, fullscreen: true }
+ )
+
+ vi.mocked(win.isFullScreen).mockReturnValue(false)
+ leaveFullScreen?.()
+ expect(win.webContents.send).toHaveBeenLastCalledWith(
+ Events.WindowMaximizedChanged,
+ { maximized: false, fullscreen: false }
)
// macOS can finish a manual resize without sending unmaximize. The final
@@ -204,7 +247,7 @@ describe('WindowManager', () => {
resized?.()
expect(win.webContents.send).toHaveBeenLastCalledWith(
Events.WindowMaximizedChanged,
- { maximized: false }
+ { maximized: false, fullscreen: false }
)
vi.mocked(win.isMaximized).mockReturnValue(true)
@@ -213,7 +256,7 @@ describe('WindowManager', () => {
unmaximize?.()
expect(win.webContents.send).toHaveBeenLastCalledWith(
Events.WindowMaximizedChanged,
- { maximized: false }
+ { maximized: false, fullscreen: false }
)
})
diff --git a/src/main/window/window-manager.ts b/src/main/window/window-manager.ts
index d57b07c7..d9a0c919 100644
--- a/src/main/window/window-manager.ts
+++ b/src/main/window/window-manager.ts
@@ -6,7 +6,7 @@ import {
} from '@shared/protocol/events'
import type { AddTaskUrlParams } from '@shared/schemas/add-task'
import type { WindowBounds, WindowState } from '@shared/types/settings'
-import { BrowserWindow, screen, shell } from 'electron'
+import { BrowserWindow, nativeTheme, screen, shell } from 'electron'
import type { LiquidGlassController } from './liquid-glass'
import { buildPlatformOptions } from './platform-options'
import {
@@ -368,6 +368,7 @@ export class WindowManager {
const platformOpts = buildPlatformOptions(platform, {
vibrancy: config.vibrancy && !liquidGlass,
liquidGlass,
+ shouldUseDarkColors: nativeTheme.shouldUseDarkColors,
})
const win = new BrowserWindow({
@@ -513,17 +514,20 @@ export class WindowManager {
if (win.isDestroyed()) return
const payload: WindowMaximizedChangedPayload = {
maximized: win.isMaximized(),
+ fullscreen: win.isFullScreen(),
}
win.webContents.send(Events.WindowMaximizedChanged, payload)
}
- // did-finish-load supplies the initial snapshot; maximize/unmaximize keep
- // it correct for caption clicks, title-bar double-clicks, and OS actions.
+ // did-finish-load supplies the initial snapshot; native state events keep
+ // custom caption controls correct for title-bar, OS, and fullscreen actions.
// Cocoa can leave the maximized state via a manual resize without emitting
// unmaximize, so reconcile once the resize gesture finishes as well.
win.webContents.on('did-finish-load', publish)
win.on('maximize', publish)
win.on('unmaximize', publish)
+ win.on('enter-full-screen', publish)
+ win.on('leave-full-screen', publish)
win.on('resized', publish)
}
diff --git a/src/preload/preload.test.ts b/src/preload/preload.test.ts
index a44a91eb..cf07fb2b 100644
--- a/src/preload/preload.test.ts
+++ b/src/preload/preload.test.ts
@@ -88,17 +88,26 @@ describe('preload latest-value replay buffers', () => {
expect(callback).toHaveBeenCalledTimes(1)
})
- it('replays only the latest maximize state before chrome subscribes', async () => {
+ it('replays only the latest window state before chrome subscribes', async () => {
await import('./preload')
- emit(Events.WindowMaximizedChanged, { maximized: false })
- emit(Events.WindowMaximizedChanged, { maximized: true })
+ emit(Events.WindowMaximizedChanged, {
+ maximized: false,
+ fullscreen: false,
+ })
+ emit(Events.WindowMaximizedChanged, {
+ maximized: false,
+ fullscreen: true,
+ })
const callback = vi.fn()
mocks.exposed?.on(Events.WindowMaximizedChanged, callback)
await Promise.resolve()
expect(callback).toHaveBeenCalledOnce()
- expect(callback).toHaveBeenCalledWith({ maximized: true })
+ expect(callback).toHaveBeenCalledWith({
+ maximized: false,
+ fullscreen: true,
+ })
})
})
diff --git a/src/renderer/components/onboarding/disclaimer-step.test.tsx b/src/renderer/components/onboarding/disclaimer-step.test.tsx
index 99f4560b..5b920299 100644
--- a/src/renderer/components/onboarding/disclaimer-step.test.tsx
+++ b/src/renderer/components/onboarding/disclaimer-step.test.tsx
@@ -69,7 +69,7 @@ describe('DisclaimerStep', () => {
await waitFor(() => expect(invoke).toHaveBeenCalledTimes(2))
})
- it('renders professional copy through black Blur Highlights', () => {
+ it('renders professional copy through theme-aware Blur Highlights', () => {
render(<DisclaimerStep />)
expect(screen.getByRole('heading', { name: 'Usage Notice' })).toBeVisible()
@@ -81,8 +81,14 @@ describe('DisclaimerStep', () => {
]
expect(highlightRoot.textContent).toBe(i18n.t('onboarding.disclaimer.body'))
expect(highlightRoot.style.getPropertyValue('--blur-highlight-color')).toBe(
- '#171717'
+ 'currentColor'
)
+ expect(screen.getByTestId('disclaimer-panel')).toHaveClass(
+ 'bg-card',
+ 'text-card-foreground',
+ 'border-border'
+ )
+ expect(highlightRoot).toHaveClass('text-card-foreground')
expect(highlightedBits.map((bit) => bit.textContent)).toEqual([
'provides download management only',
'legally authorized',
diff --git a/src/renderer/components/onboarding/disclaimer-step.tsx b/src/renderer/components/onboarding/disclaimer-step.tsx
index 8ba4e2a8..d7164acf 100644
--- a/src/renderer/components/onboarding/disclaimer-step.tsx
+++ b/src/renderer/components/onboarding/disclaimer-step.tsx
@@ -31,11 +31,11 @@ export function DisclaimerStep() {
}
return (
- <main className="flex min-h-0 flex-1 flex-col px-5 pt-4 pb-5 text-[#1d1d1f]">
+ <main className="flex min-h-0 flex-1 flex-col px-5 pt-4 pb-5 text-foreground">
<section
data-testid="disclaimer-panel"
aria-labelledby="disclaimer-title"
- className="min-h-0 flex-1 overflow-y-auto rounded-xl border border-black/14 bg-white px-6 py-6 shadow-[0_1px_2px_rgba(0,0,0,0.02)]"
+ className="min-h-0 flex-1 overflow-y-auto rounded-xl border border-border bg-card px-6 py-6 text-card-foreground shadow-sm"
>
<div className="space-y-4">
<h1
@@ -44,7 +44,7 @@ export function DisclaimerStep() {
>
{t('onboarding.disclaimer.title')}
</h1>
- <p className="text-[14px] leading-6 text-[#3f3f46]">
+ <p className="text-[14px] leading-6 text-card-foreground/80">
{t('onboarding.disclaimer.summary')}
</p>
</div>
@@ -56,11 +56,11 @@ export function DisclaimerStep() {
t('onboarding.disclaimer.highlights.authorized'),
t('onboarding.disclaimer.highlights.responsibility'),
]}
- highlightColor="#171717"
+ highlightColor="currentColor"
highlightClassName="font-medium"
viewportOptions={{ once: true, amount: 0.5 }}
className={cn(
- 'mt-6 text-[14px] tracking-[-0.006em] text-[#1d1d1f]',
+ 'mt-6 text-[14px] tracking-[-0.006em] text-card-foreground',
useCjkSpacing ? 'leading-[2.5]' : 'leading-[1.9]'
)}
>
@@ -69,7 +69,7 @@ export function DisclaimerStep() {
<p
className={cn(
- 'text-[13px] leading-5 text-[#6e6e73]',
+ 'text-[13px] leading-5 text-muted-foreground',
useCjkSpacing ? 'mt-8' : 'mt-6'
)}
>
diff --git a/src/renderer/components/onboarding/onboarding-language-select.tsx b/src/renderer/components/onboarding/onboarding-language-select.tsx
index 134f854a..fed361e0 100644
--- a/src/renderer/components/onboarding/onboarding-language-select.tsx
+++ b/src/renderer/components/onboarding/onboarding-language-select.tsx
@@ -47,7 +47,7 @@ export function OnboardingLanguageSelect() {
data-testid="onboarding-language"
size="sm"
aria-label={t('onboarding.disclaimer.language')}
- className="h-8 min-w-28 max-w-64 border-black/10 bg-white/88 text-[13px] text-[#1d1d1f] shadow-[0_1px_3px_rgba(0,0,0,0.08)] backdrop-blur-xl hover:bg-white"
+ className="h-8 min-w-28 max-w-64 border-border bg-card/88 text-[13px] text-card-foreground shadow-sm backdrop-blur-xl hover:bg-card"
>
<SelectValue />
</SelectTrigger>
diff --git a/src/renderer/components/onboarding/onboarding-surface.tsx b/src/renderer/components/onboarding/onboarding-surface.tsx
index 0ee66218..a78817eb 100644
--- a/src/renderer/components/onboarding/onboarding-surface.tsx
+++ b/src/renderer/components/onboarding/onboarding-surface.tsx
@@ -8,8 +8,7 @@ export function OnboardingSurface({ children }: OnboardingSurfaceProps) {
return (
<div
data-slot="onboarding-surface"
- className="relative isolate flex h-screen min-h-0 flex-col overflow-hidden bg-[#f7f7f8] text-[#1d1d1f]"
- style={{ colorScheme: 'light' }}
+ className="relative isolate flex h-screen min-h-0 flex-col overflow-hidden bg-[#f7f7f8] text-foreground dark:bg-[#161617]"
>
{children}
</div>
diff --git a/src/renderer/components/window-chrome/window-chrome.test.tsx b/src/renderer/components/window-chrome/window-chrome.test.tsx
index 13b8c986..d6fafc18 100644
--- a/src/renderer/components/window-chrome/window-chrome.test.tsx
+++ b/src/renderer/components/window-chrome/window-chrome.test.tsx
@@ -84,6 +84,26 @@ describe('WindowChrome', () => {
expect((container.firstChild as HTMLElement).style.paddingLeft).toBe('94px')
})
+ it('removes the macOS traffic-light inset while full-screen', () => {
+ const { container } = render(
+ <WindowChrome variant="overlay">
+ <button type="button">App action</button>
+ </WindowChrome>
+ )
+
+ act(() => {
+ emit(Events.WindowMaximizedChanged, {
+ maximized: false,
+ fullscreen: true,
+ })
+ })
+
+ const chrome = container.firstChild as HTMLElement
+ expect(chrome.style.paddingLeft).toBe('')
+ expect(chrome.style.paddingInlineStart).toBe('12px')
+ expect(screen.getByRole('button', { name: 'App action' })).toBeVisible()
+ })
+
it('renders the title text in titled variant', () => {
render(<WindowChrome variant="titled" title="My Window" />)
expect(screen.getByText('My Window')).toBeInTheDocument()
@@ -273,7 +293,10 @@ describe('WindowChrome', () => {
)
act(() => {
- emit(Events.WindowMaximizedChanged, { maximized: true })
+ emit(Events.WindowMaximizedChanged, {
+ maximized: true,
+ fullscreen: false,
+ })
})
const restore = screen.getByRole('button', { name: 'Restore' })
@@ -284,6 +307,88 @@ describe('WindowChrome', () => {
)
})
+ it.each(['win32', 'linux'] as const)(
+ 'keeps %s app actions but hides caption controls while full-screen',
+ (platform) => {
+ setPlatform(platform)
+ const { container } = render(
+ <WindowChrome
+ variant="overlay"
+ leading={<button type="button">Motrix menu</button>}
+ >
+ <button type="button">App action</button>
+ </WindowChrome>
+ )
+
+ act(() => {
+ emit(Events.WindowMaximizedChanged, {
+ maximized: false,
+ fullscreen: true,
+ })
+ })
+
+ const chrome = container.querySelector('.window-chrome')
+ expect(chrome).toBeVisible()
+ expect(chrome).toHaveAttribute('data-fullscreen', 'true')
+ expect(chrome).not.toHaveClass('app-drag')
+ expect(screen.getByRole('button', { name: 'Motrix menu' })).toBeVisible()
+ expect(screen.getByRole('button', { name: 'App action' })).toBeVisible()
+ expect(screen.queryByRole('button', { name: 'Minimize' })).toBeNull()
+ expect(screen.queryByRole('button', { name: 'Maximize' })).toBeNull()
+ expect(screen.queryByRole('button', { name: 'Close' })).toBeNull()
+
+ act(() => {
+ emit(Events.WindowMaximizedChanged, {
+ maximized: false,
+ fullscreen: false,
+ })
+ })
+ expect(container.querySelector('.window-chrome')).toHaveAttribute(
+ 'data-fullscreen',
+ 'false'
+ )
+ expect(container.querySelector('.window-chrome')).toHaveClass('app-drag')
+ expect(screen.getByRole('button', { name: 'Maximize' })).toBeVisible()
+ }
+ )
+
+ it('uses the same full-screen chrome behavior in the macOS desktop-controls preview', () => {
+ setPlatform('darwin')
+ const { container } = render(
+ <WindowChrome
+ variant="overlay"
+ previewDesktopControls
+ leading={<button type="button">Motrix menu</button>}
+ >
+ <button type="button">App action</button>
+ </WindowChrome>
+ )
+
+ act(() => {
+ emit(Events.WindowMaximizedChanged, {
+ maximized: false,
+ fullscreen: true,
+ })
+ })
+
+ const chrome = container.querySelector('.window-chrome')
+ expect(chrome).toBeVisible()
+ expect(chrome).toHaveAttribute('data-fullscreen', 'true')
+ expect(screen.getByRole('button', { name: 'Motrix menu' })).toBeVisible()
+ expect(screen.getByRole('button', { name: 'App action' })).toBeVisible()
+ expect(screen.queryByRole('button', { name: 'Minimize' })).toBeNull()
+ expect(screen.queryByRole('button', { name: 'Maximize' })).toBeNull()
+ expect(screen.queryByRole('button', { name: 'Close' })).toBeNull()
+
+ act(() => {
+ emit(Events.WindowMaximizedChanged, {
+ maximized: false,
+ fullscreen: false,
+ })
+ })
+ expect(screen.getByRole('button', { name: 'Maximize' })).toBeVisible()
+ })
+
it('uses theme-aware caption colors with a readable destructive hover', () => {
setPlatform('win32')
render(<WindowChrome variant="overlay" />)
diff --git a/src/renderer/components/window-chrome/window-chrome.tsx b/src/renderer/components/window-chrome/window-chrome.tsx
index 999633a1..f8c6c573 100644
--- a/src/renderer/components/window-chrome/window-chrome.tsx
+++ b/src/renderer/components/window-chrome/window-chrome.tsx
@@ -62,20 +62,15 @@ export function WindowChromeCaptionIcon({ name }: { name: CaptionIconName }) {
}
function DesktopWindowControls({
+ maximized,
maximizable,
separateFromActions,
}: {
+ maximized: boolean
maximizable: boolean
separateFromActions: boolean
}) {
const { t } = useTranslation()
- const [maximized, setMaximized] = useState(false)
- useIpcEvent(Events.WindowMaximizedChanged, (...args) => {
- const payload = args[0] as WindowMaximizedChangedPayload | undefined
- if (typeof payload?.maximized === 'boolean') {
- setMaximized(payload.maximized)
- }
- })
const minimize = () => {
void transport.invoke(Commands.MinimizeCurrentWindow)
@@ -171,6 +166,19 @@ export function WindowChrome({
children,
}: WindowChromeProps) {
const platform = transport.platform
+ const [windowState, setWindowState] = useState({
+ maximized: false,
+ fullscreen: false,
+ })
+ useIpcEvent(Events.WindowMaximizedChanged, (...args) => {
+ const payload = args[0] as WindowMaximizedChangedPayload | undefined
+ if (
+ typeof payload?.maximized === 'boolean' &&
+ typeof payload.fullscreen === 'boolean'
+ ) {
+ setWindowState(payload)
+ }
+ })
const showDesktopControls = shouldShowDesktopWindowControls(
platform,
previewDesktopControls
@@ -178,7 +186,10 @@ export function WindowChrome({
const isOverlay = variant === 'overlay'
const isMac = platform === 'darwin'
const showTrafficLight =
- __MOTRIX_TARGET__ === 'electron' && isMac && !previewDesktopControls
+ __MOTRIX_TARGET__ === 'electron' &&
+ isMac &&
+ !previewDesktopControls &&
+ !windowState.fullscreen
const offsetStartActionsForDesktopMenu =
showDesktopControls && leading != null && actionsPosition === 'start'
@@ -214,7 +225,11 @@ export function WindowChrome({
)
return (
- <div className="window-chrome app-drag" style={containerStyle}>
+ <div
+ className={cn('window-chrome', !windowState.fullscreen && 'app-drag')}
+ data-fullscreen={windowState.fullscreen}
+ style={containerStyle}
+ >
{!isOverlay && title && (
<div className="pt-[14px] text-[13px] font-[600]">{title}</div>
)}
@@ -233,8 +248,9 @@ export function WindowChrome({
className="min-w-16 flex-1"
/>
{actionsPosition === 'end' && actionSlot}
- {showDesktopControls && (
+ {showDesktopControls && !windowState.fullscreen && (
<DesktopWindowControls
+ maximized={windowState.maximized}
maximizable={maximizable}
separateFromActions={actionsPosition === 'end'}
/>
diff --git a/src/renderer/index.tsx b/src/renderer/index.tsx
index 52057418..7beb579c 100644
--- a/src/renderer/index.tsx
+++ b/src/renderer/index.tsx
@@ -6,6 +6,7 @@ import {
bootstrapRendererLocale,
type RendererWindowId,
} from '@renderer/lib/bootstrap-locale'
+import { applyInitialRendererTheme } from '@renderer/lib/initial-theme'
import { transport } from '@renderer/lib/transport'
import { ThemeProvider } from 'next-themes'
import { lazy, type ReactNode, Suspense } from 'react'
@@ -43,14 +44,16 @@ const windowId: RendererWindowId =
document.documentElement.classList.add(`platform-${transport.platform}`)
document.documentElement.classList.add(`window-${windowId}`)
+// Apply the resolved class before the locale IPC and React mount. The native
+// BrowserWindow background uses the same Electron nativeTheme value, so the
+// compositor and renderer agree from the first visible frame.
+applyInitialRendererTheme()
function Root({
children,
- forcedTheme,
syncSettings = true,
}: {
children: ReactNode
- forcedTheme?: string
syncSettings?: boolean
}) {
return (
@@ -58,7 +61,6 @@ function Root({
attribute="class"
defaultTheme="system"
enableSystem
- forcedTheme={forcedTheme}
disableTransitionOnChange
>
<LocaleDirectionProvider>
@@ -84,7 +86,7 @@ async function startRenderer(rootContainer: HTMLElement): Promise<void> {
)
} else if (windowId === 'onboarding') {
root.render(
- <Root syncSettings={false} forcedTheme="light">
+ <Root syncSettings={false}>
<Suspense>
<OnboardingWindow />
</Suspense>
diff --git a/src/renderer/lib/initial-theme.test.ts b/src/renderer/lib/initial-theme.test.ts
new file mode 100644
index 00000000..bfdbb6bc
--- /dev/null
+++ b/src/renderer/lib/initial-theme.test.ts
@@ -0,0 +1,71 @@
+import '@testing-library/jest-dom/vitest'
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import {
+ applyInitialRendererTheme,
+ resolveInitialRendererTheme,
+} from './initial-theme'
+
+afterEach(() => {
+ vi.unstubAllGlobals()
+ window.localStorage.clear()
+ document.documentElement.classList.remove('light', 'dark')
+ document.documentElement.style.colorScheme = ''
+ document.getElementById('motrix-theme-bootstrap')?.remove()
+})
+
+describe('resolveInitialRendererTheme', () => {
+ it.each([
+ [true, 'dark'],
+ [false, 'light'],
+ ] as const)(
+ 'uses Electron nativeTheme propagation when prefersDark=%s',
+ (prefersDark, expected) => {
+ expect(
+ resolveInitialRendererTheme({
+ target: 'electron',
+ storedTheme: expected === 'dark' ? 'light' : 'dark',
+ prefersDark,
+ })
+ ).toBe(expected)
+ }
+ )
+
+ it.each(['light', 'dark'] as const)(
+ 'honors the web renderer stored theme %s',
+ (storedTheme) => {
+ expect(
+ resolveInitialRendererTheme({
+ target: 'web',
+ storedTheme,
+ prefersDark: storedTheme === 'light',
+ })
+ ).toBe(storedTheme)
+ }
+ )
+
+ it('falls back to the system preference for web system mode', () => {
+ expect(
+ resolveInitialRendererTheme({
+ target: 'web',
+ storedTheme: 'system',
+ prefersDark: true,
+ })
+ ).toBe('dark')
+ })
+
+ it('applies the pre-React class and removes the temporary bootstrap style', () => {
+ vi.stubGlobal(
+ 'matchMedia',
+ vi.fn(() => ({ matches: true }))
+ )
+ const bootstrapStyle = document.createElement('style')
+ bootstrapStyle.id = 'motrix-theme-bootstrap'
+ document.head.append(bootstrapStyle)
+
+ expect(applyInitialRendererTheme('electron')).toBe('dark')
+ expect(document.documentElement).toHaveClass('dark')
+ expect(document.documentElement).not.toHaveClass('light')
+ expect(document.documentElement.style.colorScheme).toBe('dark')
+ expect(document.getElementById('motrix-theme-bootstrap')).toBeNull()
+ })
+})
diff --git a/src/renderer/lib/initial-theme.ts b/src/renderer/lib/initial-theme.ts
new file mode 100644
index 00000000..2ea31396
--- /dev/null
+++ b/src/renderer/lib/initial-theme.ts
@@ -0,0 +1,52 @@
+export type ResolvedRendererTheme = 'light' | 'dark'
+
+interface ResolveInitialRendererThemeInput {
+ target: 'electron' | 'web'
+ storedTheme?: string | null
+ prefersDark: boolean
+}
+
+/**
+ * Resolve the class used before React mounts. Electron's main process applies
+ * the persisted preference to nativeTheme before opening a window, so its
+ * prefers-color-scheme value is authoritative. The web renderer has no native
+ * theme bridge and therefore consults next-themes' localStorage value first.
+ */
+export function resolveInitialRendererTheme({
+ target,
+ storedTheme,
+ prefersDark,
+}: ResolveInitialRendererThemeInput): ResolvedRendererTheme {
+ if (target === 'web' && (storedTheme === 'light' || storedTheme === 'dark')) {
+ return storedTheme
+ }
+ return prefersDark ? 'dark' : 'light'
+}
+
+export function applyInitialRendererTheme(
+ target: 'electron' | 'web' = __MOTRIX_TARGET__
+): ResolvedRendererTheme {
+ let storedTheme: string | null = null
+ if (target === 'web') {
+ try {
+ storedTheme = window.localStorage.getItem('theme')
+ } catch {
+ // Storage may be disabled; the system preference remains a safe default.
+ }
+ }
+
+ const theme = resolveInitialRendererTheme({
+ target,
+ storedTheme,
+ prefersDark: window.matchMedia('(prefers-color-scheme: dark)').matches,
+ })
+ const root = document.documentElement
+ root.classList.remove(theme === 'dark' ? 'light' : 'dark')
+ root.classList.add(theme)
+ root.style.colorScheme = theme
+ // The inline head style protects the blank document before the renderer
+ // bundle loads. Once the semantic stylesheet and theme class are ready it
+ // must be removed so platform rules such as macOS transparency can win.
+ document.getElementById('motrix-theme-bootstrap')?.remove()
+ return theme
+}
diff --git a/src/renderer/styles/globals.css b/src/renderer/styles/globals.css
index 408ba6ff..61120828 100644
--- a/src/renderer/styles/globals.css
+++ b/src/renderer/styles/globals.css
@@ -210,6 +210,21 @@
--window-chrome-safe-area-trailing: 112px;
}
+/* Fullscreen hides desktop caption controls but retains the Motrix menu and app
+ actions. Release only the trailing safe area; the leading 160px still keeps
+ compact PanelShell content clear of menu/sidebar/add-task controls. The
+ macOS desktop-controls mode previews the same behavior. */
+.platform-linux.window-main
+.electron-window-chrome:has(.window-chrome[data-fullscreen="true"]),
+.platform-darwin.window-main
+ .electron-window-chrome.preview-desktop-window-controls:has(
+ .window-chrome[data-fullscreen="true"]
+ ),
+.platform-win32.window-main
+ .electron-window-chrome:has(.window-chrome[data-fullscreen="true"]) {
+ --window-chrome-safe-area-trailing: 24px;
+}
+
@media (width >= 48rem) {
.electron-window-chrome.group\/sidebar-wrapper[data-state="expanded"]
.panel-action-align-visual-end {
@@ -287,10 +302,18 @@
background-color: rgb(247 247 248 / 72%);
}
+.dark.platform-darwin.window-onboarding [data-slot="onboarding-surface"] {
+ background-color: rgb(22 22 23 / 76%);
+}
+
@media (prefers-reduced-transparency: reduce) {
.platform-darwin.window-onboarding [data-slot="onboarding-surface"] {
background-color: #f7f7f8;
}
+
+ .dark.platform-darwin.window-onboarding [data-slot="onboarding-surface"] {
+ background-color: #161617;
+ }
}
/*
diff --git a/src/renderer/windows/onboarding-window.test.tsx b/src/renderer/windows/onboarding-window.test.tsx
index 5488a89c..519eb315 100644
--- a/src/renderer/windows/onboarding-window.test.tsx
+++ b/src/renderer/windows/onboarding-window.test.tsx
@@ -31,5 +31,14 @@ describe('OnboardingWindow', () => {
'pt-3.5'
)
expect(screen.getByRole('heading', { name: '使用声明' })).toBeVisible()
+ const surface = document.querySelector(
+ '[data-slot="onboarding-surface"]'
+ ) as HTMLElement
+ expect(surface).toHaveClass(
+ 'bg-[#f7f7f8]',
+ 'dark:bg-[#161617]',
+ 'text-foreground'
+ )
+ expect(surface.style.colorScheme).toBe('')
})
})
diff --git a/src/shared/protocol/events.ts b/src/shared/protocol/events.ts
index a4dbe055..00fc8d3d 100644
--- a/src/shared/protocol/events.ts
+++ b/src/shared/protocol/events.ts
@@ -6,6 +6,7 @@ export interface LocaleChangedPayload {
export interface WindowMaximizedChangedPayload {
maximized: boolean
+ fullscreen: boolean
}
export const Events = {