Commit c75305d4c5
c75305d4c5208ecfcde94c36d49ba08065581fcb
parent: 59d401dca1
Unsigned
cmc <hello@cleberg.net> · 2026-10-20 23:49 UTC
Live Activity previews and debug sample activities (!70)
- Xcode previews for the launch, event, pass and eclipse Live Activities: Lock Screen, and Dynamic Island compact, minimal and expanded. Launch previews show Go and Hold; event previews show two mission phases. Sample data and previews are inside `#if DEBUG`.
- `SampleActivitiesSection` (Debug only) at the bottom of Settings: a pass rising in 2 minutes, a launch at T−5 minutes, an eclipse with C1 in 3 minutes and C2 4 minutes later, and "End all sample activities". Uses the real attribute types and the same `Activity.request` and stale dates as the immediate-start branch of each follow path. Samples are named "Test" / "Test rocket" / "Test site".
Tests: `swift test` and server `npm test` pass. UI accessibility audit, origin/main vs this branch: Settings 3/3, System 7/7, Sun 3/3, News & launches 21/21, Library 14/14, Saturn 13/13, Sky 0/4. The Sky issues (Explore contrast, "Chicago" and the debug draw-stats line) are existing elements; the baseline run audited Sky before it had rendered. Release build contains none of the sample or preview strings.
Layout: unified · split
App/Sources/SampleActivities.swift
added
+76
| @@ -0,0 +1,76 @@ |
| |
1 | #if DEBUG |
| |
2 | import ActivityKit |
| |
3 | import SwiftUI |
| |
4 | |
| |
5 | /// Starts Live Activities a few minutes out, to check the Lock Screen and Dynamic Island without waiting |
| |
6 | /// for a real pass, launch or eclipse. Debug builds only. |
| |
7 | struct SampleActivitiesSection: View { |
| |
8 | @State private var message: String? |
| |
9 | |
| |
10 | var body: some View { |
| |
11 | Section { |
| |
12 | Button("Pass rising in 2 minutes") { startPass() } |
| |
13 | Button("Launch at T−5 minutes") { startLaunch() } |
| |
14 | Button("Eclipse, first contact in 3 minutes") { startEclipse() } |
| |
15 | Button("End all sample activities", role: .destructive) { Task { await endAll() } } |
| |
16 | if let message { |
| |
17 | Text(message).font(.footnote).foregroundStyle(.secondary) |
| |
18 | } |
| |
19 | } header: { |
| |
20 | Text("Sample Live Activities") |
| |
21 | } footer: { |
| |
22 | Text("Debug builds only. Samples are named Test.") |
| |
23 | } |
| |
24 | } |
| |
25 | |
| |
26 | private func startPass() { |
| |
27 | let rise = Date.now.addingTimeInterval(120) |
| |
28 | let attributes = PassActivityAttributes(name: "Test", rise: rise, peak: rise.addingTimeInterval(180), |
| |
29 | set: rise.addingTimeInterval(360), riseAzimuth: 236, setAzimuth: 52, |
| |
30 | maxAltitude: 64, visible: true) |
| |
31 | request(attributes, ActivityContent(state: .init(), staleDate: attributes.set.addingTimeInterval(60))) |
| |
32 | } |
| |
33 | |
| |
34 | private func startLaunch() { |
| |
35 | let attributes = LaunchActivityAttributes(launchID: "sample", rocket: "Test rocket", mission: "Test launch", |
| |
36 | location: "Sample pad") |
| |
37 | let net = Date.now.addingTimeInterval(300) |
| |
38 | request(attributes, ActivityContent(state: .init(net: net, status: "Go"), staleDate: net.addingTimeInterval(3600))) |
| |
39 | } |
| |
40 | |
| |
41 | private func startEclipse() { |
| |
42 | let c1 = Date.now.addingTimeInterval(180) |
| |
43 | let attributes = EclipseActivityAttributes( |
| |
44 | kind: "Total", site: "Test site", c1: c1, c2: c1.addingTimeInterval(240), peak: c1.addingTimeInterval(330), |
| |
45 | c3: c1.addingTimeInterval(420), c4: c1.addingTimeInterval(900), timeZone: TimeZone.current.identifier |
| |
46 | ) |
| |
47 | request(attributes, ActivityContent(state: .init(), staleDate: attributes.c4)) |
| |
48 | } |
| |
49 | |
| |
50 | private func request<A: ActivityAttributes>(_ attributes: A, _ content: ActivityContent<A.ContentState>) { |
| |
51 | guard ActivityAuthorizationInfo().areActivitiesEnabled else { |
| |
52 | message = "Live Activities are turned off for Moonrise in Settings." |
| |
53 | return |
| |
54 | } |
| |
55 | do { |
| |
56 | _ = try Activity.request(attributes: attributes, content: content) |
| |
57 | message = nil |
| |
58 | } catch { |
| |
59 | message = "Couldn't start it: \(error.localizedDescription)" |
| |
60 | } |
| |
61 | } |
| |
62 | |
| |
63 | private func endAll() async { |
| |
64 | for a in Activity<PassActivityAttributes>.activities where a.attributes.name == "Test" { |
| |
65 | await a.end(nil, dismissalPolicy: .immediate) |
| |
66 | } |
| |
67 | for a in Activity<LaunchActivityAttributes>.activities where a.attributes.launchID == "sample" { |
| |
68 | await a.end(nil, dismissalPolicy: .immediate) |
| |
69 | } |
| |
70 | for a in Activity<EclipseActivityAttributes>.activities where a.attributes.site == "Test site" { |
| |
71 | await a.end(nil, dismissalPolicy: .immediate) |
| |
72 | } |
| |
73 | message = nil |
| |
74 | } |
| |
75 | } |
| |
76 | #endif |
App/Sources/SettingsScreen.swift
+3
| @@ -150,6 +150,9 @@ struct SettingsScreen: View { |
| 150 | NavigationLink("Credits and licences") { CreditsScreen() } |
150 | NavigationLink("Credits and licences") { CreditsScreen() } |
| 151 | Link("Privacy policy", destination: privacyPolicyURL) |
151 | Link("Privacy policy", destination: privacyPolicyURL) |
| 152 | } |
152 | } |
| |
153 | #if DEBUG |
| |
154 | SampleActivitiesSection() |
| |
155 | #endif |
| 153 | } |
156 | } |
| 154 | .navigationTitle("Settings") |
157 | .navigationTitle("Settings") |
| 155 | .navigationBarTitleDisplayMode(.inline) |
158 | .navigationBarTitleDisplayMode(.inline) |
App/Widgets/EclipseLiveActivity.swift
+37
| @@ -127,3 +127,40 @@ private func contacts(_ a: EclipseActivityAttributes) -> [(String, Date)] { |
| 127 | private func clock(_ date: Date, _ a: EclipseActivityAttributes) -> String { |
127 | private func clock(_ date: Date, _ a: EclipseActivityAttributes) -> String { |
| 128 | date.formatted(Date.FormatStyle(date: .omitted, time: .standard, timeZone: a.timeZone.flatMap(TimeZone.init(identifier:)) ?? .gmt)) |
128 | date.formatted(Date.FormatStyle(date: .omitted, time: .standard, timeZone: a.timeZone.flatMap(TimeZone.init(identifier:)) ?? .gmt)) |
| 129 | } |
129 | } |
| |
130 | |
| |
131 | #if DEBUG |
| |
132 | private extension EclipseActivityAttributes { |
| |
133 | /// A long totality, as at Luxor on 2 August 2027, with first contact 20 minutes from now. |
| |
134 | static var preview: Self { |
| |
135 | let c1 = Date.now.addingTimeInterval(20 * 60) |
| |
136 | return EclipseActivityAttributes( |
| |
137 | kind: "Total", site: "Luxor", c1: c1, c2: c1.addingTimeInterval(3_655), peak: c1.addingTimeInterval(3_844), |
| |
138 | c3: c1.addingTimeInterval(4_033), c4: c1.addingTimeInterval(7_590), timeZone: "Africa/Cairo" |
| |
139 | ) |
| |
140 | } |
| |
141 | } |
| |
142 | |
| |
143 | #Preview("Lock Screen", as: .content, using: EclipseActivityAttributes.preview) { |
| |
144 | EclipseLiveActivity() |
| |
145 | } contentStates: { |
| |
146 | EclipseActivityAttributes.ContentState() |
| |
147 | } |
| |
148 | |
| |
149 | #Preview("Compact", as: .dynamicIsland(.compact), using: EclipseActivityAttributes.preview) { |
| |
150 | EclipseLiveActivity() |
| |
151 | } contentStates: { |
| |
152 | EclipseActivityAttributes.ContentState() |
| |
153 | } |
| |
154 | |
| |
155 | #Preview("Minimal", as: .dynamicIsland(.minimal), using: EclipseActivityAttributes.preview) { |
| |
156 | EclipseLiveActivity() |
| |
157 | } contentStates: { |
| |
158 | EclipseActivityAttributes.ContentState() |
| |
159 | } |
| |
160 | |
| |
161 | #Preview("Expanded", as: .dynamicIsland(.expanded), using: EclipseActivityAttributes.preview) { |
| |
162 | EclipseLiveActivity() |
| |
163 | } contentStates: { |
| |
164 | EclipseActivityAttributes.ContentState() |
| |
165 | } |
| |
166 | #endif |
App/Widgets/EventLiveActivity.swift
+43
| @@ -84,3 +84,46 @@ private struct EventActivityView: View { |
| 84 | .padding(16) |
84 | .padding(16) |
| 85 | } |
85 | } |
| 86 | } |
86 | } |
| |
87 | |
| |
88 | #if DEBUG |
| |
89 | private extension EventActivityAttributes { |
| |
90 | static var preview: Self { |
| |
91 | EventActivityAttributes(eventID: "preview", title: "Artemis II", launch: .now.addingTimeInterval(-2.5 * 86_400)) |
| |
92 | } |
| |
93 | } |
| |
94 | |
| |
95 | private extension EventActivityAttributes.ContentState { |
| |
96 | static var outbound: Self { |
| |
97 | .init(phase: "Outbound coast", next: "Lunar flyby", nextAt: .now.addingTimeInterval(30 * 3600), distanceKm: 287_400) |
| |
98 | } |
| |
99 | static var flyby: Self { |
| |
100 | .init(phase: "Lunar flyby", next: "Return coast", nextAt: .now.addingTimeInterval(3 * 3600), distanceKm: 401_800) |
| |
101 | } |
| |
102 | } |
| |
103 | |
| |
104 | #Preview("Lock Screen", as: .content, using: EventActivityAttributes.preview) { |
| |
105 | EventLiveActivity() |
| |
106 | } contentStates: { |
| |
107 | EventActivityAttributes.ContentState.outbound |
| |
108 | EventActivityAttributes.ContentState.flyby |
| |
109 | } |
| |
110 | |
| |
111 | #Preview("Compact", as: .dynamicIsland(.compact), using: EventActivityAttributes.preview) { |
| |
112 | EventLiveActivity() |
| |
113 | } contentStates: { |
| |
114 | EventActivityAttributes.ContentState.outbound |
| |
115 | } |
| |
116 | |
| |
117 | #Preview("Minimal", as: .dynamicIsland(.minimal), using: EventActivityAttributes.preview) { |
| |
118 | EventLiveActivity() |
| |
119 | } contentStates: { |
| |
120 | EventActivityAttributes.ContentState.outbound |
| |
121 | } |
| |
122 | |
| |
123 | #Preview("Expanded", as: .dynamicIsland(.expanded), using: EventActivityAttributes.preview) { |
| |
124 | EventLiveActivity() |
| |
125 | } contentStates: { |
| |
126 | EventActivityAttributes.ContentState.outbound |
| |
127 | EventActivityAttributes.ContentState.flyby |
| |
128 | } |
| |
129 | #endif |
App/Widgets/LaunchLiveActivity.swift
+42
| @@ -101,3 +101,45 @@ private struct LaunchActivityView: View { |
| 101 | private func countdown(_ net: Date) -> Text { |
101 | private func countdown(_ net: Date) -> Text { |
| 102 | net > .now ? Text(timerInterval: Date.now...net, countsDown: true) : Text(net, style: .timer) |
102 | net > .now ? Text(timerInterval: Date.now...net, countsDown: true) : Text(net, style: .timer) |
| 103 | } |
103 | } |
| |
104 | |
| |
105 | #if DEBUG |
| |
106 | private extension LaunchActivityAttributes { |
| |
107 | static var preview: Self { |
| |
108 | LaunchActivityAttributes(launchID: "preview", rocket: "Falcon 9 Block 5", mission: "Starlink Group 10-12", |
| |
109 | location: "SLC-40, Cape Canaveral SFS, Florida") |
| |
110 | } |
| |
111 | } |
| |
112 | |
| |
113 | private extension LaunchActivityAttributes.ContentState { |
| |
114 | static var go: Self { .init(net: .now.addingTimeInterval(12 * 60), status: "Go") } |
| |
115 | static var hold: Self { .init(net: .now.addingTimeInterval(12 * 60), status: "Hold") } |
| |
116 | } |
| |
117 | |
| |
118 | #Preview("Lock Screen", as: .content, using: LaunchActivityAttributes.preview) { |
| |
119 | LaunchLiveActivity() |
| |
120 | } contentStates: { |
| |
121 | LaunchActivityAttributes.ContentState.go |
| |
122 | LaunchActivityAttributes.ContentState.hold |
| |
123 | } |
| |
124 | |
| |
125 | #Preview("Compact", as: .dynamicIsland(.compact), using: LaunchActivityAttributes.preview) { |
| |
126 | LaunchLiveActivity() |
| |
127 | } contentStates: { |
| |
128 | LaunchActivityAttributes.ContentState.go |
| |
129 | LaunchActivityAttributes.ContentState.hold |
| |
130 | } |
| |
131 | |
| |
132 | #Preview("Minimal", as: .dynamicIsland(.minimal), using: LaunchActivityAttributes.preview) { |
| |
133 | LaunchLiveActivity() |
| |
134 | } contentStates: { |
| |
135 | LaunchActivityAttributes.ContentState.go |
| |
136 | LaunchActivityAttributes.ContentState.hold |
| |
137 | } |
| |
138 | |
| |
139 | #Preview("Expanded", as: .dynamicIsland(.expanded), using: LaunchActivityAttributes.preview) { |
| |
140 | LaunchLiveActivity() |
| |
141 | } contentStates: { |
| |
142 | LaunchActivityAttributes.ContentState.go |
| |
143 | LaunchActivityAttributes.ContentState.hold |
| |
144 | } |
| |
145 | #endif |
App/Widgets/PassLiveActivity.swift
+34
| @@ -126,3 +126,37 @@ private func summary(_ pass: PassActivityAttributes) -> String { |
| 126 | } |
126 | } |
| 127 | |
127 | |
| 128 | private func time(_ date: Date) -> String { date.formatted(date: .omitted, time: .shortened) } |
128 | private func time(_ date: Date) -> String { date.formatted(date: .omitted, time: .shortened) } |
| |
129 | |
| |
130 | #if DEBUG |
| |
131 | private extension PassActivityAttributes { |
| |
132 | static var preview: Self { |
| |
133 | PassActivityAttributes(name: "ISS", rise: .now.addingTimeInterval(4 * 60), peak: .now.addingTimeInterval(7.5 * 60), |
| |
134 | set: .now.addingTimeInterval(11 * 60), riseAzimuth: 236, setAzimuth: 52, maxAltitude: 64, |
| |
135 | visible: true) |
| |
136 | } |
| |
137 | } |
| |
138 | |
| |
139 | #Preview("Lock Screen", as: .content, using: PassActivityAttributes.preview) { |
| |
140 | PassLiveActivity() |
| |
141 | } contentStates: { |
| |
142 | PassActivityAttributes.ContentState() |
| |
143 | } |
| |
144 | |
| |
145 | #Preview("Compact", as: .dynamicIsland(.compact), using: PassActivityAttributes.preview) { |
| |
146 | PassLiveActivity() |
| |
147 | } contentStates: { |
| |
148 | PassActivityAttributes.ContentState() |
| |
149 | } |
| |
150 | |
| |
151 | #Preview("Minimal", as: .dynamicIsland(.minimal), using: PassActivityAttributes.preview) { |
| |
152 | PassLiveActivity() |
| |
153 | } contentStates: { |
| |
154 | PassActivityAttributes.ContentState() |
| |
155 | } |
| |
156 | |
| |
157 | #Preview("Expanded", as: .dynamicIsland(.expanded), using: PassActivityAttributes.preview) { |
| |
158 | PassLiveActivity() |
| |
159 | } contentStates: { |
| |
160 | PassActivityAttributes.ContentState() |
| |
161 | } |
| |
162 | #endif |