Skip to content

Commit cadda61

Browse files
author
西瓜°
committed
new window example
1 parent 1167378 commit cadda61

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/main/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app, BrowserWindow, shell } from 'electron'
1+
import { app, BrowserWindow, shell,ipcMain } from 'electron'
22
import { release } from 'os'
33
import { join } from 'path'
44

@@ -68,3 +68,23 @@ app.on('activate', () => {
6868
createWindow()
6969
}
7070
})
71+
72+
// new window example arg: new windows url
73+
ipcMain.handle("open-win", (event, arg) => {
74+
const childWindow = new BrowserWindow({
75+
webPreferences: {
76+
preload: join(__dirname, "../preload/index.cjs"),
77+
},
78+
});
79+
80+
if (app.isPackaged) {
81+
childWindow.loadFile(join(__dirname, `../renderer/index.html`), {
82+
hash: `${arg}`,
83+
})
84+
} else {
85+
// 🚧 Use ['ENV_NAME'] avoid vite:define plugin
86+
const url = `http://${process.env["VITE_DEV_SERVER_HOST"]}:${process.env["VITE_DEV_SERVER_PORT"]}/#${arg.url}`
87+
childWindow.loadURL(url);
88+
childWindow.webContents.openDevTools({ mode: "undocked", activate: true })
89+
}
90+
});

0 commit comments

Comments
 (0)