forked from seydx/camera.ui
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
54 lines (47 loc) · 1.38 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
const { app, BrowserWindow } = require('electron');
const path = require('path');
const { exec } = require('child_process');
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,
preload: path.join(__dirname, 'preload.js'), // Optional preload for secure API access
},
});
// Load the Camera.UI interface on port 8081
win.loadURL('http://localhost:8081');
}
app.whenReady().then(() => {
// Step 1: Build Camera.UI
exec('npm run build', { cwd: path.join(__dirname) }, (buildErr, buildOut, buildStderr) => {
if (buildErr) {
console.error(`Build error: ${buildErr.message}`);
return;
}
console.log(buildOut || buildStderr);
// Step 2: Run the server in watch mode
exec('npm run watch', { cwd: path.join(__dirname) }, (watchErr, watchOut, watchStderr) => {
if (watchErr) {
console.error(`Watch error: ${watchErr.message}`);
return;
}
console.log(watchOut || watchStderr);
});
// Step 3: Open Electron window after build
createWindow();
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});