const { app, protocol, BrowserWindow } = require('electron')
|
const { createProtocol } = require('vue-cli-plugin-electron-builder/lib')
|
const path = require('path')
|
const isDevelopment = process.env.NODE_ENV !== 'production'
|
|
// 注册 scheme
|
protocol.registerSchemesAsPrivileged([
|
{ scheme: 'app', privileges: { secure: true, standard: true } }
|
])
|
|
async function createWindow() {
|
const win = new BrowserWindow({
|
width: 1200,
|
height: 800,
|
webPreferences: {
|
nodeIntegration: true,
|
contextIsolation: true,
|
preload: path.join(__dirname, 'electron/preload.js')
|
}
|
})
|
|
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
|
if (!process.env.IS_TEST) win.webContents.openDevTools()
|
} else {
|
createProtocol('app')
|
win.loadURL('app://./index.html')
|
}
|
}
|
|
app.on('window-all-closed', () => {
|
if (process.platform !== 'darwin') {
|
app.quit()
|
}
|
})
|
|
app.on('activate', () => {
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
})
|
|
app.on('ready', async () => {
|
createWindow()
|
})
|
|
if (isDevelopment) {
|
if (process.platform === 'win32') {
|
process.on('message', (data) => {
|
if (data === 'graceful-exit') {
|
app.quit()
|
}
|
})
|
} else {
|
process.on('SIGTERM', () => {
|
app.quit()
|
})
|
}
|
}
|