@@ -2,37 +2,6 @@ import Cocoa
22import Foundation
33import ApplicationServices
44
5- protocol WindowInspector : AnyObject {
6- var documentURL : URL ? { get }
7- var workspaceURL : URL ? { get }
8- var projectURL : URL ? { get }
9- var isMainWorkWindow : Bool { get }
10-
11- func refresh( )
12- }
13-
14- protocol EditorStrategy {
15- var displayName : String { get }
16- var bundleIdentifier : String { get }
17-
18- func shouldMonitor( _ app: NSRunningApplication ) -> Bool
19- func createWindowInspector( processId: pid_t , windowElement: AXUIElement ) -> WindowInspector ?
20- }
21-
22- struct AppInstance {
23- let app : NSRunningApplication
24- let strategy : EditorStrategy
25- var windowInspector : WindowInspector ?
26-
27- var displayName : String {
28- strategy. displayName
29- }
30-
31- var processId : pid_t {
32- app. processIdentifier
33- }
34- }
35-
365@MainActor
376class AppMonitor : ObservableObject {
387 @Published var monitoredApps : [ String : AppInstance ] = [ : ]
@@ -91,15 +60,19 @@ class AppMonitor: ObservableObject {
9160 object: nil ,
9261 queue: . main
9362 ) { [ weak self] notification in
94- self ? . handleApplicationActivated ( notification)
63+ Task { @MainActor in
64+ self ? . handleApplicationActivated ( notification)
65+ }
9566 }
9667
9768 NotificationCenter . default. addObserver (
9869 forName: NSWorkspace . didTerminateApplicationNotification,
9970 object: nil ,
10071 queue: . main
10172 ) { [ weak self] notification in
102- self ? . handleApplicationTerminated ( notification)
73+ Task { @MainActor in
74+ self ? . handleApplicationTerminated ( notification)
75+ }
10376 }
10477 }
10578
0 commit comments