Skip to content

fix: show a turned-off widget's last output when it comes back - #950

Merged
M4n0x merged 2 commits into
mainfrom
fix/keep-script-output-while-disabled
Nov 27, 2026
Merged

M4n0x merged 2 commits into
mainfrom
fix/keep-script-output-while-disabled

Conversation

@M4n0x

@M4n0x M4n0x commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Turning a script widget off stopped its script and dropped its output. Turning it back on, for example through a profile that matches one app, showed nothing until the script ran again. A script that calls network services, such as the Store's AI usage package, took seconds to come back on every return to that app. Closes #949.

Changes

  • WidgetScripts.run no longer stops the script of a widget that is only turned off. It suspends the script and keeps it in a private parked table, separate from scripts. Code that reads scripts for every configured widget, such as output barStyle and widgetStyles, the inspector and --query, therefore never sees a turned-off widget's output.
  • When the widget is turned on again with the same command, interval, timeout, widget environment and configuration environment, its script goes back into scripts. updateSuspension resumes it, unless scripts are paused (Pause scripts and providers while the displays sleep or the screen is locked #219). The widget shows its last output, samples and diagnostics at once, and the script runs again with the resume sender.
  • A parked script stops for good when its widget changes, is removed, or the configuration's environment changes, and when the bar stops.
  • BarPresentation gives a widget's presentation an output number only while the widget has a script. Before this, a turned-off widget's presentation was set to output 0. When the parked script came back, its old output then looked new, and a temporary that had already expired showed again. cubic found this.
  • docs/configuration.md says that turning a widget off pauses its script, and names what makes the script start afresh instead.

No configuration format change.

Testing

  • swift build --build-tests, then the full swift test: 293 XCTest and 1477 Swift Testing tests pass. scripts/check.sh --quick passes.
  • New in DataSourceTests:
    • aWidgetTurnedOffAndOnAgainShowsItsLastOutputAtOnce: a profile turns the widget off for one app. The same suspended script comes back with its output, then runs again. Without the fix, this test fails.
    • aWidgetTurnedOnAgainDoesNotReplayAnExpiredTemporary: a temporary that expired before the widget was turned off doesn't show again when the widget comes back. Without the BarPresentation change, this test fails.
    • aWidgetChangedWhileTurnedOffStartsAfresh: a command changed while the widget is off gets a new script.
  • liveModuleReloadPreservesWorkingScriptsAndRecoversAfterRepair expected a new script object after the widget is turned back on. It now expects the same script, resumed, with output resume. While the widget is off, it still checks that a refresh doesn't run the script.
  • One full run had a failure in shiftReturnStartsANewLineInAnInputThatWrapsAndReturnSends, which this change doesn't touch. It passed alone three times, and the next full run passed.

Not checked by hand on a running bar. The tests drive the store through the same refreshContext path as a focused-app change.

Merging

Two commits, both fix, which give the same release whether squashed or rebased. When squashing, keep the first commit's message, which closes #949. This PR is independent of #948, which animates the same profile changes. Either can merge first.

Claude Opus 5.5 via Claude Code

Turning a script widget off stopped its script and dropped its output,
so turning it on again, such as by a profile that matches one app,
showed nothing until the script ran again, which can take seconds for
a script that calls a network service. A widget turned off now keeps
its script suspended with its last output, outside the scripts the bar
reads, and gets it back when it's turned on with the same command,
interval, timeout and environment. The script then runs again at once.

Closes #949
@M4n0x
M4n0x requested a review from Seb-GRAF as a code owner November 27, 2026 09:24

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread docs/configuration.md Resolved
Comment thread docs/configuration.md Resolved
While a widget was turned off, its presentation was shown output number
0, so the parked script's last output looked new when the widget came
back, and a `temporary` that had run out showed again. A widget without
a script now leaves its presentation's output number as it was.

The guide now says that turning a widget off pauses its script, and
names everything that makes the script start afresh instead.

Refs #949
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Before and after

main at 1fe18ea → this pull request at 6a7e6d3 · 202 screens drawn · 0 changed

202 unchanged screens

docs/essentials-clock-settings-dark, docs/essentials-clock-settings-light, docs/essentials-dark, docs/essentials-light, docs/essentials-settings-dark, docs/essentials-settings-light, docs/hero-dark, docs/hero-light, docs/popups-dark, docs/popups-light, docs/settings-dark, docs/settings-light, docs/themes-dark, docs/themes-light, scenes/accessibility-guide-dark, scenes/app-menu-popup-dark, scenes/apple-menu-settings-dark, scenes/apple-menu-symbol-bar-dark, scenes/apple-menu-symbol-settings-dark, scenes/bar-dividers-dark, scenes/bottom-bar-popup-dark, scenes/chat-popup-dark, scenes/crowded-edit-bar-dark, scenes/disk-meter-bar-dark, scenes/dock-badges-bar-dark, scenes/edit-bar-wide-group-dark, scenes/essentials-clock-popup-dark, scenes/essentials-disk-popup-dark, scenes/filled-slider-popup-dark, scenes/glass-text-follows-background-bar-dark, scenes/glass-text-follows-background-bar-light, scenes/group-members-bar-dark, scenes/group-others-bar-dark, scenes/group-text-color-bar-dark, scenes/gruvbox-bar-dark, scenes/gruvbox-bar-light, scenes/horizontal-list-popup-dark, scenes/increase-contrast-bar-dark, scenes/increase-contrast-bar-light, scenes/increase-contrast-popup-dark, scenes/increase-contrast-popup-light, scenes/input-source-popup-dark, scenes/labeled-metric-built-in-dark, scenes/labeled-metric-catppuccin-dark, scenes/labeled-metric-catppuccin-light, scenes/meeting-live-popup-dark, scenes/meeting-soon-bar-dark, scenes/menu-bar-items-widget-settings-dark, scenes/menu-bar-items-widget-style-dark, scenes/merged-status-bar-dark, scenes/notch-flare-bar-dark, scenes/output-device-popup-dark, scenes/package-template-clash-bar-dark, scenes/popup-gap-bar-dark, scenes/popup-spacing-bar-dark, scenes/popup-view-dark, scenes/preset-dashboard-bar-dark, scenes/preset-developer-bar-dark, scenes/preset-everyday-bar-dark, scenes/preset-minimal-bar-dark, scenes/preset-workday-bar-dark, scenes/privacy-both-bar-dark, scenes/privacy-hide-when-idle-bar-dark, scenes/privacy-idle-bar-dark, scenes/privacy-microphone-bar-dark, scenes/privacy-settings-dark, scenes/quick-toggles-bar-dark, scenes/quick-toggles-displays-popup-dark, scenes/quick-toggles-every-tile-popup-dark, scenes/quick-toggles-network-popup-dark, scenes/quick-toggles-networks-popup-dark, scenes/quick-toggles-popup-dark, scenes/reduce-transparency-bar-dark, scenes/reduce-transparency-bar-light, scenes/reduce-transparency-glass-bar-dark, scenes/reduce-transparency-glass-bar-light, scenes/reduce-transparency-text-follows-background-bar-dark, scenes/reduce-transparency-text-follows-background-bar-light, scenes/ring-bar-dark, scenes/settings-bar-dark, scenes/settings-bar-link-dark, scenes/settings-bar-link-review-dark, scenes/settings-bar-link-workspace-color-dark, scenes/settings-bar-look-dark, scenes/settings-bar-look-light, scenes/settings-bar-placement-bottom-dark, scenes/settings-bar-placement-dark, scenes/settings-calendar-picker-dark, scenes/settings-calendar-widget-dark, scenes/settings-clock-widget-dark, scenes/settings-crashes-dark, scenes/settings-disk-widget-dark, scenes/settings-feedback-dark, scenes/settings-general-dark, scenes/settings-general-kiwidesk-dark, scenes/settings-general-macos15-dark, scenes/settings-general-macos27-dark, scenes/settings-general-manager-not-found-dark, scenes/settings-general-move-dark, scenes/settings-general-move-failed-dark, scenes/settings-general-move-moving-dark, scenes/settings-general-move-replace-dark, scenes/settings-general-setup-open-dark, scenes/settings-general-spaces-dark, scenes/settings-general-yabai-gap-dark, scenes/settings-group-dark, scenes/settings-group-defaults-dark, scenes/settings-group-defaults-light, scenes/settings-group-theme-color-dark, scenes/settings-group-theme-color-light, scenes/settings-help-dark, scenes/settings-help-starred-dark, scenes/settings-labeled-metric-dark, scenes/settings-narrow-dark, scenes/settings-package-dark, scenes/settings-package-widget-dark, scenes/settings-profiles-conditions-dark, scenes/settings-profiles-dark, scenes/settings-profiles-groups-dark, scenes/settings-profiles-theme-dark, scenes/settings-quick-toggles-dark, scenes/settings-store-dark, scenes/settings-theme-dark, scenes/settings-theme-edits-dark, scenes/settings-theme-edits-light, scenes/settings-theme-groups-dark, scenes/settings-theme-light, scenes/settings-theme-link-dark, scenes/settings-theme-link-light, scenes/settings-theme-origins-dark, scenes/settings-theme-versions-dark, scenes/settings-tiled-dark, scenes/settings-tiled-narrowest-dark, scenes/settings-uninstall-dark, scenes/settings-uninstall-failed-dark, scenes/settings-widget-backgrounds-dark, scenes/settings-widget-backgrounds-light, scenes/settings-widget-colors-dark, scenes/settings-widget-colors-light, scenes/settings-widget-style-theme-edits-dark, scenes/settings-widget-style-theme-edits-light, scenes/settings-workspace-hidden-dark, scenes/setup-allow-aerospace-gap-dark, scenes/setup-allow-automation-dark, scenes/setup-allow-below-menu-bar-dark, scenes/setup-allow-dark, scenes/setup-allow-dot-dark, scenes/setup-allow-macos27-dark, scenes/setup-allow-offline-dark, scenes/setup-allow-spaces-dark, scenes/setup-allow-workday-dark, scenes/setup-choose-dark, scenes/setup-choose-new-dark, scenes/setup-choose-no-battery-dark, scenes/setup-done-dark, scenes/setup-intro-dark, scenes/setup-intro-wallpaper-dark, scenes/setup-move-existing-dark, scenes/setup-move-failed-dark, scenes/setup-move-ready-dark, scenes/setup-move-replace-dark, scenes/shadow-offsets-bar-dark, scenes/shadow-offsets-bar-light, scenes/share-my-bar-dark, scenes/share-my-bar-dock-dark, scenes/share-my-bar-glass-dark, scenes/share-my-bar-glass-light, scenes/share-my-bar-landscape-dark, scenes/share-my-bar-link-dark, scenes/share-my-bar-macbook-dark, scenes/share-my-bar-post-dark, scenes/slider-end-stop-popup-dark, scenes/sound-details-popup-dark, scenes/stablebar-widget-bar-dark, scenes/stablebar-widget-settings-dark, scenes/starter-bar-dark, scenes/starter-edit-bar-dark, scenes/symbol-variants-bar-dark, scenes/system-monitor-memory-bar-dark, scenes/system-monitor-shows-settings-dark, scenes/system-monitor-split-warning-bar-dark, scenes/text-follows-background-bar-dark, scenes/text-follows-background-bar-light, scenes/themed-slider-inline-dark, scenes/themed-slider-inline-light, scenes/themed-slider-popup-dark, scenes/themed-slider-popup-light, scenes/themed-slider-tooltip-dark, scenes/themed-slider-tooltip-light, scenes/tinted-app-icons-bar-dark, scenes/tinted-app-icons-bar-light, scenes/tinted-image-bar-dark, scenes/tinted-image-bar-light, scenes/update-popup-dark, scenes/update-popup-star-github-cli-dark, scenes/update-popup-star-thanks-dark, scenes/workspace-badges-bar-dark, scenes/workspace-cells-bar-dark, scenes/workspace-focused-window-bar-dark, scenes/workspace-focused-window-padding-bar-dark, and 2 more

Visual review: 202 screens, none changed.

@M4n0x M4n0x added the deep-review CodeRabbit reviews this pull request: big or risky changes label Nov 27, 2026
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Disabled script widgets now retain their script and last output when their configuration matches. Re-enabled widgets restore that output and resume the script. Tests and configuration documentation cover this behavior.

Changes: Widget script resume

Layer / File(s) Summary
Park and restore matching scripts
Sources/StableBar/DataSources/WidgetScripts.swift
WidgetScripts parks disabled scripts when widget content, timeout, and environment match. It restores parked scripts when the widgets are re-enabled and stops parked scripts when configurations change or stop() runs.
Present and validate resumed output
Sources/StableBar/Bar/BarPresentation.swift, Tests/StableBarTests/DataSourceTests.swift, Tests/StableBarTests/ModuleConfigurationTests.swift, docs/configuration.md
Presentation calls show only for scripted widgets. Tests cover output retention, temporary output expiry, changed commands, and module reload. The documentation describes resume behavior and configuration changes that start scripts afresh.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 6a7e6

Turning a script widget off and on again now restores its last output immediately and resumes the script. No concrete merge-blocking defect was found in the change.

Security architecture risk: Low · up to 6a7e6

A re-enabled widget can run a previously supplied click command before its script refreshes. This is limited to an unchanged widget on the same bar and still requires an interaction that the app allows.

Retained concerns

  • Low · security · observed: The restored output can supply a click command before the re-enabled script produces fresh output. If the refresh fails or the script remains paused, the old command can remain available. The base did not carry output-derived commands across disable and re-enable. Execution still requires an allowed widget interaction and uses the existing local command runner.
Security review details

Security Blast Radius

  • inferred — The changed action exposure is local to re-enabled script widgets whose prior output supplied a click command and whose configuration still matches. It does not grant a new execution privilege or make parked widgets independently reachable.

Security Findings and Attack Paths

  • observed — A command from the last accepted script output can become clickable again after re-enable and reach the existing shell runner before a new output replaces it. The reviewed path requires a widget interaction; it does not execute the cached click command automatically on resume.

Trust Boundaries and Controls

  • observed — Configuration matching controls which instance can be restored. The existing edit-mode gate controls whether actions may execute, but does not distinguish cached output from output accepted after re-enable.

Resilience and Maintainability Implications

  • observed — Parking cancels active work using the same teardown as stop. The task checks cancellation before accepting output, and bar shutdown stops and clears parked instances.

Hardening Proposals

  • proposed — Restore cached display values immediately, but withhold output-derived commands until the script accepts fresh output after re-enable. Keep that distinction in effect if the script is paused or its refresh fails.
Pre-merge checks: Passed 3

Check name Status Explanation
Description check Passed The description follows the repository template. It has Problem, Changes, Testing, and Merging sections. It names the linked issue (Closes #949) and explains the user-visible bug and the fix. The Chan…
Linked Issues check Passed Issue #949 asks that a script widget turned off with enabled: false, then turned on again, show its last output at once and update when its script finishes. At the reviewed head, WidgetScripts.run (So…
Out of Scope Changes check Passed The changes address #949 or support it. WidgetScripts.swift contains the parking, resuming and stopping logic. The BarPresentation.swift change (show only for widgets with a script) prevents a turned-…
Full details: Description check

Explanation

The description follows the repository template. It has Problem, Changes, Testing, and Merging sections. It names the linked issue (Closes #949) and explains the user-visible bug and the fix. The Changes section explains each area and why it is needed. The Testing section lists commands, new tests, one unrelated flaky failure, and what was not checked by hand. The Merging section states the commit strategy and squash guidance. The final line names the model and harness, Claude Opus 5.5 via Claude Code, as the template requires.

Full details: Linked Issues check

Explanation

Issue #949 asks that a script widget turned off with enabled: false, then turned on again, show its last output at once and update when its script finishes. At the reviewed head, WidgetScripts.run (Sources/StableBar/DataSources/WidgetScripts.swift) handles this. When a widget is turned off and its content, timeout and environment match, and the configuration environment is unchanged, the code calls script.suspend() and stores the script in the private parked table instead of stopping it. When the widget is enabled again, the enabled-widget loop moves the parked script back into scripts, and updateSuspension() resumes it unless scripts are paused. The existing output is therefore available at once, and the script runs again. The code stops a parked script when its widget changes or is removed, or when the configuration environment changes. This matches the issue's diagnosis and expected behavior. The tests named in the PR description (DataSourceTests and the updated liveModuleReloadPreservesWorkingScriptsAndRecoversAfterRepair) were not read; the PASS rests on the source logic read at the head. The stop() path that clears parked scripts on bar stop was truncated in the read and was not checked; it is not a stated issue requirement.

Full details: Out of Scope Changes check

Explanation

The changes address #949 or support it. WidgetScripts.swift contains the parking, resuming and stopping logic. The BarPresentation.swift change (show only for widgets with a script) prevents a turned-off widget's presentation from keeping output number 0; the PR description ties this to replaying an expired temporary after the widget returns, which the DataSourceTests cover. docs/configuration.md describes the new behavior. The ModuleConfigurationTests change updates an existing test to the new resume behavior. The two summary-only files (BarPresentation.swift, ModuleConfigurationTests.swift, docs) were assessed from the supplied summary, not from the source diff, because the diff read was unavailable. No unrelated change was found.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1fe18ea and 6a7e6d3.

Files selected for processing: 5

  • Sources/StableBar/Bar/BarPresentation.swift
  • Sources/StableBar/DataSources/WidgetScripts.swift
  • Tests/StableBarTests/DataSourceTests.swift
  • Tests/StableBarTests/ModuleConfigurationTests.swift
  • docs/configuration.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@M4n0x
M4n0x added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 6776fcb Nov 27, 2026
29 checks passed
@M4n0x
M4n0x deleted the fix/keep-script-output-while-disabled branch November 27, 2026 10:29
stablebar-releases Bot pushed a commit that referenced this pull request Nov 29, 2026
## [0.20.0](v0.19.0...v0.20.0) (2026-11-29)

### Features

* animate widgets that a profile shows or hides ([#948](#948)) by @M4n0x ([eec8544](eec8544)), closes [#947](#947) [#947](#947)
* log quit causes and show unexpected quits in Status ([#953](#953)) by @M4n0x ([ea5a64e](ea5a64e)), closes [#952](#952)

### Bug Fixes

* choose a submenu item opened from the App menus tray ([#944](#944)) by @MaHofseth ([add49b0](add49b0)), closes [#942](#942)
* draw borders in whole pixels so they keep every edge on 1x screens ([#934](#934)) by @M4n0x ([8590fcd](8590fcd)), closes [#933](#933) [#933](#933)
* keep a package version installed when its folder is hidden ([#962](#962)) by @M4n0x ([2d97d15](2d97d15)), closes [#961](#961)
* keep the Sound details open and smooth when picking a device ([#931](#931)) by @M4n0x ([df96453](df96453)), closes [#928](#928) [#928](#928)
* keep windows clear of the bar after a double-click fills them ([#936](#936)) by @M4n0x ([c1478d1](c1478d1)), closes [#935](#935) [#935](#935)
* leave the keyboard with the app while StableBar shows its menus ([#943](#943)) by @MaHofseth ([abc1c4f](abc1c4f)), closes [#941](#941)
* play an app's first sound at its mixer volume ([#899](#899)) by @M4n0x ([2c38350](2c38350)), closes [#897](#897) [#897](#897)
* show a turned-off widget's last output when it comes back ([#950](#950)) by @M4n0x ([6776fcb](6776fcb)), closes [#949](#949) [#949](#949)
* show Countdown and Join in Settings after picking it ([#940](#940)) by @MaHofseth ([6ecaa72](6ecaa72))
* stop offering a package update that is already installed ([#956](#956)) by @M4n0x ([4592ebc](4592ebc))
@stablebar-releases

Copy link
Copy Markdown

🎉 This PR is included in version 0.20.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

deep-review CodeRabbit reviews this pull request: big or risky changes released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A script widget turned off and on again shows nothing until its script runs again

1 participant