feat: app.on('activate') handle

This commit is contained in:
草鞋没号 2021-12-30 10:30:50 +08:00
parent aea6e9e822
commit b62d5fae87

View File

@ -13,7 +13,7 @@ if (!app.requestSingleInstanceLock()) {
let win: BrowserWindow | null = null
async function bootstrap() {
async function createWindow() {
win = new BrowserWindow({
webPreferences: {
preload: path.join(__dirname, '../preload/index.cjs'),
@ -27,12 +27,11 @@ async function bootstrap() {
const url = `http://${pkg.env.HOST || '127.0.0.1'}:${pkg.env.PORT}`
win.loadURL(url)
win.maximize()
win.webContents.openDevTools()
}
}
app.whenReady().then(bootstrap)
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
win = null
@ -49,6 +48,15 @@ app.on('second-instance', () => {
}
})
app.on('activate', () => {
const allWindows = BrowserWindow.getAllWindows()
if (allWindows.length) {
allWindows[0].focus()
} else {
createWindow()
}
})
// @TODO
// auto update
/* if (app.isPackaged) {