forked from AntSwordProject/antSword
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
105 lines (96 loc) · 2.62 KB
/
app.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* 中国蚁剑::主程序入口
* 更新:2016/05/02
* 作者:蚁逅 <https://github.com/antoor>
*/
'use strict';
const path = require('path');
const electron = require('electron');
const {
app,
protocol,
BrowserWindow
} = require('electron');
// 注册为标准 scheme, 默认情况下web storage apis (localStorage, sessionStorage, webSQL,
// indexedDB, cookies) 被禁止访问非标准schemes
protocol.registerStandardSchemes(['ant-views', 'ant-static', 'ant-src']);
app.once('ready', () => {
/**
* 注册静态资源protocol
* - 可通过注册的协议访问资源文件,如ant-static://libs/jquery.jquery.js
*/
[
[
'static', '/static/', 13
],
[
'views', '/views/', 12
], //- 通过访问访问ant-views来访问views 文件
['src', '/source/', 10] //- 通过访问访问ant-src来访问source 文件
].map((_) => {
protocol.registerFileProtocol(`ant-${_[0]}`, (req, cb) => {
if (req.url.endsWith('/')) {
req.url = req
.url
.substr(0, req.url.length - 1);
}
cb({
path: path.normalize(path.join(__dirname, _[1], req.url.substr(_[2])))
});
});
});
// 初始化窗口
let mainWindow = new BrowserWindow({
width: 1040,
height: 699,
minWidth: 888,
minHeight: 555,
title: 'AntSword',
webPreferences: {
webgl: false,
javascript: true,
nodeIntegration: true, // 开启 nodejs 支持
// contextIsolation: false, // 关闭上下文隔离 webSecurity: false,
// allowRunningInsecureContent: true, sandbox: false,
}
});
// 加载views
mainWindow.loadURL('ant-views://front/index.html');
// 调整部分UI
const reloadUI = mainWindow
.webContents
.send
.bind(mainWindow.webContents, 'reloadui', true);
// 窗口事件监听
mainWindow.on('close', (event) => {
event.preventDefault();
app.exit(0);
}).on('minimize', (event) => {
event.preventDefault();
if (process.platform == 'darwin') {
app.hide();
} else if (process.platform == 'linux') {
return;
} else {
mainWindow.hide();
}
})
.on('resize', reloadUI)
.on('maximize', reloadUI)
.on('unmaximize', reloadUI)
.on('enter-full-screen', reloadUI)
.on('leave-full-screen', reloadUI);
// 打开调试控制台 mainWindow.webContents.openDevTools();
electron.Logger = require('./modules/logger')(mainWindow);
// 初始化模块
[
'menubar',
'request',
'database',
'cache',
'update',
'plugStore'
].map((_) => {
new(require(`./modules/${_}`))(electron, app, mainWindow);
});
});