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.

96 lines
3.6 KiB

2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
4 years ago
4 years ago
2 years ago
2 years ago
4 years ago
2 years ago
  1. const {app, BrowserWindow, dialog, protocol, session} = require('electron')
  2. const {create: createMainWindow} = require('./windows/main')
  3. const {MANUAL_CREATED_FLAG,} = require('./constant')
  4. const handleIPC = require('./ipc')
  5. // const {sinceTime,sinceTimeEnd} = require('./SinceTimeTool')
  6. // sinceTime()
  7. const store = require('./windows/lib/store');
  8. const isFirstInstall = store.get("firstInstall");
  9. if (isFirstInstall) {
  10. console.log('<========清除历史缓存=====>')
  11. app.commandLine.appendSwitch("--disable-http-cache");
  12. store.set("firstInstall", false);
  13. }
  14. // 关闭GPU加速
  15. // app.disableHardwareAcceleration()
  16. // app.allowRendererProcessReuse = true
  17. app.whenReady().then(() => {
  18. const filter = {urls: ['http://127.0.0.1:5500/*']};
  19. session.defaultSession.webRequest.onHeadersReceived(filter, (details,callback) => {
  20. if(details.responseHeaders && details.responseHeaders['Set-Cookie']){
  21. for(let i = 0;i < details.responseHeaders['Set-Cookie'].length;i++) details.responseHeaders['Set-Cookie'][i] += ";SameSite=None;Secure";
  22. }
  23. callback({ responseHeaders: details.responseHeaders});
  24. })
  25. app.commandLine.appendSwitch('disable-features','BlockInsecurePrivateNetworkRequests')
  26. // 启动应用时自动启动监控平台接口服务
  27. // const child_process = require('child_process')
  28. // if (global.worker !== 'start') {
  29. // let worker = child_process.fork('D:\\linyun\\workspace\\front-monitor-api\\src\\app.js',[])
  30. // global.worker = 'start'
  31. // }
  32. const gotTheLock = app.requestSingleInstanceLock();
  33. console.log('gotTheLock',gotTheLock)
  34. // if (!gotTheLock) {
  35. // dialog.showMessageBox(win,{
  36. // type: "warning",
  37. // title: "提示",
  38. // message: "您已打开指挥系统!请勿重复操作",
  39. // }).then(() => {
  40. // app.exit()
  41. // })
  42. // return;
  43. // }
  44. protocol.registerFileProtocol('file', (request, callback) => {
  45. const pathname = decodeURI(request.url.replace('file:///', ''));
  46. callback(pathname);
  47. });
  48. // sinceTimeEnd('whenReady')
  49. handleIPC();
  50. // sinceTimeEnd('handleIPC')
  51. createMainWindow();
  52. // sinceTimeEnd('createWindowEnd')
  53. // 兼容https非可信域
  54. app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
  55. //允许私有证书
  56. event.preventDefault()
  57. callback(true)
  58. });
  59. // 忽略证书相关错误
  60. app.commandLine.appendSwitch('ignore-certificate-errors')
  61. app.on('browser-window-created', (event, window) => {
  62. setTimeout(() => {
  63. if (window[MANUAL_CREATED_FLAG]) { // allow safe created manually
  64. return
  65. }
  66. dialog.showMessageBox({
  67. type: "warning",
  68. title: "提示",
  69. message: "新开窗口必须使用内置openWindow接口",
  70. })
  71. try {
  72. window.destroy()
  73. } catch (e) {
  74. console.error(e)
  75. }
  76. }, 100)
  77. })
  78. app.on('activate', () => {
  79. // On macOS it's common to re-create a window in the app when the
  80. // dock icon is clicked and there are no other windows open.
  81. if (BrowserWindow.getAllWindows().length === 0) {
  82. createMainWindow()
  83. }
  84. })
  85. })
  86. // Quit when all windows are closed, except on macOS. There, it's common
  87. // for applications and their menu bar to stay active until the user quits
  88. // explicitly with Cmd + Q.
  89. app.on('window-all-closed', function () {
  90. if (process.platform !== 'darwin') app.quit()
  91. })