Skip to content

fix(desktop): smooth Windows installer progress bar with live status and throughput - #66506

Merged
Hona merged 3 commits into
devfrom
smooth-update-bar
Nov 26, 2026
Merged

Hona merged 3 commits into
devfrom
smooth-update-bar

Conversation

@Hona

@Hona Hona commented Nov 26, 2026

Copy link
Copy Markdown
Member

Fixes the Windows NSIS one-click update progress bar flickering backwards/jumping randomly and replaces the static "Installing, please wait..." banner text with live phase, size, and throughput status.

Before After
Static banner text and instruction-driven bar Live extraction size, throughput, and monotonic bar

Root Cause

  • NSIS drives IDC_PROGRESS (1004) from instruction offsets inside Section "install", and SpiderBanner::Show /MODERN mirrors every PBM_SETPOS to its visible bar. Inline loops in customCheckAppRunning (walking every Windows process every 100 ms) bounced the instruction pointer forward and backward thousands of times per second.
  • On unstaged fallback updates, Nsis7z::Extract directly reset IDC_PROGRESS from ~50% back to 0%, filled to 100%, and NSIS snapped it back down to ~70% on the very next section instruction.

Changes

  • Monotonic progress driver (patches/[email protected]):
    • Wraps installSection.nsh in Function runInstallSection (single Call in Section "install") so NSIS never writes instruction-offset progress.
    • Renames NSIS's hidden progress bar control ID (1004 → 1099) via SetWindowLongW(GWL_ID) right after SpiderBanner subclasses it, preventing Nsis7z from resetting the bar while SpiderBanner continues forwarding our PBM_SETPOS calls.
    • Enforces strict monotonicity (pos > lastPos, clamped to 30000) in setInstallProgress and maps Nsis7z::ExtractWithCallback linearly across 45% → 85% using 64-bit System::Int64Op.
    • Adds a 120 ms settle at 100% (non-silent installs only) so Windows's smooth bar finishes filling before the banner hides.
  • Live phase & throughput label (patches/[email protected], packages/desktop/resources/windows/installer.nsh):
    • Updates SpiderBanner control 1000 across each phase: Closing OpenCode... (nudging +1%/100 ms while waiting), Removing previous version..., Applying staged update... or Extracting... <done> / <total> MB (<rate> MB/s) (throttled to 80 ms, KB fallback below 1 MB), Finishing installation..., Setting permissions..., and Launching OpenCode....
    • No-op in silent /S updates (zero overhead for install-on-quit).
  • Regression test (packages/desktop/script/windows-installer.test.ts): Compiles the full ONE_CLICK installer, runs an update against a running stand-in process and real .7z archive, polls SpiderBanner's msctls_progress32 every 10 ms, and asserts zero backward jumps, 30000 completion, and live Extracting... status text.
flowchart LR
  Init["SpiderBanner::Show + initInstallProgress<br/>5% · GWL_ID 1004→1099"] --> Close["CHECK_APP_RUNNING<br/>5%→20% · Closing OpenCode..."]
  Close --> Uninst["uninstallOldVersion<br/>20%→45% · Removing previous version..."]
  Uninst -->|staged| Rename["customInstallStagedApp<br/>45%→85% · Applying staged update..."]
  Uninst -->|unstaged| Extract["Nsis7z::ExtractWithCallback<br/>45%→85% · Extracting... MB (MB/s)"]
  Rename --> Finish["Registry + shortcuts + icacls<br/>85%→100% · Finishing / Setting permissions"]
  Extract --> Finish
  Finish --> Done["100% · Launching OpenCode..."]
Loading

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I couldn't verify this: it changes Windows NSIS update behaviour, and this environment is Linux. The patched one-click installer does compile cleanly (exit 0, no warnings) with electron-builder's makensis, using the same defines as the new test. The new Windows tests are skipped here.

Public API: unchanged. The changes are internal to the installer template and the custom include.

Concerns (details inline):

  • Localization: the new status lines are hard-coded English. They replace the localized $(installing) banner for most of the update.
  • New progress test: it's large and timing-sensitive, and depends on whatever .7z happens to be in the electron-builder cache.

The approach itself (driving PBM_SETPOS from a function and re-IDing the hidden 1004 control so Nsis7z can't reset it) looks sound for the one-click path.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I couldn't verify this on Windows. The patched one-click installer, with the patched messages.yml, builds cleanly with electron-builder's makensis in both single-language and multi-language mode (exit code 0, no warnings). The Windows tests are skipped on Linux.

Both earlier points are addressed:

  • Localization: the new status strings are now localized strings from messages.yml. They only have English text so far, and electron-builder uses that English text for the other languages in multi-language builds.
  • Test: the timing-dependent window polling and the arbitrary cached .7z are gone. The test now checks a trace of the shipped progress functions.

Public API: unchanged. Nothing new to flag.

@Hona
Hona merged commit 662002c into dev Nov 26, 2026
10 checks passed
@Hona
Hona deleted the smooth-update-bar branch November 26, 2026 03:16
@amrkmn amrkmn mentioned this pull request Nov 30, 2026
1 task
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