You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.2 KiB
97 lines
2.2 KiB
'use strict' |
|
|
|
import { app, protocol, BrowserWindow, nativeImage, ipcMain } from 'electron' |
|
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib' |
|
const path = require('path') |
|
import * as iconManger from '@/iconManager' |
|
import createTray from '@/tray' |
|
const isDevelopment = process.env.NODE_ENV !== 'production' |
|
|
|
const winURL = process.env.NODE_ENV === 'development' |
|
? 'http://localhost:8080' |
|
: `file://${__dirname}/index.html` |
|
|
|
//引入自定义菜单 |
|
require('./menu') |
|
//引入监听 |
|
require('./listener') |
|
|
|
// Scheme must be registered before the app is ready |
|
protocol.registerSchemesAsPrivileged([ |
|
{ scheme: 'app', privileges: { secure: true, standard: true } } |
|
]) |
|
|
|
async function createWindow() { |
|
// Create the browser window. |
|
let win = new BrowserWindow({ |
|
width: 1200, |
|
height: 800, |
|
show: false, |
|
icon: path.resolve(__dirname, iconManger.ICON_PATHS.APP_ICON), |
|
webPreferences: { |
|
preload: path.resolve(__dirname, './preload.js'), |
|
nodeIntegration: false, |
|
contextIsolation: true |
|
} |
|
}) |
|
createTray(app, win, nativeImage); |
|
|
|
|
|
createProtocol('app') |
|
win.loadURL(`${winURL}` + '/#/') |
|
|
|
// win.webContents.openDevTools({ mode: 'right' }); |
|
win.once('ready-to-show', () => { |
|
win.setTitle('Utils-Hub'); // 设置窗口标题 |
|
win.show(); |
|
}); |
|
|
|
win.on('close', (e) => { |
|
|
|
//回收BrowserWindow对象 |
|
app.quit(); |
|
// if (win.isMinimized()) { |
|
// console.log('关闭应用窗口') |
|
// win = null; |
|
// } else { |
|
// e.preventDefault(); |
|
// win.minimize(); |
|
// win.hide(); |
|
// } |
|
|
|
}) |
|
|
|
} |
|
|
|
// Quit when all windows are closed. |
|
app.on('window-all-closed', () => { |
|
if (process.platform !== 'darwin') { |
|
app.quit() |
|
} |
|
}) |
|
|
|
app.on('activate', () => { |
|
console.log('应用激活') |
|
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow() |
|
}) |
|
|
|
app.on('ready', async () => { |
|
|
|
createWindow() |
|
}) |
|
|
|
// Exit cleanly on request from parent process in development mode. |
|
if (isDevelopment) { |
|
if (process.platform === 'win32') { |
|
process.on('message', (data) => { |
|
if (data === 'graceful-exit') { |
|
app.quit() |
|
} |
|
}) |
|
} else { |
|
process.on('SIGTERM', () => { |
|
app.quit() |
|
}) |
|
} |
|
}
|
|
|