fix: recover widgets lost during monitor connect/disconnect on macOS#277
Open
lohrm-spf wants to merge 1 commit intoglzr-io:mainfrom
Open
fix: recover widgets lost during monitor connect/disconnect on macOS#277lohrm-spf wants to merge 1 commit intoglzr-io:mainfrom
lohrm-spf wants to merge 1 commit intoglzr-io:mainfrom
Conversation
During macOS display reconfiguration, available_monitors() can transiently return an empty list. This caused relaunch_all to destroy all widget state and recreate zero windows — silently leaving the process running with no visible bar. Three fixes: - Skip broadcasting empty monitor lists in the poll loop to prevent premature relaunches during display transitions - Collect per-widget relaunch errors instead of bailing on first failure, so one widget's error doesn't kill siblings - Add a safety net in the monitor change handler that detects empty widget state after relaunch and retries startup with exponential backoff (500/1000/1500ms) Also adds warn-level logging for empty monitor lists and empty widget coordinates so this class of failure is no longer silent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug where Zebar's bar silently disappears when connecting/disconnecting external monitors on macOS while the process and tray icon remain alive.
Problem
During macOS display reconfiguration, Tauri's
available_monitors()can transiently return an empty or partial list. The existing code path:relaunch_allremoves all widget states from the HashMap before attempting recreationwidget_coordinatesreturns an emptyVecwhen no monitors match → the creation loop runs zero iterations → returnsOk(())?operator in the per-widget relaunch loop bails on the first failure, skipping all remaining widgets whose states were already deletedResult: process alive (tray icon visible), zero widget windows, empty error log.
Fix
Three layered defenses:
monitor_state.rs): Whenavailable_monitors()returns an empty list during display transition, skip the update to prevent premature relaunches with zero monitorswidget_factory.rs): Collect errors instead of bailing on first failure, so one widget's error doesn't prevent siblings from relaunching. Also addswarn!when no monitors match a widget's selectionmain.rs): After a monitor change relaunch, ifwidget_statesis empty but startup configs exist, retrystartup()with exponential backoff (500ms/1000ms/1500ms)Test plan