From cadda6181ca4bd9ce1fb36f753ec4af8df353848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E7=93=9C=C2=B0?= <8441078+i_melon@user.noreply.gitee.com> Date: Wed, 1 Jun 2022 00:59:34 +0800 Subject: [PATCH] new window example --- packages/main/index.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/main/index.ts b/packages/main/index.ts index 5779c82..ac405ae 100644 --- a/packages/main/index.ts +++ b/packages/main/index.ts @@ -1,4 +1,4 @@ -import { app, BrowserWindow, shell } from 'electron' +import { app, BrowserWindow, shell,ipcMain } from 'electron' import { release } from 'os' import { join } from 'path' @@ -68,3 +68,23 @@ app.on('activate', () => { createWindow() } }) + +// new window example arg: new windows url +ipcMain.handle("open-win", (event, arg) => { + const childWindow = new BrowserWindow({ + webPreferences: { + preload: join(__dirname, "../preload/index.cjs"), + }, + }); + + if (app.isPackaged) { + childWindow.loadFile(join(__dirname, `../renderer/index.html`), { + hash: `${arg}`, + }) + } else { + // 🚧 Use ['ENV_NAME'] avoid vite:define plugin + const url = `http://${process.env["VITE_DEV_SERVER_HOST"]}:${process.env["VITE_DEV_SERVER_PORT"]}/#${arg.url}` + childWindow.loadURL(url); + childWindow.webContents.openDevTools({ mode: "undocked", activate: true }) + } +});