-
Notifications
You must be signed in to change notification settings - Fork 43
/
WindowView.swift
97 lines (92 loc) · 2.78 KB
/
WindowView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// WindowView.swift
// visionOS
//
// Created by Saagar Jha on 10/10/23.
//
import SwiftUI
struct WindowView: View {
let remote: Remote
let window: Window
@State
var frame: Frame?
let eventView = EventView()
let decoder = VideoDecoder()
var body: some View {
Group {
if let frame {
GeometryReader { geometry in
FrameView(frame: frame)
.overlay {
eventView
.task {
do {
for await event in eventView.coordinator.scrollStream {
switch event {
case .began:
_ = try await remote._scrollBegan(parameters: .init(windowID: window.windowID))
case .changed(let translation):
_ = try await remote._scrollChanged(parameters: .init(windowID: window.windowID, x: translation.x, y: translation.y))
case .ended:
_ = try await remote._scrollEnded(parameters: .init(windowID: window.windowID))
}
}
} catch {}
}
.task {
do {
for await event in eventView.coordinator.dragStream {
switch event {
case .began(let translation):
_ = try await remote._dragBegan(parameters: .init(windowID: window.windowID, x: translation.x, y: translation.y))
case .changed(let translation):
_ = try await remote._dragChanged(parameters: .init(windowID: window.windowID, x: translation.x, y: translation.y))
case .ended(let translation):
_ = try await remote._dragEnded(parameters: .init(windowID: window.windowID, x: translation.x, y: translation.y))
}
}
} catch {}
}
.task {
do {
for await (key, down) in eventView.view.keyStream {
_ = try await remote._typed(parameters: .init(windowID: window.windowID, key: key, down: down))
}
} catch {}
}
}
.onTapGesture { location in
eventView.view.becomeFirstResponder()
Task {
_ = try await remote._clicked(parameters: .init(windowID: window.windowID, x: location.x / geometry.size.width, y: location.y / geometry.size.height))
}
}
.onContinuousHover(coordinateSpace: .local) {
switch $0 {
case .active(let location):
Task {
do {
_ = try await remote._mouseMoved(parameters: .init(windowID: window.windowID, x: location.x / geometry.size.width, y: location.y / geometry.size.height))
} catch {}
}
default:
break
}
}
.onAppear {
eventView.view.becomeFirstResponder()
}
}
} else {
Text("Loading…")
}
}
.task {
do {
for await frame in try await remote.startCasting(for: window.windowID) {
self.frame = frame
}
} catch {}
}
}
}