feat: improve some functions

This commit is contained in:
草鞋没号 2021-11-08 10:21:15 +08:00
parent d13bad26f7
commit 2221092da5

View File

@ -2,6 +2,16 @@ import path from 'path'
import { app, BrowserWindow } from 'electron' import { app, BrowserWindow } from 'electron'
import { register } from './communication' import { register } from './communication'
/**
* Main Process some code reference https://github.com/cawa-93/vite-electron-builder
*/
app.disableHardwareAcceleration()
if (!app.requestSingleInstanceLock()) {
app.quit()
process.exit(0)
}
let win: BrowserWindow | null = null let win: BrowserWindow | null = null
function bootstrap() { function bootstrap() {
@ -27,5 +37,26 @@ app.whenReady().then(bootstrap)
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
win = null win = null
if (process.platform !== 'darwin') {
app.quit() app.quit()
}
}) })
app.on('second-instance', () => {
if (win) {
// someone tried to run a second instance, we should focus our window.
if (win.isMinimized()) win.restore()
win.focus()
}
})
// auto update
if (app.isPackaged) {
app.whenReady()
.then(() => import('electron-updater'))
.then(({ autoUpdater }) => autoUpdater.checkForUpdatesAndNotify())
.catch((e) =>
// maybe you need to record some log files.
console.error('Failed check update:', e)
)
}