-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
68 lines (56 loc) · 1.81 KB
/
main.js
File metadata and controls
68 lines (56 loc) · 1.81 KB
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
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const { startServer } = require('./server/app');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
let serverInstance;
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true
},
icon: path.join(__dirname, 'resources/icon.png')
});
mainWindow.loadFile(path.join(__dirname, 'ui/index.html'));
mainWindow.on('closed', function () {
mainWindow = null;
});
}
app.whenReady().then(async () => {
createWindow();
// Start the Express and WebSocket server
try {
const { server, connectionManager, ipAddress, qrCodeDataUrl } = await startServer();
serverInstance = server;
// Send initial info if window ready
// Store cached info for later requests
const cachedServerInfo = {
ip: ipAddress,
port: 3000,
roomCode: connectionManager.roomCode,
qrCodeDataUrl: qrCodeDataUrl
};
// IPC handler for UI requesting info (in case it loads late)
ipcMain.on('request-server-info', (event) => {
event.reply('server-info', cachedServerInfo);
});
// Send initial info if window ready
if (mainWindow) {
mainWindow.webContents.send('server-info', cachedServerInfo);
}
console.log('Server started successfully');
} catch (err) {
console.error('Failed to start server:', err);
}
app.on('activate', function () {
if (mainWindow === null) createWindow();
});
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});