|
@@ -1,57 +1,96 @@
|
|
|
-const { app, BrowserWindow, Menu } = require('electron/main');
|
|
|
-const { spawn } = require('child_process');
|
|
|
-const net = require('net');
|
|
|
-
|
|
|
-// 获取网卡信息
|
|
|
-// npm start 启动命令
|
|
|
-const platform = process.platform;
|
|
|
-if (platform === 'win32') {
|
|
|
- console.log('Running on Windows');
|
|
|
-} else if (platform === 'linux') {
|
|
|
- console.log('Running on Linux');
|
|
|
-} else if (platform === 'darwin') {
|
|
|
- console.log('Running on macOS');
|
|
|
-} else {
|
|
|
- console.log('Running on an unknown platform');
|
|
|
-}
|
|
|
+const { app, BrowserWindow } = require('electron');
|
|
|
+const path = require('path');
|
|
|
+const https = require('https');
|
|
|
+const fs = require('fs');
|
|
|
+const { exec } = require('child_process');
|
|
|
+const axios = require('axios');
|
|
|
+let mainWindow;
|
|
|
+let netProcess;
|
|
|
+let baseUrl = 'https://exam.habook.local:8888';
|
|
|
+const cert = fs.readFileSync('cert.pem');
|
|
|
+const agent = new https.Agent({
|
|
|
+ ca: cert
|
|
|
+});
|
|
|
+function createWindow() {
|
|
|
+ mainWindow = new BrowserWindow({
|
|
|
+ width: 1200,
|
|
|
+ height: 800,
|
|
|
+ webPreferences: {
|
|
|
+ nodeIntegration: true,
|
|
|
+ contextIsolation: false,
|
|
|
+ },
|
|
|
+ show: false
|
|
|
+ });
|
|
|
|
|
|
+ // 加载 .NET 6 项目托管的 Vue 页面
|
|
|
+ // mainWindow.loadURL('https://exam.habook.local:8888/');
|
|
|
|
|
|
-const createWindow = async () => {
|
|
|
- try {
|
|
|
- //await startDotnet();
|
|
|
- const win = new BrowserWindow({
|
|
|
- width: 800,
|
|
|
- height: 600
|
|
|
- //webPreferences: {
|
|
|
- // nodeIntegration: true,
|
|
|
- // contextIsolation: false,
|
|
|
- //},
|
|
|
- });
|
|
|
- // 忽略证书错误
|
|
|
- //win.webContents.session.setCertificateVerifyProc((request, callback) => {
|
|
|
- // callback(0); // 允许所有证书
|
|
|
- //});
|
|
|
- win.maximize();
|
|
|
- win.loadURL('https://exam.habook.local:8888');
|
|
|
- } catch (error) {
|
|
|
- console.error('Error starting dotnet or loading window:', error);
|
|
|
- }
|
|
|
-};
|
|
|
+ mainWindow.on('closed', () => {
|
|
|
+ mainWindow = null;
|
|
|
+ // 关闭 .NET 6 进程
|
|
|
+ if (netProcess) {
|
|
|
+ netProcess.kill();
|
|
|
+ }
|
|
|
|
|
|
-// Menu.setApplicationMenu(null);
|
|
|
+ if (process.platform !== 'darwin') {
|
|
|
+ app.quit();
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
-app.whenReady().then(() => {
|
|
|
+app.on('ready', () => {
|
|
|
+ https.globalAgent = agent;
|
|
|
+ const exePath = path.join(__dirname, 'server', 'IES.ExamServer.exe');
|
|
|
+ // 使用绝对路径启动 .NET 6 的 exe 文件
|
|
|
+ console.log('exePath:', exePath);
|
|
|
+ netProcess = exec(`"${exePath}"`, { cwd: path.dirname(exePath) }, (error, stdout, stderr) => {
|
|
|
+ if (error) {
|
|
|
+ console.error(`Process error: ${error}`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log(`stdout: ${stdout}`);
|
|
|
+ console.error(`stderr: ${stderr}`);
|
|
|
+ });
|
|
|
+ console.log(baseUrl + "/index/health");
|
|
|
createWindow();
|
|
|
+ // 检测 Web API 是否启动完成
|
|
|
+ const checkApiReady = async () => {
|
|
|
+ try {
|
|
|
+ // 向 Web API 发送请求
|
|
|
|
|
|
- app.on('activate', () => {
|
|
|
- if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
- createWindow();
|
|
|
+ const response = await axios.get(baseUrl + "/index/health", {
|
|
|
+ //httpsAgent: new (require('https').Agent)({
|
|
|
+ // rejectUnauthorized: false // 禁用 SSL 验证
|
|
|
+ //})
|
|
|
+ httpsAgent: agent
|
|
|
+ })
|
|
|
+ if (response.status === 200) {
|
|
|
+ console.log('Web API is ok...');
|
|
|
+ mainWindow.loadURL(baseUrl); // 加载 Web API 的 URL
|
|
|
+ mainWindow.show(); // 显示窗口
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log('Web API starting...');
|
|
|
+ // 如果请求失败,继续等待
|
|
|
+ setTimeout(checkApiReady, 1000); // 每隔 1 秒重试一次
|
|
|
}
|
|
|
- });
|
|
|
+ };
|
|
|
+ checkApiReady();
|
|
|
});
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
+ // 关闭 .NET 6 进程
|
|
|
+ if (netProcess) {
|
|
|
+ netProcess.kill();
|
|
|
+ }
|
|
|
+
|
|
|
if (process.platform !== 'darwin') {
|
|
|
app.quit();
|
|
|
}
|
|
|
+});
|
|
|
+
|
|
|
+app.on('activate', () => {
|
|
|
+ if (mainWindow === null) {
|
|
|
+ createWindow();
|
|
|
+ }
|
|
|
});
|