diff --git a/src/main/desktop-pick.ts b/src/main/desktop-pick.ts index 0513c89..0b9143b 100644 --- a/src/main/desktop-pick.ts +++ b/src/main/desktop-pick.ts @@ -28,6 +28,8 @@ export interface DesktopPickResult { } export async function pickDesktopElement(): Promise { + const appWindows = BrowserWindow.getAllWindows().filter(w => !w.isDestroyed() && w.isVisible()); + for (const w of appWindows) w.minimize(); const { stdout } = await run("powershell.exe", ["-NoProfile", "-STA", "-ExecutionPolicy", "Bypass", "-File", pickerScriptPath()], { timeout: 180000, windowsHide: false, maxBuffer: 4 * 1024 * 1024 }); const jsonLine = stdout.trim().split(/\\r?\\n/).reverse().find(l => l.trim().startsWith("{")); if (!jsonLine) throw new RuntimeError("picker_failed", "拾取未返回结果"); @@ -48,6 +50,8 @@ export async function listVisibleWindows(): Promise; } export async function pickScreenRegion(): Promise<{ x: number; y: number; width: number; height: number; imagePath: string }> { + const appWindows = BrowserWindow.getAllWindows().filter(w => !w.isDestroyed() && w.isVisible()); + for (const w of appWindows) w.minimize(); const display = screen.getPrimaryDisplay(); const sx = display.bounds.x, sy = display.bounds.y, sw = display.bounds.width, sh = display.bounds.height; const win = new BrowserWindow({ @@ -85,6 +89,7 @@ export async function pickScreenRegion(): Promise<{ x: number; y: number; width: if ((error as Error).message.includes("已取消框选")) throw error; } } + for (const w of appWindows) { if (!w.isDestroyed()) w.restore(); } win.destroy(); if (!region) throw new RuntimeError("pick_cancelled", "未完成框选"); await new Promise(r => setTimeout(r, 300)); @@ -103,4 +108,4 @@ export async function pickScreenRegion(): Promise<{ x: number; y: number; width: ].join(""); await run("powershell.exe", ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", psScript], { timeout: 30000, windowsHide: true }); return { ...region, imagePath }; -} \ No newline at end of file +}