|
@@ -1,18 +1,23 @@
|
|
-const { app, BrowserWindow } = require('electron');
|
|
|
|
|
|
+const { app, BrowserWindow, Tray, Menu } = require('electron');
|
|
|
|
+const path = require('path');
|
|
const serverManager = require('./serverManager');
|
|
const serverManager = require('./serverManager');
|
|
const menuManager = require('./menuManager');
|
|
const menuManager = require('./menuManager');
|
|
const updateManager = require('./updateManager');
|
|
const updateManager = require('./updateManager');
|
|
const constants = require('./constants');
|
|
const constants = require('./constants');
|
|
|
|
+const { getNetworkInterfaces } = require('./networkService');
|
|
//app.disableHardwareAcceleration(); //使用windows7 ,或者虚拟机的时候 需要验证 禁用 GPU 加速
|
|
//app.disableHardwareAcceleration(); //使用windows7 ,或者虚拟机的时候 需要验证 禁用 GPU 加速
|
|
//app.commandLine.appendSwitch('ignore-certificate-errors')
|
|
//app.commandLine.appendSwitch('ignore-certificate-errors')
|
|
let win = null;
|
|
let win = null;
|
|
-
|
|
|
|
|
|
+let tray = null;
|
|
|
|
+app.isQuitting = false; // 添加标志位
|
|
// 创建 Electron 窗口的函数
|
|
// 创建 Electron 窗口的函数
|
|
const createWindow = async () => {
|
|
const createWindow = async () => {
|
|
try {
|
|
try {
|
|
-
|
|
|
|
|
|
+ const networks = getNetworkInterfaces();
|
|
|
|
+ console.log('Available networks:', networks);
|
|
const isServerRunning = await serverManager.checkServerHealth();
|
|
const isServerRunning = await serverManager.checkServerHealth();
|
|
if (!isServerRunning) {
|
|
if (!isServerRunning) {
|
|
|
|
+ console.log('Server is not running, starting it......................................');
|
|
await serverManager.startServer(); // 启动 Web API
|
|
await serverManager.startServer(); // 启动 Web API
|
|
}
|
|
}
|
|
win = new BrowserWindow({
|
|
win = new BrowserWindow({
|
|
@@ -26,16 +31,65 @@ const createWindow = async () => {
|
|
//win.webContents.session.setCertificateVerifyProc((request, callback) => {
|
|
//win.webContents.session.setCertificateVerifyProc((request, callback) => {
|
|
// // 始终返回 0 表示验证通过
|
|
// // 始终返回 0 表示验证通过
|
|
// callback(0);
|
|
// callback(0);
|
|
- //});
|
|
|
|
|
|
+ //});///login/admin
|
|
win.maximize();
|
|
win.maximize();
|
|
- win.loadURL(constants.baseUrl, {
|
|
|
|
|
|
+ win.loadURL(`${constants.baseUrl}/login/admin`, {
|
|
agent: constants.agent
|
|
agent: constants.agent
|
|
});
|
|
});
|
|
|
|
+ // 监听窗口关闭事件,隐藏窗口而不是关闭
|
|
|
|
+ win.on('close', (event) => {
|
|
|
|
+ if (!app.isQuitting) {
|
|
|
|
+ event.preventDefault();
|
|
|
|
+ win.hide();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.error('Error starting server or loading window:', error);
|
|
console.error('Error starting server or loading window:', error);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const createTray = () => {
|
|
|
|
+ const iconPath = path.join(__dirname, 'logo.ico'); // 你的托盘图标路径
|
|
|
|
+ tray = new Tray(iconPath);
|
|
|
|
+
|
|
|
|
+ const contextMenu = Menu.buildFromTemplate([
|
|
|
|
+ {
|
|
|
|
+ label: '显示',
|
|
|
|
+ click: () => {
|
|
|
|
+ if (win) {
|
|
|
|
+ win.show();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ label: '退出',
|
|
|
|
+ click: () => {
|
|
|
|
+ app.isQuitting = true;
|
|
|
|
+ app.quit();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ tray.setToolTip('评测教师端');
|
|
|
|
+ tray.setContextMenu(contextMenu);
|
|
|
|
+
|
|
|
|
+ // 监听双击托盘图标事件,恢复窗口
|
|
|
|
+ tray.on('double-click', () => {
|
|
|
|
+ if (win) {
|
|
|
|
+ if (win.isVisible()) {
|
|
|
|
+ win.focus(); // 如果窗口已经显示,则聚焦窗口
|
|
|
|
+ } else {
|
|
|
|
+ win.show(); // 如果窗口隐藏,则显示窗口
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
// 定义回调函数
|
|
// 定义回调函数
|
|
const checkForUpdatesHandler = () => {
|
|
const checkForUpdatesHandler = () => {
|
|
updateManager.checkForUpdates(win, () => {
|
|
updateManager.checkForUpdates(win, () => {
|
|
@@ -46,6 +100,7 @@ const checkForUpdatesHandler = () => {
|
|
app.whenReady().then(() => {
|
|
app.whenReady().then(() => {
|
|
process.env.NODE_OPTIONS = '--tls-min-v1.2';
|
|
process.env.NODE_OPTIONS = '--tls-min-v1.2';
|
|
createWindow();
|
|
createWindow();
|
|
|
|
+ createTray();
|
|
// 创建菜单并传递回调函数
|
|
// 创建菜单并传递回调函数
|
|
menuManager.createMenu(checkForUpdatesHandler);
|
|
menuManager.createMenu(checkForUpdatesHandler);
|
|
|
|
|
|
@@ -57,13 +112,19 @@ app.whenReady().then(() => {
|
|
|
|
|
|
// 监听 before-quit 事件,关闭 IES.ExamServer.exe 进程
|
|
// 监听 before-quit 事件,关闭 IES.ExamServer.exe 进程
|
|
app.on('before-quit', async (event) => {
|
|
app.on('before-quit', async (event) => {
|
|
|
|
+ if (app.isQuitting) {
|
|
|
|
+ return; // 如果已经在退出流程中,则直接返回
|
|
|
|
+ }
|
|
|
|
+ app.isQuitting = true; // 标记正在退出
|
|
event.preventDefault(); // 阻止默认的退出行为
|
|
event.preventDefault(); // 阻止默认的退出行为
|
|
- await serverManager.shutdownServer();
|
|
|
|
- //app.quit(); // 关闭 Electron 应用程序
|
|
|
|
|
|
+ await serverManager.shutdownServer(); // 关闭服务器
|
|
|
|
+ app.quit(); // 触发退出流程
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
// 当所有窗口关闭时退出应用(macOS 除外)
|
|
// 当所有窗口关闭时退出应用(macOS 除外)
|
|
app.on('window-all-closed', function () {
|
|
app.on('window-all-closed', function () {
|
|
- app.quit();
|
|
|
|
|
|
+ if (process.platform !== 'darwin') {
|
|
|
|
+ app.quit();
|
|
|
|
+ }
|
|
});
|
|
});
|