Commit 21d86238a3
21d86238a3c798b1377d6c2a4c296152e3d4a94a
parent: e5cd77581e
Unsigned
cmc <hello@cleberg.net> · 2026-10-22 01:58 UTC
Controls: open Sky, Sun or Launches from Control Center (!108)
Stacked on !107 (branch `widgets-home-screen`); merge !106 and !107 first.
- `App/Shared/OpenTabIntent.swift`: `OpenTabIntent` with a `MoonriseTab` parameter, `.foreground(.immediate)`. Compiled into the app and the widget extension; `perform` runs in the app and sets `Router.shared.tab`. Also available in Shortcuts. Not added to the App Shortcuts list (9 of 10 used).
- `App/Widgets/Controls.swift`: Control Center buttons "Tonight's sky", "Sun", "Launches".
- Widget target: `SWIFT_ACTIVE_COMPILATION_CONDITIONS` adds `WIDGET_EXTENSION`.
- iOS and watchOS build. Not tried in Control Center.
Layout: unified · split
App/Shared/OpenTabIntent.swift
added
+34
| @@ -0,0 +1,34 @@ |
| 1 | import AppIntents |
| 2 | |
| 3 | enum MoonriseTab: String, AppEnum { |
| 4 | case sky, system, sun, launches, library |
| 5 | |
| 6 | static let typeDisplayRepresentation: TypeDisplayRepresentation = "Tab" |
| 7 | static let caseDisplayRepresentations: [MoonriseTab: DisplayRepresentation] = [ |
| 8 | .sky: "Sky", .system: "System", .sun: "Sun", .launches: "News & launches", .library: "Library", |
| 9 | ] |
| 10 | } |
| 11 | |
| 12 | /// Opens a tab. Compiled into the widget extension too, for Control Center; it runs in the app. |
| 13 | struct OpenTabIntent: AppIntent { |
| 14 | static let title: LocalizedStringResource = "Open Tab" |
| 15 | static let description = IntentDescription("Opens Moonrise on the Sky, System, Sun, News & launches or Library tab.") |
| 16 | static let supportedModes: IntentModes = .foreground(.immediate) |
| 17 | |
| 18 | @Parameter(title: "Tab", default: .sky) |
| 19 | var tab: MoonriseTab |
| 20 | |
| 21 | init() {} |
| 22 | |
| 23 | init(tab: MoonriseTab) { |
| 24 | self.tab = tab |
| 25 | } |
| 26 | |
| 27 | @MainActor |
| 28 | func perform() async throws -> some IntentResult { |
| 29 | #if !WIDGET_EXTENSION |
| 30 | Router.shared.tab = tab.rawValue |
| 31 | #endif |
| 32 | return .result() |
| 33 | } |
| 34 | } |
App/Widgets/Controls.swift
added
+26
| @@ -0,0 +1,26 @@ |
| 1 | import AppIntents |
| 2 | import SwiftUI |
| 3 | import WidgetKit |
| 4 | |
| 5 | /// Control Center buttons that open a tab. |
| 6 | @MainActor |
| 7 | private func openTab(_ kind: String, _ tab: MoonriseTab, _ title: LocalizedStringResource, _ symbol: String) -> some ControlWidgetConfiguration { |
| 8 | StaticControlConfiguration(kind: kind) { |
| 9 | ControlWidgetButton(action: OpenTabIntent(tab: tab)) { |
| 10 | Label(title, systemImage: symbol) |
| 11 | } |
| 12 | } |
| 13 | .displayName(title) |
| 14 | } |
| 15 | |
| 16 | struct SkyControl: ControlWidget { |
| 17 | var body: some ControlWidgetConfiguration { openTab("control.sky", .sky, "Tonight's sky", "sparkles") } |
| 18 | } |
| 19 | |
| 20 | struct SunControl: ControlWidget { |
| 21 | var body: some ControlWidgetConfiguration { openTab("control.sun", .sun, "Sun", "sun.max") } |
| 22 | } |
| 23 | |
| 24 | struct LaunchesControl: ControlWidget { |
| 25 | var body: some ControlWidgetConfiguration { openTab("control.launches", .launches, "Launches", "airplane.departure") } |
| 26 | } |
App/Widgets/MoonriseWidgets.swift
+3
| @@ -14,6 +14,9 @@ struct MoonriseWidgets: WidgetBundle { |
| 14 | 14 | NextLaunchWidget() |
| 15 | 15 | VoyagerWidget() |
| 16 | 16 | SunWidget() |
| 17 | SkyControl() |
| 18 | SunControl() |
| 19 | LaunchesControl() |
| 17 | 20 | LaunchLiveActivity() |
| 18 | 21 | EventLiveActivity() |
| 19 | 22 | EclipseLiveActivity() |
App/project.yml
+1
| @@ -111,6 +111,7 @@ targets: |
| 111 | 111 | MOONRISE_API_URL: https://moonrise.krz.sh |
| 112 | 112 | base: |
| 113 | 113 | PRODUCT_BUNDLE_IDENTIFIER: sh.krz.moonrise.widgets |
| 114 | SWIFT_ACTIVE_COMPILATION_CONDITIONS: $(inherited) WIDGET_EXTENSION |
| 114 | 115 | DEVELOPMENT_TEAM: ZCNAX3VL9D |
| 115 | 116 | CODE_SIGN_STYLE: Automatic |
| 116 | 117 | SWIFT_VERSION: "6.0" |