Browse Source

win7技术验证版,已通过

CrazyIter_Bin 3 months ago
parent
commit
4afeb1e477

+ 3 - 1
TEAMModelOS.Extension/IES.Exam/IES.ExamClient/constants.js

@@ -6,7 +6,8 @@ const { app } = require('electron');
 const cert = fs.readFileSync('server\\Configs\\cer\\cert.pem');
 const agent = new https.Agent({
     ca: cert,
-    rejectUnauthorized: true, // 启用证书验证
+    rejectUnauthorized: true,
+   // secureProtocol: 'TLSv1_2_method', // 强制使用 TLS 1.2
 });
 
 let serverPath;
@@ -17,6 +18,7 @@ if (app.isPackaged) {
 }
 
 const baseUrl = 'https://exam.habook.local:8888';
+//const baseUrl = 'http://exam.habook.local:9999';
 const remoteVersionsUrl = 'https://teammodelos.blob.core.chinacloudapi.cn/0-public/exam-server/versions.json';
 const remoteZipBaseUrl = 'https://teammodelos.blob.core.chinacloudapi.cn/0-public/exam-server';
 

+ 8 - 5
TEAMModelOS.Extension/IES.Exam/IES.ExamClient/main.js

@@ -3,12 +3,14 @@ const serverManager = require('./serverManager');
 const menuManager = require('./menuManager');
 const updateManager = require('./updateManager');
 const constants = require('./constants');
