监听窗口创建完成

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// src/main/index.ts

// 1. 监听新窗口创建请求 (拦截层)
mainWindow.webContents.setWindowOpenHandler((details) => {
// details.url 包含了新窗口的 URL
// details.frameName 可能是 dockview 指定的名字
console.log('⚡️ 检测到 Tab 被拖出,正在请求创建窗口:', details.url)

// 你可以在这里判断 url 是否包含特定的 query 参数,来确定这是 dockview 的弹窗

return {
action: 'allow',
overrideBrowserWindowOptions: {
// 在这里强制指定新窗口的样式
autoHideMenuBar: true,
webPreferences: {
preload: join(__dirname, '../preload/index.js'), // 别忘了 preload
backgroundThrottling: false,
// ...其他配置
}
}
}
})

// 2. 监听窗口创建完成 (结果层)
mainWindow.webContents.on('did-create-window', (childWindow, details) => {
console.log('✅ 新窗口实例已创建 (Tab 弹出成功)')

// 业务场景:你可能想告诉主渲染进程“有个子窗口诞生了”
mainWindow.webContents.send('popout-window-created', {
id: childWindow.id,
title: childWindow.getTitle()
})

// 业务场景:监听子窗口的关闭,做一些清理工作
childWindow.on('closed', () => {
console.log('❌ 子窗口已关闭')
mainWindow.webContents.send('popout-window-closed', { id: childWindow.id })
})
})

当前网速较慢或者你使用的浏览器不支持博客特定功能,请尝试刷新或换用Chrome、Firefox等现代浏览器