diff --git a/.changes/positioner-current-monitor-panic.md b/.changes/positioner-current-monitor-panic.md new file mode 100644 index 00000000..2f3a3c5d --- /dev/null +++ b/.changes/positioner-current-monitor-panic.md @@ -0,0 +1,6 @@ +--- +positioner: patch +positioner-js: patch +--- + +Replaced a panic in `calculate_position` with an error return when the window has no associated monitor (e.g. during display sleep or monitor reconfiguration). diff --git a/plugins/positioner/src/ext.rs b/plugins/positioner/src/ext.rs index 7c9be8c2..f9d6a80d 100644 --- a/plugins/positioner/src/ext.rs +++ b/plugins/positioner/src/ext.rs @@ -152,7 +152,9 @@ fn calculate_position( ) -> Result> { use Position::*; - let screen = window.current_monitor()?.unwrap(); + let screen = window.current_monitor()?.ok_or_else(|| { + tauri::Error::Io(std::io::Error::other("No monitor found for the window")) + })?; // Only use the screen_position for the Tray independent positioning, // because a tray event may not be called on the currently active monitor. let screen_position = screen.position();