Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
79 lines (66 loc) · 2.34 KB
/
Copy pathmain.js
File metadata and controls
79 lines (66 loc) · 2.34 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
require('dotenv').config(); // Load environment variables securely from .env
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const os = require('os');
// --- CAMERA FEED COLOR FIXES ---
// Forces strict color formatting to prevent the purple/green YUV decoding bug
app.commandLine.appendSwitch('force-color-profile', 'srgb');
// Disables hardware acceleration which causes color-swapping on IP Camera feeds
app.disableHardwareAcceleration();
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 800,
frame: false, // Assuming you hid the default OS frame earlier!
icon: path.join(__dirname, 'build/icon.png'), // Points to your app icon
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true
}
});
// Check if we are running in development or production
const isDev = !app.isPackaged;
if (isDev) {
win.loadURL('http://localhost:4200');
win.webContents.openDevTools();
} else {
// In production, load the compiled Angular index.html
win.loadFile(path.join(__dirname, 'dist/smartLCARS/index.html'));
}
// IPC Listeners for custom LCARS window controls
ipcMain.on('window-minimize', () => win.minimize());
ipcMain.on('window-maximize', () => {
win.isMaximized() ? win.unmaximize() : win.maximize();
});
ipcMain.on('window-close', () => win.close());
}
// Intercept the config request from the Angular frontend securely
ipcMain.handle('get-env-config', () => {
return {
HA_URL: process.env.HA_URL,
HA_TOKEN: process.env.HA_TOKEN
};
});
// New System Telemetry channel
ipcMain.handle('get-system-stats', () => {
const totalMem = os.totalmem();
const freeMem = os.freemem();
const memPercentage = (((totalMem - freeMem) / totalMem) * 100).toFixed(1);
// Node's loadavg returns 1, 5, and 15 min averages. We will use the 1-minute load.
const cpuLoad = os.loadavg()[0].toFixed(2);
const uptime = os.uptime();
return { memPercentage, cpuLoad, uptime };
});
ipcMain.on('close-app', () => {
app.quit();
});
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});