Skip to content

Commit b62cec0

Browse files
committed
fix: may crash when changing space or screen
1 parent a474660 commit b62cec0

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/logic/Windows.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class Windows {
308308
if let cgWindowId = window.cgWindowId {
309309
let spaceIds = cgWindowId.spaces()
310310
window.spaceIds = spaceIds
311-
window.spaceIndexes = spaceIds.map { spaceId in Spaces.idsAndIndexes.first { $0.0 == spaceId }!.1 }
311+
window.spaceIndexes = spaceIds.compactMap { spaceId in Spaces.idsAndIndexes.first { $0.0 == spaceId }?.1 }
312312
window.isOnAllSpaces = spaceIds.count > 1
313313
}
314314
}

src/logic/events/ScreensEvents.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ class ScreensEvents {
77

88
@objc private static func handleEvent(_ notification: Notification) {
99
Logger.debug(notification.name.rawValue)
10+
Spaces.refresh()
11+
// a screen added or removed, or screen resolution change can mess up layout; we reset components
12+
App.app.resetPreferencesDependentComponents()
1013
// a screen added or removed can shuffle windows around Spaces; we refresh them
1114
App.app.refreshOpenUi(Windows.list, .refreshUiAfterExternalEvent)
1215
Logger.info("screens", NSScreen.screens.map { ($0.uuid() ?? "nil" as CFString, $0.frame) })
1316
Logger.info("spaces", Spaces.screenSpacesMap)
1417
Logger.info("current space", Spaces.currentSpaceIndex, Spaces.currentSpaceId)
15-
// a screen added or removed, or screen resolution change can mess up layout; we reset components
16-
App.app.resetPreferencesDependentComponents()
1718
}
1819
}

0 commit comments

Comments
 (0)