4cae1b8bb8
Foundation milestone for Live Activities & Widgets (design/apple-live- activities-and-widgets.md). No user-visible change beyond the URL scheme. - New dependency-free PunktfunkShared SwiftPM target (+ library product) so a future widget extension can link it WITHOUT PunktfunkKit (Rust staticlib + presentation layer). Moves StoredHost (model + JSON codec), DefaultsKeys, and punktfunkDefaultMgmtPort there; adds AppGroup.suiteName and the punktfunk:// DeepLink builder/parser. PunktfunkKit @_exported-imports it (no call-site churn for consumers; intra-Kit files import it explicitly since imports are file-scoped). - HostStore reads/writes the shared App-Group suite (group.io.unom.punktfunk) with a one-time migration from UserDefaults.standard (old value left in place for staged rollout); reloads the "PunktfunkHosts" widget timeline on change. - App Group entitlement on iOS/tvOS + macOS. - CFBundleURLTypes scheme `punktfunk`; ContentView.onOpenURL routes connect/<uuid>[?launch=<GameEntry.id>] into the existing connect() path (unknown host / already-streaming guards; never tears down a live session). - Round-trip tests: StoredHost JSON codec (+ legacy missing-optional decode), DeepLink grammar. `swift build` + `swift test` green (142 tests, 0 failures). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
28 lines
1.7 KiB
Swift
28 lines
1.7 KiB
Swift
// Whether the iOS/iPadOS/macOS UI should be in its controller-friendly mode (the console-style
|
|
// host launcher, gamepad settings, and the coverflow library browser instead of the touch/desktop
|
|
// layouts). A pure function, not a singleton: the reactivity comes from callers already observing
|
|
// `GamepadManager.shared` and the `DefaultsKey.gamepadUIEnabled` @AppStorage themselves (the same
|
|
// local-read pattern SettingsView already uses for GamepadManager), so this stays the single place
|
|
// the two combine without adding a second ObservableObject or an environment key nobody else needs.
|
|
|
|
import Foundation
|
|
import PunktfunkShared
|
|
|
|
public enum GamepadUIEnvironment {
|
|
/// `enabledSetting` is the user's Settings toggle (`DefaultsKey.gamepadUIEnabled`);
|
|
/// `gamepadConnected` is `GamepadManager.shared.active != nil` — active only once a usable
|
|
/// controller is actually attached (a non-extended-profile device leaves `active` nil, which
|
|
/// keeps the touch UI). A `Bool` rather than the `DiscoveredController` itself: this function's
|
|
/// whole job is the AND, so there's nothing else to inspect, and it keeps the helper testable
|
|
/// without a real `GCController` (which XCTest can't construct).
|
|
public static func isActive(gamepadConnected: Bool, enabledSetting: Bool) -> Bool {
|
|
enabledSetting && (gamepadConnected || forced)
|
|
}
|
|
|
|
/// Dev-only escape hatch (like ContentView's `PUNKTFUNK_AUTOCONNECT`): pretend a controller is
|
|
/// attached so the gamepad UI can be exercised/screenshotted without physical hardware —
|
|
/// essential on a headless CI Mac and for `swift run` UI work. Never set in production.
|
|
private static let forced =
|
|
ProcessInfo.processInfo.environment["PUNKTFUNK_FORCE_GAMEPAD_UI"] == "1"
|
|
}
|