Skip to content

Commit da481a6

Browse files
Merge pull request #2 from Alexander5015/sudo
Refactor MacroVisionKit: Introduce FullScreenMonitor Actor for Real-Time Full Screen Space Detection
2 parents 5e8b06c + b7b4803 commit da481a6

File tree

10 files changed

+304
-375
lines changed

10 files changed

+304
-375
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.build
22
.swiftpm
33
.vscode
4+
.DS_Store
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import Cocoa
2+
import MacroVisionKit
3+
4+
@MainActor
5+
@main
6+
final class FullScreenMonitorExampleApp: NSObject, NSApplicationDelegate {
7+
private var monitorTask: Task<Void, Never>?
8+
9+
static func main() {
10+
let app = NSApplication.shared
11+
let delegate = FullScreenMonitorExampleApp()
12+
app.delegate = delegate
13+
app.setActivationPolicy(.accessory)
14+
app.run()
15+
}
16+
17+
func applicationDidFinishLaunching(_ notification: Notification) {
18+
print("Listening for fullscreen space changes... (Press Ctrl+C to exit)")
19+
monitorTask = Task { [weak self] in
20+
guard let self = self else { return }
21+
let stream = await FullScreenMonitor.shared.spaceChanges()
22+
for await spaces in stream {
23+
self.render(spaces)
24+
}
25+
}
26+
}
27+
28+
func applicationWillTerminate(_ notification: Notification) {
29+
monitorTask?.cancel()
30+
}
31+
32+
private func render(_ spaces: [FullScreenMonitor.SpaceInfo]) {
33+
print("\n--- Fullscreen Spaces Updated ---")
34+
if spaces.isEmpty {
35+
print("No fullscreen applications detected.")
36+
} else {
37+
print("Detected fullscreen applications:")
38+
for space in spaces {
39+
let screenID = space.screenUUID ?? "Unknown"
40+
let screenName = FullScreenMonitor.shared.screen(for: space)?.localizedName ?? "Unknown"
41+
42+
let apps = space.runningApps.isEmpty ? "Unknown" : space.runningApps.joined(separator: ", ")
43+
print("- Screen UUID: \(screenID)")
44+
print("- Screen Name: \(screenName)")
45+
print("- Apps: \(apps)")
46+
}
47+
}
48+
fflush(stdout)
49+
}
50+
}

Examples/FullscreenDetectorExample.swift

Lines changed: 0 additions & 35 deletions
This file was deleted.

Package.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 6.1
22
import PackageDescription
33

44
let package = Package(
@@ -10,12 +10,16 @@ let package = Package(
1010
.library(
1111
name: "MacroVisionKit",
1212
targets: ["MacroVisionKit"]),
13+
.executable(
14+
name: "FullScreenMonitorExample",
15+
targets: ["FullScreenMonitorExample"]),
1316
],
1417
targets: [
1518
.target(
1619
name: "MacroVisionKit"),
17-
.testTarget(
18-
name: "MacroVisionKitTests",
19-
dependencies: ["MacroVisionKit"]),
20+
.executableTarget(
21+
name: "FullScreenMonitorExample",
22+
dependencies: ["MacroVisionKit"],
23+
path: "Examples"),
2024
]
2125
)

README.md

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Add the following dependency to your `Package.swift` file:
1818

1919
```swift
2020
dependencies: [
21-
.package(url: "https://github.com/TheBoredTeam/MacroVisionKit.git", from: "0.0.0")
21+
.package(url: "https://github.com/TheBoredTeam/MacroVisionKit.git", from: "0.2.0")
2222
]
2323
```
2424

@@ -29,39 +29,54 @@ dependencies: [
2929
```swift
3030
import MacroVisionKit
3131

32-
// Initialize the detector
33-
let detector = MacroVisionKit.shared
34-
let fullscreenApps = detector.detectFullscreenApps()
32+
// Initialize the monitor
33+
let monitor = FullScreenMonitor.shared
34+
35+
// Get current Full Screen apps
36+
let fullScreenApps = monitor.detectFullscreenApps()
3537

3638
// Process detection results
37-
fullscreenApps.forEach { appInfo in
38-
print(appInfo.debugDescription)
39+
fullScreenApps.forEach { spaceInfo in
40+
print(spaceInfo.debugDescription)
3941
}
4042
```
4143

42-
### Advanced Configuration
44+
### Real-time Updates
45+
46+
Use the `spaceChanges()` method to get an asynchronous stream of fullscreen space updates:
4347

4448
```swift
45-
// Configure detection parameters
46-
var config = MacroVisionKit.Configuration()
47-
config.sizeTolerance = 0.15 // 15% tolerance threshold
48-
config.includeSystemApps = true
49+
import MacroVisionKit
50+
51+
// Get the stream of space changes
52+
let monitor = FullScreenMonitor.shared
53+
let stream = await monitor.spaceChanges()
4954

50-
// Apply configuration
51-
MacroVisionKit.shared.configuration = config
55+
// Process updates asynchronously
56+
for await fullScreenSpaces in stream {
57+
print("Fullscreen spaces updated: \(fullScreenSpaces.count)")
58+
fullScreenSpaces.forEach { spaceInfo in
59+
print(spaceInfo.debugDescription)
60+
}
61+
}
5262
```
5363

54-
### Diagnostic Mode
64+
### Testing with the Example
5565

56-
```swift
57-
// Enable diagnostic output for detailed analysis
58-
let fullscreenApps = detector.detectFullscreenApps(debug: true)
59-
```
66+
To test the framework, you can run the included example application. First, ensure you have Swift installed on your macOS system.
67+
68+
1. Clone the repository:
69+
```bash
70+
git clone https://github.com/TheBoredTeam/MacroVisionKit.git
71+
cd MacroVisionKit
72+
```
6073

61-
## Technical Requirements
74+
2. Build and run the example:
75+
```bash
76+
swift run FullScreenMonitorExample
77+
```
6278

63-
- macOS 10.15 or later
64-
- Swift 5.0 or later
79+
3. The example will start monitoring for fullscreen space changes. Open some applications in fullscreen mode to see the detection in action. Press `Ctrl+C` to exit.
6580

6681
## License
6782

0 commit comments

Comments
 (0)