2025-10-11 10:47:07 +08:00
|
|
|
|
// main.js
|
2025-10-21 14:56:09 +08:00
|
|
|
|
const { app, BrowserWindow, globalShortcut, screen, ipcMain } = require('electron'); // 添加 ipcMain
|
2025-10-11 10:47:07 +08:00
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
|
|
|
|
let mainWindow;
|
2025-10-21 19:19:26 +08:00
|
|
|
|
let allowQuit = false; // 添加一个标志来控制是否允许退出
|
2025-10-16 17:39:50 +08:00
|
|
|
|
|
2025-10-11 10:47:07 +08:00
|
|
|
|
function createWindow () {
|
2025-10-21 14:56:09 +08:00
|
|
|
|
// 获取主显示器尺寸
|
|
|
|
|
|
const primaryDisplay = screen.getPrimaryDisplay();
|
|
|
|
|
|
const { width, height } = primaryDisplay.size;
|
|
|
|
|
|
|
2025-10-11 10:47:07 +08:00
|
|
|
|
mainWindow = new BrowserWindow({
|
|
|
|
|
|
// --- 关键修改:设置为全屏无框 ---
|
2025-10-21 14:56:09 +08:00
|
|
|
|
width: width,
|
|
|
|
|
|
height: height,
|
2025-10-21 19:19:26 +08:00
|
|
|
|
x: 0,
|
|
|
|
|
|
y: 0,
|
2025-10-11 10:47:07 +08:00
|
|
|
|
fullscreen: true,
|
2025-10-21 14:56:09 +08:00
|
|
|
|
kiosk: true, // 关键:kiosk 模式,隐藏菜单栏、Dock
|
|
|
|
|
|
alwaysOnTop: true,
|
2025-10-11 10:47:07 +08:00
|
|
|
|
resizable: false,
|
2025-10-21 14:56:09 +08:00
|
|
|
|
movable: false,
|
|
|
|
|
|
fullscreenable: false,
|
2025-10-21 19:19:26 +08:00
|
|
|
|
frame: false, // 隐藏窗口框架和标题栏
|
|
|
|
|
|
titleBarStyle: 'hidden', // 隐藏标题栏
|
|
|
|
|
|
trafficLightPosition: { x: -100, y: -100 }, // 将红绿灯按钮移出窗口可见区域
|
2025-10-22 15:12:50 +08:00
|
|
|
|
backgroundColor: '#ffffff', // 设置背景为纯白色
|
|
|
|
|
|
hasShadow: false, // 移除窗口阴影
|
2025-10-11 10:47:07 +08:00
|
|
|
|
webPreferences: {
|
|
|
|
|
|
nodeIntegration: false,
|
2025-10-21 14:56:09 +08:00
|
|
|
|
contextIsolation: true,
|
2025-10-11 10:47:07 +08:00
|
|
|
|
enableRemoteModule: false,
|
2025-10-21 14:56:09 +08:00
|
|
|
|
preload: path.join(__dirname, 'preload.js')
|
|
|
|
|
|
}
|
2025-10-11 10:47:07 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
mainWindow.loadFile('student_app_fullscreen.html');
|
|
|
|
|
|
|
2025-10-21 19:19:26 +08:00
|
|
|
|
// 禁用窗口关闭按钮
|
|
|
|
|
|
mainWindow.on('close', (event) => {
|
|
|
|
|
|
if (!allowQuit) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-10-21 14:56:09 +08:00
|
|
|
|
// 启动时就注册全局快捷键拦截
|
|
|
|
|
|
registerGlobalShortcuts();
|
|
|
|
|
|
|
|
|
|
|
|
// 添加退出应用的IPC处理程序
|
|
|
|
|
|
ipcMain.handle('exit-app', async () => {
|
2025-10-21 19:19:26 +08:00
|
|
|
|
allowQuit = true;
|
2025-10-21 14:56:09 +08:00
|
|
|
|
app.quit();
|
2025-10-11 10:47:07 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-21 14:56:09 +08:00
|
|
|
|
// 注册全局快捷键拦截
|
|
|
|
|
|
function registerGlobalShortcuts() {
|
|
|
|
|
|
// 移除 Esc 退出功能
|
|
|
|
|
|
|
|
|
|
|
|
// 尝试注册其他快捷键(在无辅助功能权限时可能无效,但无害)
|
|
|
|
|
|
const shortcuts = [
|
|
|
|
|
|
'CommandOrControl+Tab',
|
|
|
|
|
|
'CommandOrControl+Shift+Tab',
|
|
|
|
|
|
'Command+Q',
|
|
|
|
|
|
'Command+W',
|
|
|
|
|
|
'Command+R',
|
|
|
|
|
|
'F5',
|
|
|
|
|
|
'F11',
|
|
|
|
|
|
'F12',
|
|
|
|
|
|
'Alt+Tab',
|
|
|
|
|
|
'Alt+F4',
|
|
|
|
|
|
'Control+Escape',
|
|
|
|
|
|
'CommandOrControl+W',
|
|
|
|
|
|
'CommandOrControl+R',
|
|
|
|
|
|
'Control+R',
|
|
|
|
|
|
'Alt+Space', // Windows打开菜单
|
|
|
|
|
|
'Command+Space', // Mac打开Spotlight
|
|
|
|
|
|
'Command+M', // Mac最小化
|
|
|
|
|
|
'Command+H', // Mac隐藏
|
|
|
|
|
|
'Command+Option+H', // Mac隐藏其他
|
|
|
|
|
|
'Command+Option+M', // Mac最小化所有
|
|
|
|
|
|
'Command+Option+Escape', // Mac强制退出
|
|
|
|
|
|
'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', // 功能键
|
2025-10-22 15:12:50 +08:00
|
|
|
|
'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20', 'F21', 'F22', 'F23', 'F24' // 功能键
|
2025-10-21 14:56:09 +08:00
|
|
|
|
];
|
2025-10-16 17:39:50 +08:00
|
|
|
|
|
2025-10-21 14:56:09 +08:00
|
|
|
|
shortcuts.forEach(key => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
globalShortcut.register(key, () => {
|
|
|
|
|
|
// 吃掉事件,什么都不做
|
|
|
|
|
|
console.log(`⚠️ 阻止了快捷键:`, key);
|
|
|
|
|
|
});
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.warn('Failed to register:', key);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-10-16 17:39:50 +08:00
|
|
|
|
|
2025-10-21 14:56:09 +08:00
|
|
|
|
// 注销全局快捷键拦截
|
|
|
|
|
|
function unregisterGlobalShortcuts() {
|
|
|
|
|
|
globalShortcut.unregisterAll();
|
|
|
|
|
|
}
|
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-21 14:56:09 +08:00
|
|
|
|
// 注销所有快捷键
|
|
|
|
|
|
unregisterGlobalShortcuts();
|
2025-10-11 10:47:07 +08:00
|
|
|
|
if (process.platform !== 'darwin') app.quit();
|
2025-10-21 19:19:26 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 防止应用通过常规方式退出
|
|
|
|
|
|
app.on('before-quit', (event) => {
|
|
|
|
|
|
// 只有通过退出按钮才能真正退出
|
|
|
|
|
|
if (!allowQuit) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
app.on('will-quit', (event) => {
|
|
|
|
|
|
// 清理工作
|
|
|
|
|
|
unregisterGlobalShortcuts();
|
2025-10-21 14:56:09 +08:00
|
|
|
|
});
|