Skip to content

Commit 0b8b5a6

Browse files
committed
Fix SITL binary path resolution for dev and packaged modes
The SITL feature was broken because the code looked for binaries in the wrong location. The path used __dirname which points to the Vite build output (.vite/build/), but SITL binaries are in resources/public/sitl/. Changes: - Add getSitlBasePath() function that returns correct path based on whether app is packaged (process.resourcesPath) or in dev mode (app.getAppPath()/resources/public/sitl) - Add extraResource in forge.config.js to include SITL in packages - Add afterCopy hook to remove binaries for other platforms/architectures, reducing package size
1 parent 5bf903c commit 0b8b5a6

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

forge.config.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export default {
99
executableName: "inav-configurator",
1010
asar: false,
1111
icon: 'images/inav',
12+
extraResource: [
13+
'resources/public/sitl'
14+
],
1215
},
1316
rebuildConfig: {},
1417
plugins: [
@@ -43,6 +46,37 @@ export default {
4346
},
4447
],
4548
hooks: {
49+
// Remove SITL binaries for other platforms/architectures to reduce package size
50+
postPackage: async (forgeConfig, options) => {
51+
for (const outputPath of options.outputPaths) {
52+
const sitlPath = path.join(outputPath, 'resources', 'sitl');
53+
if (!fs.existsSync(sitlPath)) continue;
54+
55+
if (options.platform === 'win32') {
56+
fs.rmSync(path.join(sitlPath, 'linux'), { recursive: true, force: true });
57+
fs.rmSync(path.join(sitlPath, 'macos'), { recursive: true, force: true });
58+
} else if (options.platform === 'darwin') {
59+
fs.rmSync(path.join(sitlPath, 'linux'), { recursive: true, force: true });
60+
fs.rmSync(path.join(sitlPath, 'windows'), { recursive: true, force: true });
61+
} else if (options.platform === 'linux') {
62+
fs.rmSync(path.join(sitlPath, 'macos'), { recursive: true, force: true });
63+
fs.rmSync(path.join(sitlPath, 'windows'), { recursive: true, force: true });
64+
// Remove wrong architecture
65+
if (options.arch === 'x64') {
66+
fs.rmSync(path.join(sitlPath, 'linux', 'arm64'), { recursive: true, force: true });
67+
} else if (options.arch === 'arm64') {
68+
// Move arm64 binary to linux root and remove x64
69+
const arm64Binary = path.join(sitlPath, 'linux', 'arm64', 'inav_SITL');
70+
const destBinary = path.join(sitlPath, 'linux', 'inav_SITL');
71+
if (fs.existsSync(arm64Binary)) {
72+
fs.rmSync(destBinary, { force: true });
73+
fs.renameSync(arm64Binary, destBinary);
74+
fs.rmSync(path.join(sitlPath, 'linux', 'arm64'), { recursive: true, force: true });
75+
}
76+
}
77+
}
78+
}
79+
},
4680
// Uniform artifact file names
4781
postMake: async (config, makeResults) => {
4882
makeResults.forEach(result => {

js/main/main.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ import child_process from './child_process';
1414

1515
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1616

17+
/**
18+
* Returns the base path for SITL binaries.
19+
* - In packaged mode: uses Electron's resourcesPath (where extraResource files are placed)
20+
* - In dev mode: uses the source location in resources/public/sitl
21+
*/
22+
function getSitlBasePath() {
23+
if (app.isPackaged) {
24+
return path.join(process.resourcesPath, 'sitl');
25+
} else {
26+
return path.join(app.getAppPath(), 'resources', 'public', 'sitl');
27+
}
28+
}
29+
1730
const usbBootloaderIds = [
1831
{ vendorId: 1155, productId: 57105},
1932
{ vendorId: 11836, productId: 57105}
@@ -350,7 +363,7 @@ app.whenReady().then(() => {
350363

351364
ipcMain.handle('chmod', (_event, pathName, mode) => {
352365
return new Promise(resolve => {
353-
chmod(path.join(__dirname, 'sitl', pathName), mode, error => {
366+
chmod(path.join(getSitlBasePath(), pathName), mode, error => {
354367
if (error) {
355368
resolve(error.message)
356369
} else {
@@ -373,7 +386,7 @@ app.whenReady().then(() => {
373386
});
374387

375388
ipcMain.on('startChildProcess', (_event, command, args, opts) => {
376-
child_process.start(path.join(__dirname, 'sitl', command), args, opts, mainWindow);
389+
child_process.start(path.join(getSitlBasePath(), command), args, opts, mainWindow);
377390
});
378391

379392
ipcMain.on('killChildProcess', (_event) => {

0 commit comments

Comments
 (0)