Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Dec 24, 2025

User description

Summary

Fixes SITL feature which was broken because the code looked for binaries in the wrong location.

Problem

The SITL path used __dirname which points to the Vite build output (.vite/build/), but SITL binaries are located in resources/public/sitl/. This meant SITL couldn't find its executables in either dev mode or packaged builds.

Changes

  • Add getSitlBasePath() function that returns the correct path based on whether the app is packaged (process.resourcesPath) or in dev mode (app.getAppPath()/resources/public/sitl)
  • Add extraResource in forge.config.js to include SITL binaries in packaged builds
  • Add afterCopy hook to remove binaries for other platforms/architectures, reducing package size

Testing

  • Verified path resolution logic for both packaged and dev scenarios
  • The afterCopy hook correctly handles all platform/arch combinations including Linux arm64

Related

Alternative implementation to #2492


PR Type

Bug fix


Description

  • Fix SITL binary path resolution for dev and packaged modes

  • Add getSitlBasePath() function for correct path detection

  • Include SITL binaries in packaged builds via extraResource

  • Remove platform-specific binaries in afterCopy hook to reduce package size


Diagram Walkthrough

flowchart LR
  A["SITL Binary Location"] --> B{"App Packaged?"}
  B -->|Yes| C["process.resourcesPath/sitl"]
  B -->|No| D["app.getAppPath/resources/public/sitl"]
  C --> E["getSitlBasePath Function"]
  D --> E
  E --> F["chmod & startChildProcess"]
  G["forge.config.js"] --> H["extraResource adds SITL to package"]
  H --> I["afterCopy removes unused platform binaries"]
Loading

File Walkthrough

Relevant files
Configuration changes
forge.config.js
Configure SITL binary inclusion and platform filtering     

forge.config.js

  • Add extraResource configuration to include resources/public/sitl in
    packaged builds
  • Add afterCopy hook that removes SITL binaries for non-target platforms
    and architectures
  • Handle Linux arm64 architecture by moving binary to correct location
    and removing x64 variant
+33/-0   
Bug fix
main.js
Implement dynamic SITL path resolution logic                         

js/main/main.js

  • Add getSitlBasePath() function that returns correct path based on
    packaged vs dev mode
  • Replace hardcoded __dirname/sitl paths with getSitlBasePath() calls in
    chmod and startChildProcess handlers
  • Function uses process.resourcesPath for packaged builds and
    app.getAppPath()/resources/public/sitl for dev mode
+15/-2   

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
@qodo-code-review
Copy link
Contributor

ⓘ Your approaching your monthly quota for Qodo. Upgrade your plan

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

Comment on lines 364 to 369
ipcMain.handle('chmod', (_event, pathName, mode) => {
return new Promise(resolve => {
chmod(path.join(__dirname, 'sitl', pathName), mode, error => {
chmod(path.join(getSitlBasePath(), pathName), mode, error => {
if (error) {
resolve(error.message)
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Refactor the chmod IPC handler to use the promise-based fs.promises.chmod instead of wrapping the callback version in a new Promise. [general, importance: 6]

New proposed code:
-ipcMain.handle('chmod', (_event, pathName, mode) => {
-  return new Promise(resolve => {
-    chmod(path.join(getSitlBasePath(), pathName), mode, error => {
-      if (error) {
-        resolve(error.message)
-      } else {
-        resolve(false)
-      }
-    });
-  });
+ipcMain.handle('chmod', async (_event, pathName, mode) => {
+  try {
+    await chmod(path.join(getSitlBasePath(), pathName), mode);
+    return false; // Indicates success
+  } catch (error) {
+    return error.message;
+  }
 });

@qodo-code-review
Copy link
Contributor

ⓘ Your monthly quota for Qodo has expired. Upgrade your plan
ⓘ Paying users. Check that your Qodo account is linked with this Git user account

@sensei-hacker sensei-hacker merged commit ac5180b into iNavFlight:maintenance-9.x Dec 24, 2025
5 of 6 checks passed
This was referenced Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant