mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-04-08 04:50:14 +08:00
60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
import path from 'path'
|
|
import { app, BrowserWindow } from 'electron'
|
|
|
|
app.disableHardwareAcceleration()
|
|
|
|
if (!app.requestSingleInstanceLock()) {
|
|
app.quit()
|
|
process.exit(0)
|
|
}
|
|
|
|
let win: BrowserWindow | null = null
|
|
|
|
async function bootstrap() {
|
|
win = new BrowserWindow({
|
|
webPreferences: {
|
|
preload: path.join(__dirname, '../preload/index.cjs'),
|
|
},
|
|
})
|
|
|
|
if (app.isPackaged) {
|
|
win.loadFile(path.join(__dirname, '../renderer/index.html'))
|
|
} else {
|
|
const pkg = await import('../../package.json')
|
|
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.on('window-all-closed', () => {
|
|
win = null
|
|
if (process.platform !== 'darwin') {
|
|
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()
|
|
}
|
|
})
|
|
|
|
// @TODO
|
|
// 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)
|
|
)
|
|
} */
|