-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
71 lines (58 loc) · 1.73 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const expressServer = require('./server.js');
let mainWindow;
let sharedState = {
judgeName: ''
};
function createWindow() {
mainWindow = new BrowserWindow({
width: 1250,
height: 900,
fullscreen: true, // Open in fullscreen mode
fullscreenable: true, // Allow fullscreen toggle
autoHideMenuBar: true, // Hide menu bar in fullscreen
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
enableRemoteModule: false,
},
});
mainWindow.loadFile('public/index.html'); // Adjust the path to your entry HTML file
if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.openDevTools(); // Enable DevTools only in development
}
mainWindow.on('closed', () => {
mainWindow = null;
});
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
// Set the environment variable before starting the server
process.env.ELECTRON = true;
expressServer.start(); // Start the Express server
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
ipcMain.handle('get-shared-state', () => {
console.log('Shared state retrieved:', sharedState);
return sharedState;
});
ipcMain.handle('set-shared-state', (event, newState) => {
sharedState = { ...sharedState, ...newState };
console.log('Shared state updated:', sharedState);
});
// Handle navigation IPC
ipcMain.on('navigate', (event, url) => {
if (mainWindow) {
mainWindow.loadFile(`public/${url}`);
}
});
// Handle quit IPC
ipcMain.on('quit-app', () => {
app.quit();
});