-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
77 lines (64 loc) · 2.41 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
/*
MultiSite Latency Tool
Copyright (C) 2024 Snake Konginchrist
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// 引入Electron模块
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const measureLatency = require('./src/latency');
const getGeoLocation = require('./src/geoip');
// 创建窗口的函数
function createWindow() {
// 创建浏览器窗口
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
// nodeIntegration: true, // 允许在渲染进程中使用Node.js
// contextIsolation: false, // 在这个示例中关闭上下文隔离以便简化代码
preload: path.join(__dirname, 'preload.js')
}
});
// 打开开发者工具
// mainWindow.webContents.openDevTools();
// 加载index.html
mainWindow.loadFile('index.html');
}
// 当Electron应用完成时初始化
// app.whenReady().then(createWindow);
// 初始化并创建窗口
app.on('ready', createWindow);
// 所有窗口关闭时退出应用
app.on('window-all-closed', () => {
// 在macOS上,除非用户使用Cmd + Q确定地退出,
// 否则绝大部分应用及其菜单栏会保持激活
if (process.platform !== 'darwin') {
app.quit();
}
});
// macOS用户在点击dock图标并且没有其他窗口打开时,
// 通常在应用程序中重新创建一个窗口
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
ipcMain.handle('measure-latency', async (event, urls) => {
const results = [];
for (const url of urls) {
const latency = await measureLatency(url);
const { ip, location } = await getGeoLocation(url);
results.push({ url, latency, ip, location });
}
return results;
});