-
Notifications
You must be signed in to change notification settings - Fork 43
/
WindowPickerView.swift
58 lines (53 loc) · 1.19 KB
/
WindowPickerView.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
//
// WindowPickerView.swift
// visionOS
//
// Created by Saagar Jha on 10/10/23.
//
import SwiftUI
struct WindowPickerView: View {
let remote: Remote
@State
var windows: [Window]?
@State
var filter: String = ""
@Binding
var selectedWindow: Window?
var body: some View {
NavigationStack {
if let windows {
ScrollView {
LazyVGrid(
columns: [GridItem(), GridItem()],
spacing: 20,
content: {
let filteredWindows = windows.filter {
filter.isEmpty || $0.app.localizedStandardContains(filter) || $0.title?.localizedStandardContains(filter) ?? false
}
ForEach(filteredWindows) { window in
WindowPreviewView(remote: remote, window: window, selectedWindow: $selectedWindow)
}
}
)
.padding(20)
}
.navigationTitle("Select a window.")
.searchable(text: $filter)
} else {
Text("Loading windows…")
}
}
.task {
do {
while true {
windows = try await remote.windows.filter {
!($0.title?.isEmpty ?? true) && $0.windowLayer == 0 /* NSWindow.Level.normal */
}.sorted {
$0.windowID < $1.windowID
}
try await Task.sleep(for: .seconds(1))
}
} catch {}
}
}
}