forked from 2Quico/antSword
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
76 lines (65 loc) · 2.08 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
'use strict';
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
// 导入模块
const Menubar = require('./modules/menubar');
const Request = require('./modules/request');
const Database = require('./modules/database');
const Cache = require('./modules/cache');
// electron.crashReporter.start();
app
.on('window-all-closed', app.quit)
.on('ready', () => {
let mainWindow = new BrowserWindow({
width: 1040,
height: 699,
minWidth: 1040,
minHeight: 699,
webgl: false,
title: 'AntSword',
// autoHideMenuBar: true,
// transparent: false,
// frame: false
// resizable: false
});
mainWindow.loadURL(`file:\/\/${__dirname}/views/index.html`);
// 是否重新加载刷新UI
// 获取初始化窗口大小
let winSize = mainWindow.getSize();
const reloadUI = () => {
// 判断调整大小是否已经超过界限
// 判断标准:取调整后的长(宽)与之前的长(宽)绝对值,>= 10就提示调整,最后保存调整后的长宽值
let _winSize = mainWindow.getSize();
if (Math.abs(_winSize[0] - winSize[0]) < 10 && Math.abs(_winSize[1] - winSize[1]) < 10) {
return;
};
winSize = _winSize;
mainWindow.webContents.executeJavaScript(`
layer.confirm(
'窗口已经调整,是否重启应用刷新UI?',
{
title: '重启应用',
btn: ['好的','不必']
},
location.reload.bind(location)
);
`);
}
mainWindow
.on('closed', () => { mainWindow = null })
.on('resize', reloadUI)
.on('maximize', reloadUI)
.on('unmaximize', reloadUI)
.on('enter-full-screen', reloadUI)
.on('leave-full-screen', reloadUI);
// 打开调试控制台
// mainWindow.webContents.openDevTools();
new Menubar(electron, app, mainWindow);
// 监听Request请求
new Request(electron);
// 初始化数据库
new Database(electron);
// 初始化缓存模块
new Cache(electron);
});