krz/moonrise

Night-sky companion for iPhone, Apple Watch and Vision Pro: what's up tonight, the Moon, planets, launches and missions, and a Library of the solar system. SwiftUI app with a Cloudflare Workers backend. astronomy cloudflare-workers ios night-sky space swiftui visionos watchos

Commit 1ee3c935aa

1ee3c935aacf6a3be0b957c6f7a38443f6e19915

parent: 21d86238a3

Unsigned

cmc <hello@cleberg.net> · 2026-10-22 01:58 UTC

ISS pass alerts: 15 minutes before each visible pass (!109)

Stacked on !108 (branch `widgets-controls`); merge !106–!108 first.

- Settings → "ISS passes" toggle (`issPassAlerts`, off by default) with its own permission message.
- `ISSPassNotifications`: up to 8 local notifications (`iss-pass-0…7`), 15 min before each visible ISS pass in `SkyModel.passes` (next 72 h). Body: rise time and direction, highest altitude and time, set time and direction.
- Rescheduled with the daily summary: Settings dismissed, place change, app active (`rescheduleSummary` → `rescheduleNotifications`).
- Nothing leaves the device. iOS builds. Not run on a device: notification permission needs a tap.

Layout: unified · split

App/Sources/ISSPassNotifications.swift added +37
@@ -0,0 +1,37 @@
1import SkyEngine
2import SwiftUI
3import UserNotifications
4
5/// Opt-in local notifications 15 minutes before each visible ISS pass in the next three days. Worked out on the
6/// device and replaced whenever the daily summary is.
7enum ISSPassNotifications {
8 static let ids = (0..<8).map { "iss-pass-\($0)" }
9 static let lead: TimeInterval = 15 * 60
10
11 @MainActor
12 static func reschedule(_ model: SkyModel) async {
13 let center = UNUserNotificationCenter.current()
14 center.removePendingNotificationRequests(withIdentifiers: ids)
15 guard UserDefaults.standard.bool(forKey: SettingsKey.issPasses) else { return }
16 await model.refreshPasses()
17 for (id, pass) in zip(ids, plan(model.passes)) {
18 let content = UNMutableNotificationContent()
19 content.title = "ISS pass in 15 minutes"
20 content.body = body(pass)
21 content.sound = .default
22 let trigger = UNTimeIntervalNotificationTrigger(timeInterval: pass.rise.timeIntervalSinceNow - lead, repeats: false)
23 try? await center.add(UNNotificationRequest(identifier: id, content: content, trigger: trigger))
24 }
25 }
26
27 /// Visible ISS passes whose alert time is still ahead, soonest first.
28 nonisolated static func plan(_ passes: [SatellitePass], now: Date = .now) -> [SatellitePass] {
29 passes.filter { $0.displayName == "ISS" && $0.visible && $0.rise.addingTimeInterval(-lead) > now }
30 .sorted { $0.rise < $1.rise }
31 }
32
33 nonisolated static func body(_ p: SatellitePass) -> String {
34 let t = { (d: Date) in d.formatted(date: .omitted, time: .shortened) }
35 return "Rises \(t(p.rise)) in the \(SkyEngine.compass(p.riseAzimuth)), highest \(Int(p.maxAltitude.rounded()))° at \(t(p.peak)), sets \(t(p.set)) in the \(SkyEngine.compass(p.setAzimuth))."
36 }
37}
App/Sources/SettingsScreen.swift +27
@@ -15,6 +15,8 @@ enum SettingsKey {
15 /// Whether the Sky tab is currently drawn in night mode (written by the Sky tab). 15 /// Whether the Sky tab is currently drawn in night mode (written by the Sky tab).
16 static let nightActive = "nightActive" 16 static let nightActive = "nightActive"
17 static let dailySummary = "dailySummary" 17 static let dailySummary = "dailySummary"
18 /// Local alerts 15 minutes before visible ISS passes.
19 static let issPasses = "issPassAlerts"
18 /// Sky culture id, or "western" for the IAU constellations. 20 /// Sky culture id, or "western" for the IAU constellations.
19 static let skyCulture = "skyCulture" 21 static let skyCulture = "skyCulture"
20 /// Minutes after local midnight. 22 /// Minutes after local midnight.
@@ -77,8 +79,10 @@ struct SettingsScreen: View {
77 @Environment(\.dismiss) private var dismiss 79 @Environment(\.dismiss) private var dismiss
78 @State private var alerts = AuroraAlerts.shared 80 @State private var alerts = AuroraAlerts.shared
79 @AppStorage(SettingsKey.dailySummary) private var dailySummary = false 81 @AppStorage(SettingsKey.dailySummary) private var dailySummary = false
82 @AppStorage(SettingsKey.issPasses) private var issPasses = false
80 @AppStorage(SettingsKey.dailySummaryMinutes) private var dailySummaryMinutes = DailySummaryNotifications.defaultMinutes 83 @AppStorage(SettingsKey.dailySummaryMinutes) private var dailySummaryMinutes = DailySummaryNotifications.defaultMinutes
81 @State private var summaryStatus: String? 84 @State private var summaryStatus: String?
85 @State private var issStatus: String?
82 @AppStorage(SettingsKey.cloudForecast) private var cloudForecast = false 86 @AppStorage(SettingsKey.cloudForecast) private var cloudForecast = false
83 var onChange: () -> Void 87 var onChange: () -> Void
84 88
@@ -130,6 +134,17 @@ struct SettingsScreen: View {
130 } footer: { 134 } footer: {
131 Text("A note each day with the Moon, the planets up that night, the best satellite pass and any events. It is worked out on this device; nothing is sent to our server.") 135 Text("A note each day with the Moon, the planets up that night, the best satellite pass and any events. It is worked out on this device; nothing is sent to our server.")
132 } 136 }
137 Section {
138 Toggle("ISS passes", isOn: Binding(
139 get: { issPasses },
140 set: { on in Task { await setISSPasses(on) } }
141 ))
142 if let issStatus {
143 Text(issStatus).font(.footnote).foregroundStyle(.secondary)
144 }
145 } footer: {
146 Text("An alert 15 minutes before the International Space Station crosses your sky while you can see it. Worked out on this device; nothing is sent to our server.")
147 }
133 Section { 148 Section {
134 Toggle("Cloud forecasts", isOn: $cloudForecast) 149 Toggle("Cloud forecasts", isOn: $cloudForecast)
135 } footer: { 150 } footer: {
@@ -192,6 +207,18 @@ struct SettingsScreen: View {
192 ) 207 )
193 } 208 }
194 209
210 private func setISSPasses(_ on: Bool) async {
211 if on {
212 let granted = (try? await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound])) ?? false
213 guard granted else {
214 issStatus = "Notifications are off for Moonrise. Turn them on in the Settings app."
215 return
216 }
217 }
218 issStatus = nil
219 issPasses = on
220 }
221
195 private func setDailySummary(_ on: Bool) async { 222 private func setDailySummary(_ on: Bool) async {
196 if on { 223 if on {
197 let granted = (try? await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound])) ?? false 224 let granted = (try? await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound])) ?? false
App/Sources/SkyScreen.swift +9 −5
@@ -104,7 +104,7 @@ struct SkyScreen: View {
104 .sheet(isPresented: $showYear) { 104 .sheet(isPresented: $showYear) {
105 YearSheet(year: $model.historicalYear, south: model.observer.latitude < 0).preferredColorScheme(.dark) 105 YearSheet(year: $model.historicalYear, south: model.observer.latitude < 0).preferredColorScheme(.dark)
106 } 106 }
107 .sheet(isPresented: $showSettings, onDismiss: rescheduleSummary) { 107 .sheet(isPresented: $showSettings, onDismiss: rescheduleNotifications) {
108 SettingsScreen { model.applyLocationSettings() } 108 SettingsScreen { model.applyLocationSettings() }
109 .preferredColorScheme(.dark) 109 .preferredColorScheme(.dark)
110 .tint(.blue) 110 .tint(.blue)
@@ -122,8 +122,8 @@ struct SkyScreen: View {
122 .onChange(of: model.scene == nil) { showRequestedTarget() } 122 .onChange(of: model.scene == nil) { showRequestedTarget() }
123 .onChange(of: onboarded) { if onboarded { model.start() } } 123 .onChange(of: onboarded) { if onboarded { model.start() } }
124 .onChange(of: night, initial: true) { nightActive = night } 124 .onChange(of: night, initial: true) { nightActive = night }
125 .onChange(of: model.observer) { rescheduleSummary() } 125 .onChange(of: model.observer) { rescheduleNotifications() }
126 .onChange(of: scenePhase) { if scenePhase == .active { rescheduleSummary() } } 126 .onChange(of: scenePhase) { if scenePhase == .active { rescheduleNotifications() } }
127 .task { 127 .task {
128 if onboarded { model.start() } 128 if onboarded { model.start() }
129 while !Task.isCancelled { 129 while !Task.isCancelled {
@@ -190,8 +190,12 @@ struct SkyScreen: View {
190 aim(at: t) 190 aim(at: t)
191 } 191 }
192 192
193 private func rescheduleSummary() { 193 /// The daily summary and ISS pass alerts.
194 Task { await DailySummaryNotifications.reschedule(model) } 194 private func rescheduleNotifications() {
195 Task {
196 await DailySummaryNotifications.reschedule(model)
197 await ISSPassNotifications.reschedule(model)
198 }
195 } 199 }
196 200
197 private func select(_ object: SkyObject?) { 201 private func select(_ object: SkyObject?) {
PLAN.org +10 −4
@@ -485,12 +485,18 @@ Sky, System, Sun, Launches, Library core (above).
485 3D, checked on a device. Done: Sun snapshot OVATION grid zlib-compressed 485 3D, checked on a device. Done: Sun snapshot OVATION grid zlib-compressed
486 (grid 87 KB to 9 KB base64; snapshot 156 KB to about 78 KB). 486 (grid 87 KB to 9 KB base64; snapshot 156 KB to about 78 KB).
487 487
488** v4.2: widgets and controls 488** v4.2: provider usage terms
489Done: User-Agent with version and contact for every provider; LL2 429
490backoff; CelesTrak retry without a second download; news and Kp through the
491Worker; DSN Now freshness; NASA/ESA image licences; 26 LoC plates bundled.
492
493** v4.3: widgets and controls
489- Lock Screen: Kp, next launch. Home Screen: Voyager 1 distance, today's Sun 494- Lock Screen: Kp, next launch. Home Screen: Voyager 1 distance, today's Sun
490 image. 495 image. Done; not yet checked on a device.
491- Widgets and Control Center controls backed by the App Intents, with an 496- Widgets and Control Center controls backed by the App Intents, with an
492 App Group. 497 App Group. Done: App Group =group.sh.krz.moonrise= shares the Sky tab's
493- Opt-in notification for a visible ISS pass in 15 minutes (local). 498 place; controls open Sky, Sun and Launches.
499- Opt-in notification for a visible ISS pass in 15 minutes (local). Done.
494 500
495** v5.0: eclipse, 2 August 2027 501** v5.0: eclipse, 2 August 2027
496- Watch haptics at second and third contact. 502- Watch haptics at second and third contact.