/
main.js
59 lines (53 loc) · 1.57 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
const electron = require('electron');
const nativeImage = require('electron').nativeImage;
const Tray = electron.Tray;
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const Menu = electron.Menu;
let mainWindow = null;
// 若所有窗口关闭,则退出
app.on('window-all-closed', () => {
if(process.platform != 'darwin') {
app.quit();
}
});
var appIcon = null;
app.on('ready', () => {
appIcon = new Tray(__dirname + '/static/pikachu.png');
var contextMenu = Menu.buildFromTemplate([
{ label: '打开', click() {
mainWindow.show();
}},
{ label: '最大化', click() {
mainWindow.maximize();
}},
{ label: '最小化', click() {
mainWindow.minimize();
}},
{ label: '关闭', click() {
mainWindow.close();
}}
]);
appIcon.setToolTip('Windows 资源管理器');
appIcon.setContextMenu(contextMenu);
// 创建浏览器窗口
mainWindow = new BrowserWindow({
width: 1366,
height: 768,
minHeight: 768,
maxHeight: 768,
title: "资源管理器",
center: true,
resizable: false,
skipTaskbar: true,
icon: nativeImage.createFromPath(__dirname + '/static/pikachu.png')
});
// 加载应用的index.html
mainWindow.loadURL('file://' + __dirname + '/index.html');
// 打开开发工具
// mainWindow.openDevTools();
// 当window被关闭,触发下面事件
mainWindow.on('closed', () => {
mainWindow = null;
});
});