|
|
const {app, BrowserWindow, dialog, protocol, session} = 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 filter = {urls: ['http://127.0.0.1:5500/*']}; session.defaultSession.webRequest.onHeadersReceived(filter, (details,callback) => { if(details.responseHeaders && details.responseHeaders['Set-Cookie']){ for(let i = 0;i < details.responseHeaders['Set-Cookie'].length;i++) details.responseHeaders['Set-Cookie'][i] += ";SameSite=None;Secure"; } callback({ responseHeaders: details.responseHeaders}); }) app.commandLine.appendSwitch('disable-features','BlockInsecurePrivateNetworkRequests') // 启动应用时自动启动监控平台接口服务
// 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')
// 兼容https非可信域
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => { //允许私有证书
event.preventDefault() callback(true) }); // 忽略证书相关错误
app.commandLine.appendSwitch('ignore-certificate-errors')
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() })
|