15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const { app } = require('electron');
const EE = require('../../ee');
const Log = require('../../log');
const Electron = require('../index');
const UtilsIs = require('../../utils/is');
const Cross = require('../../cross');
const Window = require('../window');
 
/**
 * CoreElectronApp (框架封装的electron app对象)
 */
const CoreElectronApp = {
 
  /**
   * 创建electron应用
   */
  async create() {
    const { CoreApp } = EE;
 
    const gotTheLock = app.requestSingleInstanceLock();
    if (!gotTheLock) {
      app.quit();
    }
 
    app.whenReady().then(() => {
      CoreApp.createWindow();
    })
 
    // 显示首次打开的窗口
    app.on('second-instance', () => {
      Log.coreLogger.info('[ee-core] [lib/eeApp] second-instance');
      Window.restoreMainWindow();
    });
 
    app.on('window-all-closed', () => {
      if (!UtilsIs.macOS()) {
        Log.coreLogger.info('[ee-core] [lib/eeApp] window-all-closed quit');
        CoreApp.appQuit();
      }
    })
 
    app.on('before-quit', () => {
      Electron.extra.closeWindow = true;
 
      // kill cross services
      Cross.killAll();
    })
 
    if (CoreApp.config.hardGpu.enable == false) {
      app.disableHardwareAcceleration();
    }
 
    return app;
  },
 
  /**
   * 退出app
   */
  quit() {
    app.quit();
  }
}
 
module.exports = CoreElectronApp;