-
+//app.disableHardwareAcceleration(); //使用windows7 ,或者虚拟机的时候 需要验证 禁用 GPU 加速
+//app.commandLine.appendSwitch('ignore-certificate-errors')
 let win = null;
 
 // 创建 Electron 窗口的函数
 const createWindow = async () => {
     try {
+       
         const isServerRunning = await serverManager.checkServerHealth();
         if (!isServerRunning) {
             await serverManager.startServer(); // 启动 Web API
@@ -21,6 +23,10 @@ const createWindow = async () => {
                 contextIsolation: false,
             },
         });
+        //win.webContents.session.setCertificateVerifyProc((request, callback) => {
+        //    // 始终返回 0 表示验证通过
+        //    callback(0);
+        //});
         win.maximize();
         win.loadURL(constants.baseUrl, {
             agent: constants.agent
@@ -38,11 +44,8 @@ const checkForUpdatesHandler = () => {
 };
 // 当 Electron 应用准备好时创建窗口
 app.whenReady().then(() => {
+    process.env.NODE_OPTIONS = '--tls-min-v1.2';
     createWindow();
-    // menuManager.createMenu(win);
-
-  
-
     // 创建菜单并传递回调函数
     menuManager.createMenu(checkForUpdatesHandler);
 

+ 71 - 6
TEAMModelOS.Extension/IES.Exam/IES.ExamClient/menuManager.js

@@ -1,4 +1,4 @@
-const { Menu, dialog } = require('electron');
+const { Menu, dialog, BrowserWindow, session } = require('electron');
 //const updateManager = require('./updateManager');
 const constants = require('./constants');
 const utils = require('./utils');
@@ -18,9 +18,34 @@ const createMenu = (checkForUpdatesCallback) => {
         {
             label: '主页',
             click: () => {
-               win.loadURL('https://www.baidu.com');
+                const win = BrowserWindow.getFocusedWindow(); // 获取当前获得焦点的窗口
+                console.log('win', win);
+                if (win) {
+                    win.loadURL(constants.baseUrl, {
+                        agent: constants.agent
+                    });
+                } else {
+                    console.warn('没有获得焦点的窗口');
+                }
             }
-},
+        },
+        {
+            label: '设置',
+            submenu: [
+                {
+                    label: '清理缓存',
+                    click: () => {
+                        clearCache();
+                    }
+                },
+                {
+                    label: '调试模式',
+                    click: () => {
+                        openDevTools();
+                    }
+                }
+            ]
+        },
         { label: '帮助' },
         {
             label: '版本',
@@ -28,7 +53,6 @@ const createMenu = (checkForUpdatesCallback) => {
                 {
                     label: '检查更新服务端',
                     click: () => {
-                        //updateManager.checkForUpdates(win);
                         if (typeof checkForUpdatesCallback === 'function') {
                             checkForUpdatesCallback(); // 确保回调函数是函数
                         } else {
@@ -52,7 +76,49 @@ const createMenu = (checkForUpdatesCallback) => {
     const menu = Menu.buildFromTemplate(template);
     Menu.setApplicationMenu(menu);
 };
-
+// 开启调试模式
+const openDevTools = () => {
+    const win = BrowserWindow.getFocusedWindow(); // 获取当前获得焦点的窗口
+    if (win) {
+        win.webContents.openDevTools(); // 打开开发者工具
+    } else {
+        console.warn('没有获得焦点的窗口');
+    }
+};
+// 清理缓存
+const clearCache = () => {
+    const win = BrowserWindow.getFocusedWindow(); // 获取当前获得焦点的窗口
+   // console.log('win', win);
+    if (win) {
+        session.defaultSession.clearStorageData({
+            storages: ['cookies', 'localstorage', 'shadercache', 'serviceworkers', 'cachestorage'],
+            quotas: ['temporary', 'persistent', 'syncable'],
+        }, () => {
+            console.log('缓存和其他存储数据已清理');
+            console.log('缓存已清理');
+            dialog.showMessageBox(win, {
+                type: 'info',
+                title: '清理缓存',
+                message: '缓存已清理',
+                buttons: ['确定']
+            });
+        });
+        // 清理缓存
+        //win.webContents.on('did-finish-load', () => {
+        //    win.webContents.clearCache();
+        //    console.log('缓存已清理');
+        //});
+        // 清理默认会话的缓存
+        session.defaultSession.clearCache(() => {
+            console.log('缓存已清理');
+        });
+        win.loadURL(constants.baseUrl, {
+            agent: constants.agent
+        });
+    } else {
+        console.warn('没有获得焦点的窗口');
+    }
+};
 // 获取本地版本号
 const getLocalVersion = () => {
     const appSettingsPath = path.join(constants.serverPath, 'server', 'appsettings.json');
@@ -66,7 +132,6 @@ const getLocalVersion = () => {
         return '1.250101.01';
     }
 };
-
 module.exports = {
     createMenu
 };

+ 1 - 1
TEAMModelOS.Extension/IES.Exam/IES.ExamClient/package.json

@@ -13,7 +13,7 @@
   "author": "",
   "license": "MIT",
   "devDependencies": {
-    "electron": "20.3.12"
+    "electron": "21.4.4"
   },
   "build": {
     "appId": "exam.habook.local",

+ 3 - 3
TEAMModelOS.Extension/IES.Exam/IES.ExamClient/serverManager.js

@@ -32,14 +32,14 @@ const startServer = () => {
         const checkHealth = async () => {
             try {
                 const response = await axios.get(`${constants.baseUrl}/index/health`, {
-                    httpsAgent: constants.agent
+                httpsAgent: constants.agent
                 });
                 if (response.status === 200) {
                     console.log('Server is up and running!');
                     resolve();
                 }
             } catch (error) {
-                console.log('Waiting for server to start...');
+                console.log('Waiting for server to start...', error);
                 setTimeout(checkHealth, 1000); // 每隔 1 秒检查一次
             }
         };
@@ -58,7 +58,7 @@ const checkServerHealth = async () => {
             return true;
         }
     } catch (error) {
-        console.log('Server is not running yet.');
+        console.log('Server is not running yet.', error);
         return false;
     }
 };

File diff suppressed because it is too large
+ 544 - 544
TEAMModelOS.Extension/IES.Exam/IES.ExamClient/yarn.lock


+ 12 - 1
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/Program.cs

@@ -10,6 +10,7 @@ using System.Text.Encodings.Web;
 using System.Text.Unicode;
 using static System.Net.Mime.MediaTypeNames;
 using System.Diagnostics;
+using System.Security.Authentication;
 namespace IES.ExamServer.Server
 {
     public class Program
@@ -20,7 +21,17 @@ namespace IES.ExamServer.Server
             var builder = WebApplication.CreateBuilder(args);
 
             // Add services to the container.
-
+            builder.WebHost.ConfigureKestrel(serverOptions =>
+            {
+                // ÅäÖÃÖ§³ÖµÄ SSL/TLS ЭÒé°æ±¾
+                serverOptions.ConfigureHttpsDefaults(httpsOptions =>
+                {
+                    httpsOptions.SslProtocols = SslProtocols.Tls |
+                                              SslProtocols.Tls11 |
+                                              SslProtocols.Tls12 |
+                                              SslProtocols.Tls13;
+                });
+            });
             string path = $"{builder.Environment.ContentRootPath}/Configs";
             // Add services to the container.
             builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

+ 3 - 0
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/appsettings.json

@@ -22,6 +22,9 @@
           "Path": "Configs/cer/cert.pem",
           "KeyPath": "Configs/cer/key.pem"
         }
+      },
+      "Http": {
+        "Url": "http://*:9999"
       }
     }
   },