Skip to content

BACKGROUND THROTTLING - keep renderer at full speed when FW is flashing - #2863

Open
error414 wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
error414:error414/fix/background-throttling
Open

error414 wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
error414:error414/fix/background-throttling

Conversation

@error414

@error414 error414 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

In windows if chrome application is minimalized or not visble, then system slow down apllication and flashing never end. This PR keeps configurator alive durring flashing even if configurator is minimalized.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Keep Electron renderer unthrottled while firmware is flashing

🐞 Bug fix ✨ Enhancement 🕐 20-40 Minutes

Grey Divider

AI Description

• Disables Electron background throttling while firmware flashing holds GUI.connect_lock, so
 flashing survives minimized or covered windows.
• Adds a setBackgroundThrottling IPC bridge from renderer through preload to main, with a no-op
 stub for the web build.
• STM32 USB DFU flashing takes the lock on start and releases it when the DFU device is not found.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: device_operations.
  • Firmware flashing is one end-to-end device-management operation.
  • The changed lock setter is used by the flasher and both STM32 protocol paths, while the main-process handler controls the renderer execution needed by that operation.
  • Backup and restore are distinct device-management outcomes but share the bounded device_operations integration with firmware flashing.
  • Their lock assignments cause the new throttling side effect, without evidence that unrelated tabs consume this behavior.
Behavioral complexity 🟡 Medium 🧩 Coordinated invariants, Interacting branches

  • Before: connect_lock was a boolean UI guard, and background throttling was not coupled to it.
  • After: every lock transition must update renderer throttling through the preload and main-process path, while the browser path must remain safe.
  • New correctness conditions are that throttling is disabled for the entire locked operation, restored on every unlock path, and does not break browser builds; direct DFU also must hold the lock across asynchronous discovery.
  • Existing lock assignments and cleanup branches are reused rather than newly implemented, but their state transitions now have an additional runtime side effect.
Sources

js/main/main.js[303-307]

  // The renderer turns throttling off only while it flashes firmware: throttled timers
  // break the flashing when the window is unfocused, minimized or covered.
  ipcMain.on('setBackgroundThrottling', (event, allowed) => {
    event.sender.setBackgroundThrottling(allowed);
  });

js/browser/platform.js[116-120]

    appGetVersion: () => WEB_VERSION,
    appGetLocale: () => navigator.language || "en",
    appGetPath: () => "",
    setBackgroundThrottling: () => {},
    showOpenDialog: selectFile,
Potential damage 🟡 Medium 🩹 Temporary loss

  • If the changed throttling coordination regresses, a backgrounded or minimized flash can stall or fail, leaving firmware flashing unavailable until the device is reflashed or the operation is retried.
  • The source does not establish irreversible device data loss.
  • A successful reflash through the bootloader is required; reverting code stops new failures but does not repair a device left with incomplete or unusable firmware.
Assessed commit 4383b64
Diagram

graph TD
  A["STM32 DFU flasher"] --> B["GUI.connect_lock setter"] --> C["preload electronAPI"] --> D["ipcMain handler"] --> E["webContents.setBackgroundThrottling"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Reference-counted or scoped power-save hold
  • ➕ A missed release cannot leave throttling disabled
  • ➕ Several operations can hold throttling off independently
  • ➖ More code than a single boolean lock
  • ➖ Still needs an IPC hop to reach the main process
2. Electron powerSaveBlocker during flashing
  • ➕ Keeps the system awake during long flashes
  • ➕ Uses an established Electron API
  • ➖ Does not stop renderer timer throttling by itself
  • ➖ Adds a separate IPC and main-process lifecycle to manage

Recommendation: The approach is reasonable because Electron only exposes throttling control on the main-process WebContents, so some IPC hop is required. Keeping the lock as the single source of truth ties the throttling state to the existing flashing guard. A more robust option would be to reference-count the lock holders or use try/finally around flashing, so a missed release cannot leave throttling disabled.

Files changed (5) +28 / -1

Enhancement (3) +8 / -0
platform.jsAdd no-op setBackgroundThrottling stub for web build +1/-0

Add no-op setBackgroundThrottling stub for web build

• Adds a no-op setBackgroundThrottling to the browser platform shim so GUI code can call window.electronAPI unconditionally. Browsers have no equivalent control, so the stub does nothing.

js/browser/platform.js

main.jsHandle setBackgroundThrottling IPC in main process +6/-0

Handle setBackgroundThrottling IPC in main process

• Registers an ipcMain.on listener for 'setBackgroundThrottling' that applies the flag to event.sender, the window that sent the message. This is the only place the throttling flag is changed in the main process.

js/main/main.js

preload.jsExpose setBackgroundThrottling on electronAPI bridge +1/-0

Expose setBackgroundThrottling on electronAPI bridge

• Adds setBackgroundThrottling to the contextBridge electronAPI as a one-way ipcRenderer.send. The renderer does not wait for a reply.

js/main/preload.js

Bug fix (2) +20 / -1
gui.jsMake connect_lock a setter that toggles background throttling +16/-1

Make connect_lock a setter that toggles background throttling

• Renames the backing field to _connect_lock and defines connect_lock as an accessor on the prototype. The setter coerces the value to boolean and calls electronAPI.setBackgroundThrottling(!locked) only when the state changes.

js/gui.js

stm32usbdfu.jsHold connect_lock during STM32 DFU flashing +4/-0

Hold connect_lock during STM32 DFU flashing

• Sets GUI.connect_lock = true at the start of DFU connect and resets it to false when no DFU device is found. The diff does not show the release in the success or error path, which the comment says happens in cleanup(), so that path needs verification.

js/protocols/stm32usbdfu.js

@sonarqubecloud

sonarqubecloud Bot commented Dec 2, 2026

Copy link
Copy Markdown

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. USB enumeration errors block further flashes 🐞 Bug ☼ Reliability
Description
STM32DFU_protocol.connect() takes GUI.connect_lock before calling navigator.usb.getDevices(),
but handles only a successful enumeration. If enumeration rejects, the lock remains set and the
firmware flasher refuses subsequent attempts until the application is restarted.
Code

js/protocols/stm32usbdfu.js[91]

+    GUI.connect_lock = true;
Evidence
The new assignment takes the lock before the promise starts. The enumeration has no rejection
handler, while the flasher's entry guard requires the lock to be false.

js/protocols/stm32usbdfu.js[90-117]
tabs/firmware_flasher.js[614-617]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A rejected USB device enumeration leaves the newly acquired connection lock set, blocking further firmware flashes.

## Fix Focus Areas
- js/protocols/stm32usbdfu.js[90-117]

## Recommended Fix
Handle rejection from `navigator.usb.getDevices()` by logging the failure and releasing `GUI.connect_lock`, as the no-device path does.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 15 rules
✅ Cross-repo context — repo relationships
Review mode: Auto: ⚖️ Balanced: Behavioral firmware-flashing and Electron IPC changes carry meaningful runtime risk.

Grey Divider

Tip of the day
💡 Did you know, you can see how risky a PR is at a glance with blast radius labels

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Configurator test build ready — commit 4383b64

Download build artifacts for PR #2863

Available platforms (scroll to the Artifacts section at the bottom of the run page):

  • Windows x64 (ZIP, MSI) and x32 (ZIP, MSI)
  • macOS arm64 (ZIP, DMG) and x64 (ZIP, DMG)
  • Linux x64 (DEB, RPM, ZIP) and aarch64 (DEB, RPM, ZIP)

A GitHub login is required to download artifacts. Build is for testing only.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant