MCPcopy Create free account
hub / github.com/ZToolsCenter/ZTools / createWindow

Method createWindow

src/main/core/pluginWindowManager.ts:209–313  ·  view source on GitHub ↗

* 创建插件独立窗口 * @returns win.id(数字)

(
    pluginPath: string,
    pluginName: string,
    sessionPartition: string,
    url: string,
    options: BrowserWindowConstructorOptions,
    senderWebContents: Electron.WebContents
  )

Source from the content-addressed store, hash-verified

207 * @returns win.id(数字)
208 */
209 public createWindow(
210 pluginPath: string,
211 pluginName: string,
212 sessionPartition: string,
213 url: string,
214 options: BrowserWindowConstructorOptions,
215 senderWebContents: Electron.WebContents
216 ): BrowserWindow {
217 // 处理 preload 路径(如果是相对路径)
218 let preloadPath = options.webPreferences?.preload
219 if (preloadPath && !path.isAbsolute(preloadPath)) {
220 preloadPath = path.join(pluginPath, preloadPath)
221 }
222
223 // 使用插件名称创建 session,确保和插件主视图共享同一个 session
224 const sess = session.fromPartition(sessionPartition)
225 sess.registerPreloadScript({
226 type: 'frame',
227 filePath: mainPreload
228 })
229
230 // 应用代理配置到插件 session
231 proxyManager
232 .applyProxyToSession(sess, `插件窗口 ${pluginName} (${sessionPartition})`)
233 .catch((error) => {
234 console.error(
235 `[pluginWindow:create] 插件窗口 ${pluginName} (${sessionPartition}) 应用代理配置失败:`,
236 error
237 )
238 })
239
240 const win = new BrowserWindow({
241 ...options,
242 webPreferences: {
243 ...options.webPreferences,
244 preload: preloadPath,
245 session: sess,
246 contextIsolation: false,
247 nodeIntegration: false,
248 webSecurity: false,
249 sandbox: false
250 }
251 })
252
253 // 保存窗口信息(以 win.id 为键)
254 this.windowInfoMap.set(win.id, {
255 window: win,
256 parentWebContents: senderWebContents,
257 pluginPath,
258 pluginName,
259 sessionPartition
260 })
261
262 // 加载 URL
263 if (url.startsWith('http')) {
264 win.loadURL(url)
265 } else if (url.startsWith('file:///')) {
266 win.loadURL(url)

Callers

nothing calls this directly

Calls 2

applyProxyToSessionMethod · 0.80
onMethod · 0.80

Tested by

no test coverage detected