Repository navigation
fix: undo StableBar's changes when it's uninstalled from Settings or with Homebrew - #894
Conversation
…ey're done
Settings' Uninstall sheet was built before the button read the Mac, so it planned no steps: not
the menu bar's auto-hide, Open at login or the stablebar command, and it took a Homebrew install
for a download. It then called NSApp.terminate with the sheet still attached, which AppKit
refuses ("App termination blocked by modal sheet"), so StableBar never quit, Uninstall beeped
on a second click and --finish-uninstall waited for good. Quit StableBar had the same problem.
UninstallFlow, a state machine, now decides the sheet's phases, and a controller owned by the
Settings row reads the Mac when the sheet opens and performs its effects. The sheet reads the
flow as it draws, and the sheet ends before StableBar quits.
The guide said brew uninstall --zap runs stablebar --uninstall --yes, but the cask only deletes files. Run on its own, Homebrew leaves the menu bar's auto-hide, Open at login and permissions as they are, and a StableBar that's running keeps running.
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
Before and after
263 unchanged screens
Visual review: 263 screens, none changed. |
|
About the 8 changed |
* fix: undo StableBar's changes when Homebrew uninstalls it brew uninstall --cask stablebar only removed the app: a bar that was running kept running, and the menu bar's auto-hide, Open at login, permissions, the stablebar command and Keychain items stayed. The cask's uninstall script now runs --homebrew-uninstall. Homebrew runs that script to upgrade and reinstall too, without saying which, so it copies the app to ~/Library/Caches and starts the copy, which waits for brew to exit. When StableBar is still installed then, it only deletes itself. Otherwise Launch Services opens it, so it controls System Events with StableBar's own permission, and it does what Settings' Uninstall does, except moving the app. Refs #896 * fix: delete StableBar's preferences file when uninstalling Removing the preferences domain left an empty property list in ~/Library/Preferences, which UserDefaults writes seconds later, even after StableBar has quit. It also came back after brew uninstall --zap had trashed the file. defaults delete writes that file at once, so Uninstall now runs it and then deletes the file. * docs: say what brew uninstall undoes and what an older cask leaves brew uninstall --cask stablebar now undoes StableBar's changes once Homebrew is done, and keeps everything on an upgrade or a reinstall. Homebrew keeps the uninstall steps of the cask that installed StableBar, so an install from before 0.19.0 needs brew reinstall first. * fix: list every step left to do when Homebrew's uninstall can't quit StableBar When another StableBar wouldn't quit, the steps after Homebrew stopped there, and the alert listed only the quit, saying to uninstall again, which Homebrew's removal of the app no longer allows. The alert now also lists each step that didn't run, with what to do by hand. --------- Co-authored-by: Steve Mendes Reis <[email protected]>
|
🎉 This PR is included in version 0.19.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Problem
Settings → General → Uninstall did nothing: a spinner for under a second, then the sheet stayed open and a second click only beeped. Fixes #848; the notch apps request from that issue moved to #893.
I reproduced it in a tart VM (macOS 26.6, StableBar 0.18.0 from the Homebrew tap, setup finished with Replace the menu bar and Open at login on). There were two causes:
.sheet(isPresented:)builtUninstallSheetwith the snapshot captured before the button had read the Mac. It saw an empty Mac: no auto-hide to turn off, no Open at login, nostablebarcommand, and not installed by Homebrew. It listed only "Reset permissions" and "Delete caches and preferences".--finish-uninstalland calledNSApp.terminatewhile the sheet was still attached. AppKit refuses that; the log saysApp termination blocked by modal sheetand thenTermination aborted. The helper then waited for good, and quitting by AppleScript was cancelled too. Quit StableBar in the result sheet had the same problem.This branch also contains #898, merged into it:
brew uninstall --cask stablebarleft the bar running from the deleted app and every change on the Mac. Fixes #896. That part needs the cask change in stablebox/homebrew-tap#3.Changes
UninstallFlow(new,App/UninstallFlow.swift) is aStateMachinefor the sheet's phases: closed, confirming, running, finished (with outcomes and whether--finish-uninstallwaits), quitting. The steps and decisions are the same as before (stepsBeforeQuit,finishesAfterQuit, staying open for a failed step or a Homebrew install), but each transition is now unit-tested.UninstallController, owned by the Settings row, reads the Mac when the sheet opens and performs the flow's effects. It holdsBarStoreweakly. The sheet'sisPresentedand its content read the flow from the controller as they draw, so the sheet always shows what was just read.NSApp.terminategoes through.main.brew uninstall --zapdidn't runstablebar --uninstall --yes, as the guide said; the cask only deleted files.From #898 (Homebrew, #896; its description has the details and the Homebrew source it relies on):
--homebrew-uninstall, which the cask'suninstallscript runs. Homebrew runs that script to upgrade and reinstall too, without saying which. So StableBar copies itself to~/Library/Cachesand starts the copy with--finish-homebrew-uninstall, which waits untilbrewexits. If StableBar is still installed then, the copy only deletes itself. Otherwise Launch Services opens it, so it controls System Events with StableBar's own permission, and it does what Settings' Uninstall does, except moving the app.org.stablebar.app.plistinstead of leaving the empty file thatremovePersistentDomainmade cfprefsd write seconds later. Settings' Uninstall gets this too.docs/getting-started.md,docs/questions.mdand its copy inHelpQuestion.swiftsay whatbrew uninstalland--zapnow do. Installs made before the cask change keep its old steps untilbrew reinstall --cask stablebar.Testing
swift test: 10 new tests inUninstallFlowTestscover every transition and ending an attached sheet. The uninstall, help, scene renderer and architecture tests pass. In the full suite,workspaceLabelsFollowTheBarFromLightToDarkalso fails onmainon this Mac.shiftReturnStartsANewLineInAnInputThatWrapsAndReturnSendsfailed once under load and passed on its own.scripts/check.sh --quickis clean.HomebrewUninstallTests,UninstallTests,UninstallFlowTests,HelpQuestionTestsandArchitectureRulesTestspass (65 tests), and CI's required checks pass on bb90c02. fix: undo StableBar's changes when Homebrew uninstalls it #898's description has its VM results:brew uninstall(with and without the bar running) and--zapput everything back;brew upgrade --cask --greedyandbrew reinstallchange nothing.~/.config/stablebarto the Trash. Everything was put back: auto-hide off, the login item disabled, the command removed, permissions reset, preferences deleted, andStableBar.appand the configuration in the Trash.--uninstallwith System Events access denied and the password cancelled. Both steps were reported with what to do by hand and the other steps still ran.SIGSTOP). Uninstall stopped after the quit step and changed nothing else. Run again once it could quit, it finished every step.Before, on a Homebrew install with auto-hide and Open at login on: the sheet still open 5 seconds after clicking Uninstall, with only two steps listed.
After, the same Mac:
After, the password prompt cancelled: the step is listed and Quit StableBar finishes the rest.
After, a download install:
Merging
Three commits: two
fixand adocs, each passing on its own. A merge commit or rebase merge keeps all three for semantic-release. When squashing, keep thefix:title and keep "Fixes #848" and "Fixes #896" in the message.stablebox/homebrew-tap#3 can merge before or after this. With an older StableBar, its script fails without stopping brew (
must_succeed: false), so Homebrew uninstalls only put the Mac back once a release has this.Claude Opus 5.5 via Claude Code (T3 Code)