Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): fall back when native window drag initialization fails
zcinta05148ea696c8f31f
diff --git a/apps/desktop/src/main/__tests__/windowManualDrag.test.ts b/apps/desktop/src/main/__tests__/windowManualDrag.test.tsindex 77fd70c16c..19b6c3c4d5 100644--- a/apps/desktop/src/main/__tests__/windowManualDrag.test.ts+++ b/apps/desktop/src/main/__tests__/windowManualDrag.test.ts@@ -132,6 +132,32 @@ describe('WindowManualDragController', () => {expect(bounds).not.toHaveBeenCalled();});+ // #7898 review: a native offset read can throw during a Windows desktop+ // switch. Unit tier: start must still move with fixed bounds and stop normally;+ // prior native coverage only exercised a follower returning false after start.+ it('falls back to fixed bounds when native drag initialization throws', () => {+ const { screen, cursor } = makeScreen();+ const win = makeWindow();+ const error = new Error('GetCursorPos failed');+ const report = vi.fn();+ const controller = new WindowManualDragController(screen, 16, 1000, () => {+ throw error;+ }, report);++ expect(() => controller.start(win)).not.toThrow();+ expect(report).toHaveBeenCalledWith(error);+ cursor.x += 40;+ cursor.y += 20;+ vi.advanceTimersByTime(16);+ expect(win.position).toEqual([140, 120]);+ expect(win.size).toEqual([813, 607]);+ controller.stop(win);+ cursor.x += 40;+ vi.advanceTimersByTime(16);+ expect(win.position).toEqual([140, 120]);+ expect(controller.isDragging()).toBe(false);+ });+it('clamps window y to the display workArea top (menu bar)', () => {const { screen, cursor } = makeScreen(25);const win = makeWindow(100, 100);diff --git a/apps/desktop/src/main/bootstrap-electron.ts b/apps/desktop/src/main/bootstrap-electron.tsindex fb343b879b..024ae9a07b 100644--- a/apps/desktop/src/main/bootstrap-electron.ts+++ b/apps/desktop/src/main/bootstrap-electron.ts@@ -5572,7 +5572,9 @@ const registerIpcHandlers = () => {if (!native || !handle) return null;const offset = native.windowDragOffset(handle);return () => native.moveWindowAtCursor(handle, offset.x, offset.y);- } : undefined);+ } : undefined, (error: unknown) => {+ windowDragLog.warn('Windows native window drag initialization failed; using DIP bounds fallback', error);+ });// start / stop 都严格绑定 sender 窗口,解析不到(窗口销毁中)直接忽略,// 不 fallback 主窗:多窗口下副窗的延迟消息若落到主窗上,start 会让主窗diff --git a/apps/desktop/src/main/windowManualDrag.ts b/apps/desktop/src/main/windowManualDrag.tsindex 250d14d9c0..5b2a9ce63f 100644--- a/apps/desktop/src/main/windowManualDrag.ts+++ b/apps/desktop/src/main/windowManualDrag.ts@@ -62,6 +62,7 @@ export class WindowManualDragController {private readonly intervalMs: number = FOLLOW_INTERVAL_MS,private readonly maxDurationMs: number = MAX_DRAG_DURATION_MS,private readonly nativeFollower?: (win: DragWindowLike) => (() => boolean) | null,+ private readonly onNativeStartError?: (error: unknown) => void,) {}/**@@ -77,7 +78,14 @@ export class WindowManualDragController {this.stop();if (win.isDestroyed() || win.isMaximized() || win.isFullScreen()) return;- const followNative = this.nativeFollower?.(win);+ let followNative: (() => boolean) | null | undefined;+ try {+ followNative = this.nativeFollower?.(win);+ } catch (error: unknown) {+ // Offset reads may fail during a Windows desktop switch. Keep the drag+ // available through the fixed-bounds fallback instead of escaping IPC.+ this.onNativeStartError?.(error);+ }const cursor = this.screen.getCursorScreenPoint();const { x: winX, y: winY, width, height } = win.getBounds();const offsetX = cursor.x - winX;