Repository navigation
Expand file tree
/
Copy pathSettingsView.swift
More file actions
64 lines (62 loc) · 3.19 KB
/
Copy pathSettingsView.swift
File metadata and controls
64 lines (62 loc) · 3.19 KB
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
import SwiftUI
import UserNotifications
/// PCs this iPhone is trusted by (switch, add, forget), alerts, and the connection.
struct SettingsView: View {
@ObservedObject var model: AppModel
let switchTo: (PC) -> Void
let addPC: () -> Void
@State private var pcs = PC.all()
@AppStorage("alertWaiting") private var alertWaiting = true
@AppStorage("alertDone") private var alertDone = true
@State private var notificationsOff = false
var body: some View {
NavigationStack {
List {
Section {
ForEach(pcs) { pc in
Button { switchTo(pc) } label: {
HStack {
Image(systemName: "desktopcomputer")
VStack(alignment: .leading) {
Text(pc.name).foregroundStyle(.primary)
Text(pc.lan.map { "Wi-Fi \(URL(string: $0)?.host() ?? $0) · share" } ?? "share")
.font(.caption).foregroundStyle(.secondary)
}
Spacer()
if pc.id == PC.current?.id { Image(systemName: "checkmark").foregroundStyle(Palette.accent) }
}
}
.swipeActions {
Button("Forget", role: .destructive) { PC.remove(pc.id); pcs = PC.all() }
}
}
Button(action: addPC) { Label("Add a PC", systemImage: "qrcode.viewfinder") }
} header: { Text("Computers") } footer: {
Text("Each PC trusts this device once: after that, `sd share` on it is found without a QR code or approval. With iCloud Keychain on, your other iPhone or iPad (same Apple ID) gets the same PCs; each still logs in with the password.")
}
Section {
Toggle("When an agent needs you", isOn: $alertWaiting)
Toggle("When an agent finishes", isOn: $alertDone)
if notificationsOff {
Button("Notifications are off: open Settings") {
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
}
}
} header: { Text("Alerts") } footer: {
Text("With sound. They ring while shelldeck is open or was just in use; a locked phone would need push, which needs a paid Apple developer account.")
}
Section("Connection") {
LabeledContent("Via", value: model.server.isTunnel ? "share (Cloudflare)" : "home Wi-Fi")
LabeledContent("Address", value: model.server.base.host() ?? "")
}
}
.scrollContentBackground(.hidden)
.background(Palette.background)
.navigationTitle("Settings")
.task {
pcs = PC.all()
notificationsOff = await UNUserNotificationCenter.current().notificationSettings().authorizationStatus == .denied
}
}
}
}