fix(client): mount the shell.leading seat on macOS only and cover the fullscreen relay

This commit is contained in:
Yif committed 2026-09-18 14:28:07 +08:00
1 parent 02bb08ecd9
commit 9ae6f0defa
4 files changed
+76 -4

No files matched your search

+35
View File
@@ -74,6 +74,8 @@ const harness = await vi.hoisted(async () => {
super(); if (windowFailure !== undefined) throw windowFailure; windows.push(this); if (options.modal) policyBlocked.resolve()
}
isDestroyed() { return this.destroyed }
fullscreen = false
isFullScreen() { return this.fullscreen }
isMinimized() { return false }
isFocused() { return true }
async loadURL(url: string) {
@@ -518,6 +520,39 @@ describe('desktop main startup', () => {
expect(harness.hosts).toHaveLength(0)
})
it('relays the macOS fullscreen state on transitions and after each load', async () => {
vi.spyOn(process, 'platform', 'get').mockReturnValue('darwin')
await import('../src/main.ts')
await harness.preparing.promise
const window = harness.windows[0]!
const sent = () => window.webContents.send.mock.calls.filter(([channel]) => channel === DESKTOP_IPC.windowFullscreen)
expect(sent()).toHaveLength(0)
window.fullscreen = true
window.emit('enter-full-screen')
expect(sent().at(-1)).toEqual([DESKTOP_IPC.windowFullscreen, true])
// A reload re-registers the preload listener; the finished load resends
// the current state so fullscreen CSS survives the reload.
window.webContents.emit('did-finish-load')
expect(sent().at(-1)).toEqual([DESKTOP_IPC.windowFullscreen, true])
window.fullscreen = false
window.emit('leave-full-screen')
expect(sent().at(-1)).toEqual([DESKTOP_IPC.windowFullscreen, false])
const relayed = sent().length
window.destroyed = true
window.emit('enter-full-screen')
expect(sent()).toHaveLength(relayed)
})
it.each(['win32', 'linux'] as const)('registers no fullscreen relay on %s', async (platform) => {
vi.spyOn(process, 'platform', 'get').mockReturnValue(platform)
await import('../src/main.ts')
await harness.preparing.promise
const window = harness.windows[0]!
window.emit('enter-full-screen')
window.webContents.emit('did-finish-load')
expect(window.webContents.send.mock.calls.filter(([channel]) => channel === DESKTOP_IPC.windowFullscreen)).toHaveLength(0)
})
it('follows the Windows primary document language and palette without trusting other frames', async () => {
vi.spyOn(process, 'platform', 'get').mockReturnValue('win32')
await import('../src/main.ts')
@@ -0,0 +1,33 @@
// @vitest-environment jsdom
import { afterEach, expect, it, vi } from 'vitest'
import { DESKTOP_IPC } from '../src/ipc.ts'
import { syncWindowFullscreen } from '../src/preload-platform.ts'
const on = vi.hoisted(() => vi.fn())
vi.mock('electron', () => ({ ipcRenderer: { on } }))
afterEach(() => {
delete document.documentElement.dataset.fullscreen
vi.restoreAllMocks()
on.mockClear()
})
it.each(['win32', 'linux'] as const)('subscribes no fullscreen channel on %s', (platform) => {
vi.spyOn(process, 'platform', 'get').mockReturnValue(platform)
syncWindowFullscreen()
expect(on).not.toHaveBeenCalled()
})
it('mirrors the sent fullscreen state onto html[data-fullscreen] on darwin', () => {
vi.spyOn(process, 'platform', 'get').mockReturnValue('darwin')
syncWindowFullscreen()
expect(on).toHaveBeenCalledExactlyOnceWith(DESKTOP_IPC.windowFullscreen, expect.any(Function))
const handler = on.mock.calls[0]?.[1] as (event: unknown, fullscreen: boolean) => void
handler({}, true)
expect(document.documentElement.dataset.fullscreen).toBe('true')
handler({}, false)
expect(document.documentElement.dataset.fullscreen).toBeUndefined()
// A repeated windowed report stays a no-op rather than toggling the flag.
handler({}, false)
expect(document.documentElement.dataset.fullscreen).toBeUndefined()
})
@@ -266,11 +266,12 @@ export function AppFrame({
), [usePanelInfo, renderSlot])
const overlays = useMemo(() => renderSlot('shell.overlay', {}), [renderSlot])
// Window-chrome seat over the main panels' top-left corner: only a fully
// hidden sidebar column (macOS desktop collapse) leaves window chrome
// without a home. AppFrame.module.css publishes the matching
// hidden sidebar column on macOS desktop leaves window chrome without a
// home — the Windows zero-width collapse keeps its controls in the caption
// row (ui-sidebar). AppFrame.module.css publishes the matching
// --dsh-frame-leading-clearance under the same collapsed condition.
const leading = useMemo(() => renderSlot('shell.leading', {}), [renderSlot])
const leadingMounted = sidebarCollapsed && collapsedWidth === 0
const leadingMounted = darwin && sidebarCollapsed
return (
<div
@@ -229,11 +229,14 @@ describe('AppFrame', () => {
it('keeps Windows caption controls mounted with a zero-width collapsed column', () => {
document.documentElement.setAttribute('data-windows-titlebar', '')
try {
const { frame, instance, sidebarOwner, getByTestId } = mountFrame()
const { frame, instance, sidebarOwner, getByTestId, queryByTestId } = mountFrame()
act(() => { instance.actions.toggleSidebar() })
expect(tracks(frame)[0]).toBe(0)
expect(sidebarOwner()).toMatchObject({ collapsed: true, width: 0 })
expect(getByTestId('sidebar-content')).toBeTruthy()
// The caption row keeps the reopen controls; the darwin-only
// shell.leading seat must not mount a duplicate set.
expect(queryByTestId('shell.leading-content')).toBeNull()
} finally {
document.documentElement.removeAttribute('data-windows-titlebar')
}