Skip to content

Commit ac5180b

Browse files
Merge pull request #2496 from sensei-hacker/fix-sitl-path-resolution
Fix SITL binary path resolution for dev and packaged modes
2 parents 5bf903c + 34d2696 commit ac5180b

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

forge.config.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,39 @@ export default {
99
executableName: "inav-configurator",
1010
asar: false,
1111
icon: 'images/inav',
12+
extraResource: [
13+
'resources/public/sitl'
14+
],
15+
afterCopy: [
16+
(buildPath, electronVersion, platform, arch, callback) => {
17+
// Remove SITL binaries for other platforms/architectures to reduce package size
18+
const sitlPath = path.join(buildPath, 'resources', 'sitl');
19+
if (platform === 'win32') {
20+
fs.rmSync(path.join(sitlPath, 'linux'), { recursive: true, force: true });
21+
fs.rmSync(path.join(sitlPath, 'macos'), { recursive: true, force: true });
22+
} else if (platform === 'darwin') {
23+
fs.rmSync(path.join(sitlPath, 'linux'), { recursive: true, force: true });
24+
fs.rmSync(path.join(sitlPath, 'windows'), { recursive: true, force: true });
25+
} else if (platform === 'linux') {
26+
fs.rmSync(path.join(sitlPath, 'macos'), { recursive: true, force: true });
27+
fs.rmSync(path.join(sitlPath, 'windows'), { recursive: true, force: true });
28+
// Remove wrong architecture
29+
if (arch === 'x64') {
30+
fs.rmSync(path.join(sitlPath, 'linux', 'arm64'), { recursive: true, force: true });
31+
} else if (arch === 'arm64') {
32+
// Move arm64 binary to linux root and remove x64
33+
const arm64Binary = path.join(sitlPath, 'linux', 'arm64', 'inav_SITL');
34+
const destBinary = path.join(sitlPath, 'linux', 'inav_SITL');
35+
if (fs.existsSync(arm64Binary)) {
36+
fs.rmSync(destBinary, { force: true });
37+
fs.renameSync(arm64Binary, destBinary);
38+
fs.rmSync(path.join(sitlPath, 'linux', 'arm64'), { recursive: true, force: true });
39+
}
40+
}
41+
}
42+
callback();
43+
}
44+
],
1245
},
1346
rebuildConfig: {},
1447
plugins: [

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)