-
Notifications
You must be signed in to change notification settings - Fork 149
/
main.js
113 lines (102 loc) · 3.1 KB
/
main.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
106
107
108
109
110
111
112
113
const { app, BrowserWindow, Menu } = require('electron');
const path = require('path');
const url = require('url');
const fs = require('fs');
let logo = path.join(__dirname, 'assets/img/logo.png');
let win = null;
let win_about = null;
let willClose = false;
function createWindow () {
win = new BrowserWindow({
width: 360,
// width: 1000,
height: 572,
// height: 700,
title: 'iView',
// y:200,
// x:20,
center: true,
resizable: false,
icon: logo,
titleBarStyle: 'hidden'
});
win.loadURL(url.format({
pathname: path.join(__dirname, 'app/index.html'),
protocol: 'file:',
slashes: true
}));
// 打开开发者工具。
// win.webContents.openDevTools();
// 当 window 被关闭,这个事件会被触发。
win.on('close', (event) => {
if (process.platform !== 'win32' && !willClose) {
win.hide();
event.preventDefault();
}
});
win.on('closed', () => {
win = null;
});
}
function createMenu (language) {
const template = [
{
label: app.getName(),
submenu: [
{
label: (language.lang==="zh"? "关于": "about")+' iView Cli',
click () {
if (win_about == null) {
win_about = new BrowserWindow({
width: 300,
height: 180,
title: (language.lang==="zh"? "关于": "about")+' iView',
center: true,
resizable: false,
icon: logo,
minimizable: false,
maximizable: false
});
win_about.loadURL(url.format({
pathname: path.join(__dirname, 'app/about.html'),
protocol: 'file:',
slashes: true
}));
win_about.on('closed', (e) => {
win_about = null;
});
}
}
},
{
role: 'quit',
label: (language.lang==="zh"? "退出": "Quit")
}
]
}
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}
app.on('ready', () => {
let _path = path.join(__dirname, './conf/lang.json');
let data = fs.readFileSync(_path);
let language = data?JSON.parse(data):{ lang: 'zh', message: 'EN' };
createWindow();
createMenu(language);
});
app.on('activate', () => {
if (win == null) {
createWindow();
} else {
win.show();
}
});
app.on('before-quit', function () {
willClose = true;
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});