-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.js
More file actions
70 lines (62 loc) · 2.09 KB
/
main.js
File metadata and controls
70 lines (62 loc) · 2.09 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
import { exec } from 'node:child_process'; // Add exec for running shell commands
import fs from 'node:fs';
import { dirname } from 'node:path';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { BrowserWindow, app, protocol } from 'electron';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
app.whenReady().then(() => {
// Set up file protocol interception for static files
protocol.interceptFileProtocol('file', (request, callback) => {
const url = request.url.substr(7);
if (url.includes('/static')) {
const startIndex = url.indexOf('/static');
let extractedString = url;
if (startIndex !== -1) {
extractedString = url.substring(startIndex);
}
const newPath = path.join(__dirname, 'build', 'app', extractedString);
callback({ path: newPath });
} else if (url.includes('/main.web.bundle')) {
const newPath = path.join(__dirname, 'build', 'app', '/main.web.bundle');
callback({ path: newPath });
} else {
callback({ path: path.normalize(url) });
}
});
const win = new BrowserWindow({
icon: path.join(__dirname, 'build', 'app', 'favicon.ico'),
webPreferences: {
nodeIntegration: false,
},
});
win.maximize();
win.loadFile(path.join(__dirname, 'build', 'app', 'index.html'));
const filePath = path.join(__dirname, 'build', 'web', 'main.web.bundle');
// Function to run the build command and reload after the process completes
const runBuildAndReload = () => {
// Run the build command
exec(
'rsbuild build -c ./config/lynx.app.ts',
{ cwd: __dirname },
(error, stdout, stderr) => {
if (error) {
console.error(`Build process failed: ${error.message}`);
return;
}
if (stderr) {
console.error(`Build process stderr: ${stderr}`);
return;
}
win.reload();
},
);
};
// Watch the file for changes
fs.watch(filePath, (eventType, filename) => {
if (filename && eventType === 'change') {
runBuildAndReload();
}
});
});