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

2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
  1. const {app, BrowserWindow, dialog, protocol, ipcMain} = 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. // 启动应用时自动启动监控平台接口服务
  19. // const child_process = require('child_process')
  20. // if (global.worker !== 'start') {
  21. // let worker = child_process.fork('D:\\linyun\\workspace\\front-monitor-api\\src\\app.js',[])
  22. // global.worker = 'start'
  23. // }
  24. const gotTheLock = app.requestSingleInstanceLock();
  25. console.log('gotTheLock',gotTheLock)
  26. // if (!gotTheLock) {
  27. // dialog.showMessageBox(win,{
  28. // type: "warning",
  29. // title: "提示",
  30. // message: "您已打开指挥系统!请勿重复操作",
  31. // }).then(() => {
  32. // app.exit()
  33. // })
  34. // return;
  35. // }
  36. protocol.registerFileProtocol('file', (request, callback) => {
  37. const pathname = decodeURI(request.url.replace('file:///', ''));
  38. callback(pathname);
  39. });
  40. sinceTimeEnd('whenReady')
  41. handleIPC();
  42. sinceTimeEnd('handleIPC')
  43. createMainWindow();
  44. sinceTimeEnd('createWindowEnd')
  45. app.on('browser-window-created', (event, window) => {
  46. setTimeout(() => {
  47. if (window[MANUAL_CREATED_FLAG]) { // allow safe created manually
  48. return
  49. }
  50. dialog.showMessageBox({
  51. type: "warning",
  52. title: "提示",
  53. message: "新开窗口必须使用内置openWindow接口",
  54. })
  55. try {
  56. window.destroy()
  57. } catch (e) {
  58. console.error(e)
  59. }
  60. }, 100)
  61. })
  62. app.on('activate', () => {
  63. // On macOS it's common to re-create a window in the app when the
  64. // dock icon is clicked and there are no other windows open.
  65. if (BrowserWindow.getAllWindows().length === 0) {
  66. createMainWindow()
  67. }
  68. })
  69. })
  70. // Quit when all windows are closed, except on macOS. There, it's common
  71. // for applications and their menu bar to stay active until the user quits
  72. // explicitly with Cmd + Q.
  73. app.on('window-all-closed', function () {
  74. if (process.platform !== 'darwin') app.quit()
  75. })