Skip to content
Source
Sign inSign up
samwillis/jerry
Open History to see the last commit

JOLSettingsView.swift

101 lines6.9 KB

1import SwiftUI
2​
3struct JOLSettingsView: View {
4 @ObservedObject var connection: JOLController
5 @State private var confirmHistory = false
6 @State private var confirmDetails = false
7 @State private var confirmPhotos = false
8 var body: some View {
9 VStack(alignment: .leading, spacing: 18) {
10 Text("Your explorer. On line.").font(.custom("Caveat", size: 27))
11 Text("Read Jerry’s journals and send directions from your browser. Choose a JOL server you trust—or keep everything on this Mac.")
12 .font(.system(size: 12)).foregroundStyle(Color(nsColor: NotebookTheme.faded))
13 if connection.connected {
14 GroupBox {
15 VStack(alignment: .leading, spacing: 10) {
16 Text(connection.manifest?.name ?? "Jerry On Line").font(.headline)
17 Text(connection.manifest?.origin ?? connection.address).font(.system(size: 12))
18 Text(connection.status).font(.system(size: 12)).accessibilityLabel("JOL status: " + connection.status)
19 if let synced = connection.lastSync { Text("Last synced \(synced, style: .relative) ago").font(.system(size: 11)).foregroundStyle(.secondary) }
20 HStack {
21 Button("Open JOL") { connection.openWebsite() }
22 Button("Disconnect") { connection.disconnect() }
23 }
24 }.frame(maxWidth: .infinity, alignment: .leading).padding(8)
25 }
26 GroupBox {
27 VStack(alignment: .leading, spacing: 10) {
28 Toggle("Allow remote missions", isOn: Binding(get: { connection.remoteArmed }, set: { connection.setRemoteArmed($0) }))
29 Text("Remote directions use this Mac and its AI connection. Taking manual control pauses remote missions. Enable them again here when you’re ready, then close Settings.")
30 .font(.system(size: 12)).foregroundStyle(.secondary)
31 }.padding(8)
32 }
33 GroupBox("Journal sharing") {
34 VStack(alignment: .leading, spacing: 10) {
35 Text("Sharing notes\(connection.sharePhotos || connection.backfillPhotos ? ", photographs" : "")\(connection.shareDetails || connection.backfillDetails ? ", and technical details" : "").")
36 if connection.includeHistory {
37 Text("Older expeditions are included.").foregroundStyle(.secondary)
38 } else {
39 Button("Share Older Expeditions…") { confirmHistory = true }
40 }
41 if !connection.shareDetails && !connection.backfillDetails {
42 Button("Share Technical Details…") { confirmDetails = true }
43 .disabled(connection.working)
44 }
45 if !connection.sharePhotos && !connection.backfillPhotos {
46 Button("Share Journal Photographs…") { confirmPhotos = true }
47 .disabled(connection.working)
48 }
49 if let issue = connection.sharingIssue {
50 Text(issue).font(.system(size: 11)).foregroundStyle(.secondary)
51 }
52 }.frame(maxWidth: .infinity, alignment: .leading).padding(8)
53 }
54 } else {
55 VStack(alignment: .leading, spacing: 10) {
56 TextField("https://jol.example.com", text: $connection.address).textFieldStyle(.roundedBorder)
57 .disabled(connection.working).onSubmit { connection.checkServer() }.accessibilityLabel("JOL server address")
58 .onChange(of: connection.address) { _, _ in connection.serverAddressChanged() }
59 if connection.manifest == nil {
60 Button("Find Server") { connection.checkServer() }.disabled(connection.working || connection.address.isEmpty)
61 } else {
62 Text(connection.manifest?.name ?? "Jerry On Line").font(.headline)
63 Text(connection.manifest?.origin ?? "").font(.system(size: 12)).foregroundStyle(.secondary)
64 Toggle("Share journal photographs", isOn: $connection.sharePhotos)
65 Toggle("Share technical details", isOn: $connection.shareDetails)
66 Toggle("Also share existing expeditions", isOn: $connection.includeHistory)
67 Text("New expeditions are shared when connected. Photographs and details can contain screen content. Your server’s operator can read shared journals; enabling remote missions also trusts that server to send directions.")
68 .font(.system(size: 11)).foregroundStyle(.secondary)
69 HStack {
70 Button("Connect in Browser") { connection.connect() }.disabled(connection.working)
71 if connection.working { Button("Cancel") { connection.cancelSignIn() } }
72 else { Button("Change Server") { connection.checkServer() } }
73 }
74 }
75 Text(connection.status).font(.system(size: 12)).fixedSize(horizontal: false, vertical: true)
76 }.padding(14).background(Color(nsColor: NotebookTheme.leather).opacity(0.045), in: RoundedRectangle(cornerRadius: 7))
77 Text("AI credentials stay on this Mac. Disconnecting JOL never stops local journal saving or removes your AI connection.")
78 .font(.system(size: 11)).foregroundStyle(.secondary)
79 }
80 }
81 .frame(width: 532, alignment: .leading)
82 .foregroundStyle(Color(nsColor: NotebookTheme.ink))
83 .tint(Color(nsColor: NotebookTheme.ink))
84 .font(.system(size: 13))
85 .confirmationDialog("Share older expeditions?", isPresented: $confirmHistory) {
86 Button("Share Older Expeditions") { connection.shareOlderExpeditions() }
87 } message: {
88 Text("Upload expeditions saved on this Mac before you connected, using your current sharing choices.")
89 }
90 .confirmationDialog("Share technical details?", isPresented: $confirmDetails) {
91 Button("Share Technical Details") { connection.shareTechnicalDetails() }
92 } message: {
93 Text("Include technical details from past and future shared expeditions. Details may contain screen content.")
94 }
95 .confirmationDialog("Share journal photographs?", isPresented: $confirmPhotos) {
96 Button("Share Journal Photographs") { connection.shareJournalPhotos() }
97 } message: {
98 Text("Upload photographs from expeditions you share with this JOL server, including photographs Jerry has already taken. Photographs can contain screen content.")
99 }
100 }