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
65
66
67
68
69
70
71
72
73
74
const is = require('is-type-of');
const { BrowserWindow, Menu } = require('electron');
const Conf = require('../../config/cache');
const Ps = require('../../ps');
const EEMainWindow = Symbol('Ee#electron#mainWindow');
 
const Window = {
 
  /**
   * 获取 mainWindow
   */
  getMainWindow() {
    if (!this[EEMainWindow]) {
      this[EEMainWindow] = this.createMainWindow();
    }
 
    return this[EEMainWindow] || null;
  },
 
  /**
   * 创建应用主窗口
   */
  createMainWindow() {
 
    // todo
    // const protocolName = 'eefile';
    // protocol.registerFileProtocol(protocolName, (request, callback) => {
    //   const url = request.url.substring(protocolName.length + 3);
    //   console.log('[ee-core] [lib/eeApp] registerFileProtocol ----url: ', url);
    //   callback({ path: path.normalize(decodeURIComponent(url)) })
    // });
 
    const config = Conf.all();
    const win = new BrowserWindow(config.windowsOption);
    this[EEMainWindow] = win;
 
    // 菜单显示/隐藏
    if (config.openAppMenu === 'dev-show' && Ps.isProd()) {
      Menu.setApplicationMenu(null);
    } else if (config.openAppMenu === false) {
      Menu.setApplicationMenu(null);
    } else {
      // nothing 
    }
 
    // DevTools
    if (is.object(config.openDevTools)) {
      win.webContents.openDevTools(config.openDevTools);
    } else if (config.openDevTools === true) {
      win.webContents.openDevTools({
        mode: 'undocked'
      });
    } else {
      //
    }
    
    return win;
  },
 
  /**
   * 还原窗口
   */
  restoreMainWindow() {
    if (this[EEMainWindow]) {
      if (this[EEMainWindow].isMinimized()) {
        this[EEMainWindow].restore();
      }
      this[EEMainWindow].show();
      this[EEMainWindow].focus();
    }
  }
};
 
module.exports = Window;