-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
79 lines (67 loc) · 1.9 KB
/
main.js
File metadata and controls
79 lines (67 loc) · 1.9 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
69
70
71
72
73
74
75
76
77
78
79
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const UDPService = require('./udp-service');
let mainWindow;
let udpService;
function createWindow() {
// Create the browser window
mainWindow = new BrowserWindow({
width: 400,
height: 830,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
},
resizable: false,
title: 'Atomberg Remote Controller',
icon: path.join(__dirname, 'icon.iconset', 'atomberg.png')
});
// Load the app
mainWindow.loadFile('index.html');
// Open DevTools in development
if (process.argv.includes('--dev')) {
mainWindow.webContents.openDevTools();
}
// Initialize UDP service
udpService = new UDPService();
udpService.startDeviceDiscovery();
// Handle window closed
mainWindow.on('closed', () => {
mainWindow = null;
if (udpService) {
udpService.stopDeviceDiscovery();
}
});
}
// App event handlers
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// IPC handlers for communication with renderer process
ipcMain.handle('get-available-devices', () => {
const devices = udpService ? udpService.getAvailableDevices() : {};
console.log('Main process - returning devices:', devices);
return devices;
});
ipcMain.handle('send-command', async (event, deviceMAC, command) => {
console.log('Main process - sending command:', command, 'to device:', deviceMAC);
if (udpService) {
return await udpService.sendCommand(deviceMAC, command);
}
return false;
});
ipcMain.handle('refresh-devices', () => {
console.log('Main process - refresh devices requested');
if (udpService) {
udpService.refreshDevices();
}
});