mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-01-19 11:56:36 +08:00
new window example
This commit is contained in:
parent
1167378f0d
commit
cadda6181c
@ -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 })
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user