Skip to content

Commit

Permalink
Don't use workspace object with potentially expired life time
Browse files Browse the repository at this point in the history
The workspace object crosses the boundaries of refreshSession. It may
not be valid in the newly started refreshSession

_fixes nikitabobko#349 on my machine

The key to reproduce 349 is to switch to workspace not mentioned in
aerospace.toml
  • Loading branch information
nikitabobko committed Jul 31, 2024
1 parent 2391f60 commit dc28c17
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/AppBundle/tree/MacWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ final class MacWindow: Window, CustomStringConvertible {
return
}
let parent = unbindFromParent().parent
let workspace = parent.workspace
let workspace = parent.workspace?.name
for obs in axObservers {
AXObserverRemoveNotification(obs.obs, obs.ax, obs.notif)
}
axObservers = []
// todo the if is an approximation to filter out cases when window just closed itself (or was killed remotely)
// we might want to track the time of the latest workspace switch to make the approximation more accurate
let focus = focus
if let workspace, workspace == focus.workspace || workspace == prevFocusedWorkspace {
if let workspace, workspace == focus.workspace.name || workspace == prevFocusedWorkspace?.name {
switch parent.cases {
case .tilingContainer, .workspace, .macosInvisibleWindowsContainer, .macosFullscreenWindowsContainer:
refreshSession(forceFocus: focus.windowOrNil?.app != app) {
_ = workspace.focusWorkspace()
_ = Workspace.get(byName: workspace).focusWorkspace()
}
case .macosPopupWindowsContainer:
break // Don't switch back on popup destruction
Expand Down

0 comments on commit dc28c17

Please sign in to comment.