Skip to content

Commit

Permalink
Merge pull request HalseySpicy#137 from wxh0402/main
Browse files Browse the repository at this point in the history
new window example
  • Loading branch information
youngleish authored Jun 1, 2022
2 parents 694f51f + 347bfde commit e554d8f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/main/index.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -71,3 +71,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}`
childWindow.loadURL(url);
// childWindow.webContents.openDevTools({ mode: "undocked", activate: true })
}
});

0 comments on commit e554d8f

Please sign in to comment.