Skip to content

Commit 024fcca

Browse files
committed
Fix overlay window destruction
1 parent 0ca850c commit 024fcca

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

Core/Sources/Service/ScheduledCleaner.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public final class ScheduledCleaner {
6161
}.result
6262
await workspace.cleanUp(availableTabs: [])
6363
await service.workspacePool.removeWorkspace(url: url)
64-
await service.overlayWindowController.removeController(for: url)
6564
} else {
6665
let tabs = (workspaceInfos[.url(url)]?.tabs ?? [])
6766
.union(workspaceInfos[.unknown]?.tabs ?? [])

OverlayWindow/Sources/OverlayWindow/IDEWorkspaceWindowOverlayWindowController.swift

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ final class IDEWorkspaceWindowOverlayWindowController {
2929
let inspector: WorkspaceXcodeWindowInspector
3030
let contentProviders: [any IDEWorkspaceWindowOverlayWindowControllerContentProvider]
3131
let maskPanel: OverlayPanel
32-
private var isDestroyed: Bool = false
3332
private var axNotificationTask: Task<Void, Never>?
3433

3534
init(
@@ -89,14 +88,10 @@ final class IDEWorkspaceWindowOverlayWindowController {
8988

9089
deinit {
9190
axNotificationTask?.cancel()
92-
_ = withExtendedLifetime(self) {
93-
Task { @MainActor in
94-
precondition(
95-
!self.isDestroyed,
96-
"IDEWorkspaceWindowOverlayWindowController should be destroyed before deinit"
97-
)
98-
}
99-
}
91+
}
92+
93+
var isWindowClosed: Bool {
94+
inspector.isInvalid
10095
}
10196

10297
func access() {
@@ -116,12 +111,10 @@ final class IDEWorkspaceWindowOverlayWindowController {
116111
}
117112

118113
func destroy() {
119-
axNotificationTask?.cancel()
120114
maskPanel.close()
121115
for contentProvider in contentProviders {
122116
contentProvider.destroy()
123117
}
124-
isDestroyed = true
125118
}
126119
}
127120

OverlayWindow/Sources/OverlayWindow/OverlayWindowController.swift

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public final class OverlayWindowController {
1717
var ideWindowOverlayWindowControllers: [URL: IDEWorkspaceWindowOverlayWindowController] = [:]
1818
var updateWindowStateTask: Task<Void, Error>?
1919

20-
@MainActor
2120
lazy var fullscreenDetector = {
2221
let it = NSWindow(
2322
contentRect: .zero,
@@ -40,17 +39,6 @@ public final class OverlayWindowController {
4039
observeEvents()
4140
_ = fullscreenDetector
4241
}
43-
44-
public func removeController(for url: URL) {
45-
if let controller = ideWindowOverlayWindowControllers[url] {
46-
controller.destroy()
47-
ideWindowOverlayWindowControllers.removeValue(forKey: url)
48-
}
49-
}
50-
51-
public func removeAllControllers() {
52-
ideWindowOverlayWindowControllers.removeAll()
53-
}
5442

5543
public nonisolated static func registerIDEWorkspaceWindowOverlayWindowControllerContentProviderFactory(
5644
_ factory: @escaping IDEWorkspaceWindowOverlayWindowControllerContentProviderFactory
@@ -110,8 +98,17 @@ private extension OverlayWindowController {
11098
defer { self.observeWindowChange() }
11199

112100
guard XcodeInspector.shared.activeApplication?.isXcode ?? false else {
113-
for (_, controller) in self.ideWindowOverlayWindowControllers {
114-
controller.dim()
101+
var closedControllers: [URL] = []
102+
for (url, controller) in self.ideWindowOverlayWindowControllers {
103+
if controller.isWindowClosed {
104+
controller.dim()
105+
closedControllers.append(url)
106+
} else {
107+
controller.dim()
108+
}
109+
}
110+
for url in closedControllers {
111+
self.removeIDEOverlayWindowController(for: url)
115112
}
116113
return
117114
}
@@ -169,6 +166,13 @@ private extension OverlayWindowController {
169166
newController.access()
170167
ideWindowOverlayWindowControllers[workspaceURL] = newController
171168
}
169+
170+
func removeIDEOverlayWindowController(for workspaceURL: URL) {
171+
if let controller = ideWindowOverlayWindowControllers[workspaceURL] {
172+
controller.destroy()
173+
}
174+
ideWindowOverlayWindowControllers[workspaceURL] = nil
175+
}
172176

173177
func handleSpaceChange() async {
174178
let windowInspector = XcodeInspector.shared.focusedWindow

Tool/Sources/XcodeInspector/XcodeWindowInspector.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public class XcodeWindowInspector {
1313
self.uiElement = uiElement
1414
uiElement.setMessagingTimeout(2)
1515
}
16+
17+
public var isInvalid: Bool {
18+
uiElement.parent == nil
19+
}
1620
}
1721

1822
@XcodeInspectorActor

0 commit comments

Comments
 (0)