forked from Whatever-If-It-Is-Cool/Cool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
84 lines (74 loc) · 2.8 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
// --- 主要依赖 ---
// 载入electron模块
const electron = require("electron");
// 创建应用程序对象
const app = electron.app;
// 创建一个浏览器窗口,主要用来加载HTML页面
const BrowserWindow = electron.BrowserWindow;
// --- 其他依赖 ---
const {
ipcMain
} = require('electron');
// --- 窗口 ---
// 声明一个BrowserWindow对象实例
let mainWindow;
var settingsWindow = null;
//定义一个创建浏览器窗口的方法
function createWindow() {
// 创建一个浏览器窗口对象,并指定窗口的大小
// 1024×768 合理的窗口大小
mainWindow = new BrowserWindow({
width: 1920,
height: 1080
});
// 通过浏览器窗口对象加载index.html文件,同时也是可以加载一个互联网地址的
// 同时也可以简化成:mainWindow.loadURL('./index.html');
mainWindow.loadURL('file://' + __dirname + '/src/windows/main/main.html');
// mainWindow.loadURL('http://www.sushithedog.com');
// 打开程序的同时打开开发者工具
mainWindow.openDevTools();
// 监听浏览器窗口对象是否关闭,关闭之后直接将mainWindow指向空引用,也就是回收对象内存空间
mainWindow.on("closed", function () {
mainWindow = null;
});
}
ipcMain.on('asynchronous-message', (event, arg) => {
event.sender.send('asynchronous-reply', 'pong')
});
ipcMain.on('switchto', (event, arg) => {
mainWindow.loadURL('file://' + __dirname + '/src/windows/' + arg + '.html');
});
ipcMain.on('processwindow', (event, arg) => {
if (settingsWindow) {
return;
}
settingsWindow = new BrowserWindow({
height: 1920,
width: 1080
});
settingsWindow.loadURL('file://' + __dirname + '/src/windows/start/start.html');
settingsWindow.on('closed', function () {
console.log('closed');
settingsWindow = null;
});
});
ipcMain.on('synchronous-message', (event, arg) => {
console.log(arg); // prints "ping"
event.returnValue = 'pong';
});
// 监听应用程序对象是否初始化完成,初始化完成之后即可创建浏览器窗口
app.on("ready", createWindow);
// 监听应用程序对象中的所有浏览器窗口对象是否全部被关闭,如果全部被关闭,则退出整个应用程序。该
app.on("window-all-closed", function () {
// 判断当前操作系统是否是window系统,因为这个事件只作用在window系统中
if (process.platform != "darwin") {
// 退出整个应用程序
app.quit();
}
});
// 监听应用程序图标被通过点或者没有任何浏览器窗口显示在桌面上,那我们应该重新创建并打开浏览器窗口,避免Mac OS X系统回收或者销毁浏览器窗口
app.on("activate", function () {
if (mainWindow === null) {
createWindow();
}
});