2025-10-11 10:47:07 +08:00
|
|
|
// main.js
|
|
|
|
|
const { app, BrowserWindow, dialog, ipcMain } = require('electron'); // 1. 导入 ipcMain
|
|
|
|
|
const path = require('path');
|
2025-10-16 17:39:50 +08:00
|
|
|
// const cv = require('opencv4nodejs'); // 已移除视觉作弊相关
|
2025-10-11 10:47:07 +08:00
|
|
|
|
|
|
|
|
let mainWindow;
|
|
|
|
|
let switchCount = 0; // 在主进程中也维护一个计数器
|
|
|
|
|
const switchLimit = 3;
|
|
|
|
|
const warningLimit = 2;
|
|
|
|
|
|
2025-10-16 17:39:50 +08:00
|
|
|
// --- 已移除视觉作弊相关变量 ---
|
|
|
|
|
|
2025-10-11 10:47:07 +08:00
|
|
|
function createWindow () {
|
|
|
|
|
mainWindow = new BrowserWindow({
|
|
|
|
|
// --- 关键修改:设置为全屏无框 ---
|
|
|
|
|
fullscreen: true,
|
|
|
|
|
frame: false,
|
|
|
|
|
resizable: false,
|
|
|
|
|
webPreferences: {
|
|
|
|
|
nodeIntegration: false,
|
|
|
|
|
contextIsolation: true, // 2. 必须开启
|
|
|
|
|
enableRemoteModule: false,
|
|
|
|
|
preload: path.join(__dirname, 'preload.js') // 3. 关键:加载 preload 脚本
|
|
|
|
|
},
|
|
|
|
|
// --- 可选:设置图标 ---
|
|
|
|
|
// icon: path.join(__dirname, 'icon.png')
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mainWindow.loadFile('student_app_fullscreen.html');
|
|
|
|
|
|
|
|
|
|
// --- 关键修改:监听窗口失去焦点事件 ---
|
|
|
|
|
mainWindow.on('blur', () => {
|
|
|
|
|
switchCount++;
|
|
|
|
|
console.log(`窗口失去焦点,切屏次数: ${switchCount}`); // 控制台输出日志
|
|
|
|
|
|
|
|
|
|
if (switchCount <= warningLimit - 1 ) {
|
|
|
|
|
// 显示警告对话框
|
|
|
|
|
dialog.showMessageBox(mainWindow, {
|
|
|
|
|
type: 'warning',
|
|
|
|
|
title: '切屏警告',
|
|
|
|
|
message: `您进行了切屏操作,此行为已被记录,如您再次进行两次切屏,则会重置考试`,
|
|
|
|
|
buttons: ['确定']
|
|
|
|
|
}).then(() => {
|
|
|
|
|
// 警告后,将焦点重新移回主窗口
|
|
|
|
|
mainWindow.focus();
|
|
|
|
|
});
|
|
|
|
|
} else if (switchCount < switchLimit) {
|
|
|
|
|
// 第三次切屏,重置警告
|
|
|
|
|
dialog.showMessageBox(mainWindow, {
|
|
|
|
|
type: 'warning',
|
|
|
|
|
title: '切屏警告',
|
|
|
|
|
message: `您再次进行了切屏操作,此行为已被记录,如您再次进行一次切屏,则会重置考试`,
|
|
|
|
|
buttons: ['确定']
|
|
|
|
|
}).then(() => {
|
|
|
|
|
mainWindow.focus();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// 超过限制次数
|
|
|
|
|
dialog.showMessageBox(mainWindow, {
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: '切屏过多',
|
|
|
|
|
message: `您因切屏超过误触缓冲次数,重置考试`,
|
|
|
|
|
buttons: ['确定']
|
|
|
|
|
}).then(() => {
|
|
|
|
|
// 重置考试:重新加载页面,重置计数器
|
|
|
|
|
switchCount = 0;
|
|
|
|
|
mainWindow.reload();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// --- 结束监听 ---
|
|
|
|
|
|
|
|
|
|
// 监听窗口关闭事件
|
|
|
|
|
mainWindow.on('closed', () => {
|
|
|
|
|
mainWindow = null;
|
|
|
|
|
});
|
2025-10-16 17:39:50 +08:00
|
|
|
|
|
|
|
|
// --- 已移除视觉作弊检测启动 ---
|
2025-10-11 10:47:07 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-16 17:39:50 +08:00
|
|
|
// --- 已移除视觉作弊检测相关函数 ---
|
|
|
|
|
|
|
|
|
|
// --- IPC 处理程序 ---
|
2025-10-11 10:47:07 +08:00
|
|
|
// 处理来自渲染进程的获取切屏次数请求
|
|
|
|
|
ipcMain.handle('get-switch-count', async () => {
|
|
|
|
|
return switchCount; // 返回当前计数
|
|
|
|
|
});
|
2025-10-16 17:39:50 +08:00
|
|
|
|
|
|
|
|
// --- 已移除未认真答题次数相关 IPC ---
|
2025-10-11 10:47:07 +08:00
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
|
|
|
|
createWindow();
|
|
|
|
|
|
|
|
|
|
app.on('activate', function () {
|
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.on('window-all-closed', function () {
|
2025-10-16 17:39:50 +08:00
|
|
|
// --- 已移除应用退出时停止色码检测 ---
|
2025-10-11 10:47:07 +08:00
|
|
|
if (process.platform !== 'darwin') app.quit();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// --- 注释掉或移除旧的 IPC 代码 ---
|
|
|
|
|
// const { ipcMain } = require('electron');
|
|
|
|
|
// ipcMain.on('get-switch-count', (event) => {
|
|
|
|
|
// event.reply('switch-count-reply', switchCount);
|
|
|
|
|
// });
|
|
|
|
|
// ipcMain.on('reset-switch-count', () => {
|
|
|
|
|
// switchCount = 0;
|
|
|
|
|
// });
|
|
|
|
|
// --- 结束注释 ---
|