electron launcher
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.
 
 
 

79 lines
2.7 KiB

const {app, BrowserWindow, dialog, protocol, ipcMain} = require('electron')
const {create: createMainWindow} = require('./windows/main')
const {MANUAL_CREATED_FLAG,} = require('./constant')
const handleIPC = require('./ipc')
const {sinceTime,sinceTimeEnd} = require('./SinceTimeTool')
sinceTime()
const store = require('./windows/lib/store');
const isFirstInstall = store.get("firstInstall");
if (isFirstInstall) {
console.log('<========清除历史缓存=====>')
app.commandLine.appendSwitch("--disable-http-cache");
store.set("firstInstall", false);
}
// 关闭GPU加速
// app.disableHardwareAcceleration()
// app.allowRendererProcessReuse = true
app.whenReady().then(() => {
// 启动应用时自动启动监控平台接口服务
// const child_process = require('child_process')
// if (global.worker !== 'start') {
// let worker = child_process.fork('D:\\linyun\\workspace\\front-monitor-api\\src\\app.js',[])
// global.worker = 'start'
// }
const gotTheLock = app.requestSingleInstanceLock();
console.log('gotTheLock',gotTheLock)
// if (!gotTheLock) {
// dialog.showMessageBox(win,{
// type: "warning",
// title: "提示",
// message: "您已打开指挥系统!请勿重复操作",
// }).then(() => {
// app.exit()
// })
// return;
// }
protocol.registerFileProtocol('file', (request, callback) => {
const pathname = decodeURI(request.url.replace('file:///', ''));
callback(pathname);
});
sinceTimeEnd('whenReady')
handleIPC();
sinceTimeEnd('handleIPC')
createMainWindow();
sinceTimeEnd('createWindowEnd')
app.on('browser-window-created', (event, window) => {
setTimeout(() => {
if (window[MANUAL_CREATED_FLAG]) { // allow safe created manually
return
}
dialog.showMessageBox({
type: "warning",
title: "提示",
message: "新开窗口必须使用内置openWindow接口",
})
try {
window.destroy()
} catch (e) {
console.error(e)
}
}, 100)
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createMainWindow()
}
})
})
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})