2026-05-01 20:39:09 +08:00
|
|
|
import type { Session } from 'electron/main'
|
|
|
|
|
import { BrowserWindow, nativeTheme } from 'electron/main'
|
2026-04-19 14:18:20 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
import { attachWindowDiagnostics, loadWindowURLSafely } from './external-window'
|
2026-04-19 14:18:20 +08:00
|
|
|
|
|
|
|
|
interface ReviewWindowRecord {
|
2026-05-01 20:39:09 +08:00
|
|
|
taskId: string
|
|
|
|
|
window: BrowserWindow
|
2026-04-19 14:18:20 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
const reviewWindows = new Map<string, ReviewWindowRecord>()
|
2026-04-19 14:18:20 +08:00
|
|
|
|
|
|
|
|
export async function openReviewWindow(options: {
|
2026-05-01 20:39:09 +08:00
|
|
|
taskId: string
|
|
|
|
|
title: string
|
|
|
|
|
url: string
|
|
|
|
|
session: Session
|
2026-04-19 14:18:20 +08:00
|
|
|
}): Promise<void> {
|
2026-05-01 20:39:09 +08:00
|
|
|
const existing = reviewWindows.get(options.taskId)
|
2026-04-19 14:18:20 +08:00
|
|
|
if (existing && !existing.window.isDestroyed()) {
|
2026-05-01 20:39:09 +08:00
|
|
|
existing.window.show()
|
|
|
|
|
existing.window.focus()
|
2026-04-19 14:18:20 +08:00
|
|
|
if (existing.window.webContents.getURL() !== options.url) {
|
2026-05-01 20:39:09 +08:00
|
|
|
await loadWindowURLSafely(existing.window, options.url, options.title)
|
2026-04-19 14:18:20 +08:00
|
|
|
}
|
2026-05-01 20:39:09 +08:00
|
|
|
return
|
2026-04-19 14:18:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const window = new BrowserWindow({
|
|
|
|
|
width: 1440,
|
|
|
|
|
height: 960,
|
|
|
|
|
minWidth: 1120,
|
|
|
|
|
minHeight: 760,
|
|
|
|
|
title: options.title,
|
|
|
|
|
autoHideMenuBar: true,
|
2026-05-01 20:39:09 +08:00
|
|
|
backgroundColor: nativeTheme.shouldUseDarkColors ? '#15191a' : '#f4f1ea',
|
2026-04-19 14:18:20 +08:00
|
|
|
webPreferences: {
|
|
|
|
|
session: options.session,
|
|
|
|
|
sandbox: true,
|
|
|
|
|
contextIsolation: true,
|
|
|
|
|
nodeIntegration: false,
|
|
|
|
|
},
|
2026-05-01 20:39:09 +08:00
|
|
|
})
|
2026-04-19 14:18:20 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
attachWindowDiagnostics(window, options.title)
|
|
|
|
|
reviewWindows.set(options.taskId, { taskId: options.taskId, window })
|
|
|
|
|
window.on('closed', () => {
|
|
|
|
|
reviewWindows.delete(options.taskId)
|
|
|
|
|
})
|
2026-04-19 14:18:20 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
await loadWindowURLSafely(window, options.url, options.title)
|
|
|
|
|
window.show()
|
|
|
|
|
window.focus()
|
2026-04-19 14:18:20 +08:00
|
|
|
}
|