Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 处理资源监视器全屏转换竞态
David23236a5f3412
diff --git a/apps/desktop/src/main/resource-usage-window/__tests__/controller.test.ts b/apps/desktop/src/main/resource-usage-window/__tests__/controller.test.tsindex b4384369b9..20638c33f6 100644--- a/apps/desktop/src/main/resource-usage-window/__tests__/controller.test.ts+++ b/apps/desktop/src/main/resource-usage-window/__tests__/controller.test.ts@@ -396,7 +396,7 @@ describe('ResourceUsageWindowController', () => {expect(owner.focus).not.toHaveBeenCalled();});- it('ignores owner hide during a macOS native fullscreen Space transition', () => {+ it('tracks a pending macOS fullscreen entry without hiding the resource window', () => {const windows: FakeWindow[] = [];const mainSender = { id: 100 } as WebContents;const ownerListeners = new Map<string, () => void>();@@ -426,11 +426,15 @@ describe('ResourceUsageWindowController', () => {expect(controller.open(mainSender)).toBe(true);windows[0]?.hide.mockClear();- expect(ownerListeners.has('hide')).toBe(false);+ expect(ownerListeners.has('hide')).toBe(true);ownerListeners.get('hide')?.();expect(windows[0]?.hide).not.toHaveBeenCalled();- ownerListeners.get('minimize')?.();+ windows[0]?.close();+ expect(windows[0]?.setFullScreen).toHaveBeenCalledWith(false);+ expect(windows[0]?.hide).not.toHaveBeenCalled();++ windows[0]?.emitWindow('leave-full-screen');expect(windows[0]?.hide).toHaveBeenCalledOnce();});diff --git a/apps/desktop/src/main/resource-usage-window/__tests__/windowSecurity.test.ts b/apps/desktop/src/main/resource-usage-window/__tests__/windowSecurity.test.tsindex 091c81cad3..168f426972 100644--- a/apps/desktop/src/main/resource-usage-window/__tests__/windowSecurity.test.ts+++ b/apps/desktop/src/main/resource-usage-window/__tests__/windowSecurity.test.ts@@ -28,13 +28,15 @@ describe('resource usage BrowserWindow security contract', () => {expect(source).not.toContain("once('ready-to-show'");});- it('only drives fullscreen to exit before hiding and follows its own native fullscreen events', () => {+ it('only drives fullscreen to exit and uses the shared native-state broadcaster', () => {expect(controllerSource).toContain("win.once('leave-full-screen'");expect(controllerSource).toContain('win.setFullScreen(false)');expect(controllerSource).not.toContain('win.setFullScreen(true)');- expect(controllerSource).not.toContain("'enter-full-screen'");- expect(source).toContain("win.on('enter-full-screen'");- expect(source).toContain("win.on('leave-full-screen'");+ expect(controllerSource).toContain("win.on('enter-full-screen'");+ expect(source).toContain('installWindowFullscreenStateBroadcast(win');+ expect(source).toContain('screen.getDisplayMatching(bounds).bounds');+ expect(source).not.toContain("win.on('enter-full-screen'");+ expect(source).not.toContain("win.on('leave-full-screen'");expect(preloadSource).toContain('onFullscreenChange: fanOutFullscreenChange');expect(preloadSource).toContain("getFullscreenState: (): Promise<boolean> => ipcRenderer.invoke('get-fullscreen-state')",diff --git a/apps/desktop/src/main/resource-usage-window/controller.ts b/apps/desktop/src/main/resource-usage-window/controller.tsindex 50ac0c054b..ab8fe71036 100644--- a/apps/desktop/src/main/resource-usage-window/controller.ts+++ b/apps/desktop/src/main/resource-usage-window/controller.ts@@ -65,6 +65,8 @@ export class ResourceUsageWindowController {private locale: SupportedLocale | null = null;private lastOwner: ResourceUsageOwnerWindow | null = null;private ownerHideUnsubscribers: Array<() => void> = [];+ /** macOS 原生全屏动画开始后,isFullScreen() 在 enter-full-screen 前仍可能返回 false。 */+ private enteringNativeFullscreen = false;/** 关闭全屏与重新打开可能交错;迟到的 leave-full-screen 只能完成原来的隐藏请求。 */private visibilityGeneration = 0;@@ -241,6 +243,12 @@ export class ResourceUsageWindowController {win.on('restore', () => this.onNativeVisibilityChanged(win, true));win.on('hide', () => this.onNativeVisibilityChanged(win, false));win.on('minimize', () => this.onNativeVisibilityChanged(win, false));+ win.on('enter-full-screen', () => {+ if (win === this.winRef && !win.isDestroyed()) this.enteringNativeFullscreen = false;+ });+ win.on('leave-full-screen', () => {+ if (win === this.winRef && !win.isDestroyed()) this.enteringNativeFullscreen = false;+ });// index.html 的 <title>Cindy</title> 会在每次导航发出 page-title-updated,// 不拦截的话 Mission Control / 任务栏会把本地化标题盖回 Cindy。win.webContents.on('page-title-updated', (event) => {@@ -294,6 +302,7 @@ export class ResourceUsageWindowController {this.clearPrewarmTimeout();this.clearLeaveTimeout();this.pendingOpen = false;+ if (!win.isVisible()) this.enteringNativeFullscreen = false;this.visibilityGeneration += 1;this.setSamplingActive(win, true);if (win.isMinimized()) win.restore();@@ -322,7 +331,7 @@ export class ResourceUsageWindowController {this.visible = false;if (options.restoreOwner !== false) this.focusOwnerWindow();};- if (this.platform() === 'darwin' && win.isFullScreen()) {+ if (this.platform() === 'darwin' && (this.enteringNativeFullscreen || win.isFullScreen())) {win.once('leave-full-screen', finishHide);win.setFullScreen(false);this.leaveTimeout = setTimeout(@@ -346,14 +355,31 @@ export class ResourceUsageWindowController {if (!owner?.on) return;const hide = () => this.hideWithOwner();// macOS 切换独立窗口的原生全屏 Space 时,owner 可能短暂发出 hide;把它- // 当成“主窗口主动隐藏”会立刻 hide 正在进入全屏的资源窗口。主窗口红灯关闭- // 已在 bootstrap 中显式调用 hideWithOwner,因此 macOS 这里只跟随 minimize / closed。- const events: Array<'hide' | 'minimize' | 'closed'> =- this.platform() === 'darwin' ? ['minimize', 'closed'] : ['hide', 'minimize', 'closed'];+ // 当成“主窗口主动隐藏”会立刻 hide 正在进入全屏的资源窗口。这里把它作为进入动画+ // 已开始的早期信号,确保 enter-full-screen 尚未到达时关闭也会先取消原生转换。+ if (this.platform() === 'darwin') {+ const trackFullscreenEntry = () => this.trackFullscreenEntryFromOwnerHide();+ owner.on('hide', trackFullscreenEntry);+ owner.on('minimize', hide);+ owner.on('closed', hide);+ this.ownerHideUnsubscribers = [+ () => this.safeOff(owner, 'hide', trackFullscreenEntry),+ () => this.safeOff(owner, 'minimize', hide),+ () => this.safeOff(owner, 'closed', hide),+ ];+ return;+ }+ const events: Array<'hide' | 'minimize' | 'closed'> = ['hide', 'minimize', 'closed'];for (const event of events) owner.on(event, hide);this.ownerHideUnsubscribers = events.map((event) => () => this.safeOff(owner, event, hide));}+ private trackFullscreenEntryFromOwnerHide(): void {+ const win = this.winRef;+ if (!win || win.isDestroyed() || !win.isVisible() || win.isFullScreen()) return;+ this.enteringNativeFullscreen = true;+ }+private unbindOwnerVisibility(): void {for (const unsubscribe of this.ownerHideUnsubscribers) unsubscribe();this.ownerHideUnsubscribers = [];@@ -431,6 +457,7 @@ export class ResourceUsageWindowController {this.pendingOpen = false;this.samplingActive = false;this.destroyingWindow = false;+ this.enteringNativeFullscreen = false;if (!options.preserveOwner) {this.unbindOwnerVisibility();this.lastOwner = null;diff --git a/apps/desktop/src/main/resource-usage-window/window.ts b/apps/desktop/src/main/resource-usage-window/window.tsindex d4f0f43659..72977be01d 100644--- a/apps/desktop/src/main/resource-usage-window/window.ts+++ b/apps/desktop/src/main/resource-usage-window/window.ts@@ -13,10 +13,11 @@* - 通过 `resourceUsageWindow=1` 进入独立轻量 renderer 模块图*/-import { BrowserWindow, app, nativeTheme } from 'electron';+import { BrowserWindow, app, nativeTheme, screen } from 'electron';import path from 'node:path';import { createLogger } from '../logger.js';+import { installWindowFullscreenStateBroadcast } from '../mainWindowFullscreenStartup.js';import { markAppContentWindow } from '../windowFocusClassifier.js';import { installExternalLinkGuards } from '../secondary-windows.js';import { installSelectionContextMenu } from '../selection-context-menu.js';@@ -65,13 +66,10 @@ export function createResourceUsageWindow(parent?: BrowserWindow): BrowserWindowwebviewTag: false,},});- // 与分离右侧栏一致:辅助窗口拥有自己的原生全屏生命周期,状态必须由本窗口- // 推给 renderer,不能依赖主窗口的 fullscreen-change。- win.on('enter-full-screen', () => {- if (!win.isDestroyed()) win.webContents.send('fullscreen-change', true);- });- win.on('leave-full-screen', () => {- if (!win.isDestroyed()) win.webContents.send('fullscreen-change', false);+ // 辅助窗口拥有自己的原生全屏生命周期;退出动画开始时交通灯已经恢复,需通过+ // resize 边界兜底提前撤掉 renderer 的全屏标题留白,不能只等待 leave-full-screen。+ installWindowFullscreenStateBroadcast(win, {+ getDisplayBounds: (bounds) => screen.getDisplayMatching(bounds).bounds,});markResourceUsageWebContentsId(win.webContents.id);markAppContentWindow(win);