feat(apple): gamepad UI v2 — controller settings + add host, aurora, macOS
Sources reorganized (client: Home/Session/Settings/Stores/Support/Trust; kit: Audio/Connection/Gamepad/Input/Support/Video/Views) with the big files split along the same seams. The gamepad mode is couch-complete, and now on macOS too (the living-room Mac case), not just iOS/iPadOS: - GamepadSettingsView: a console-style, fully controller-navigable settings screen (X from the launcher) — up/down moves focus, left/right steps values (clamped, boundary thud), A cycles/toggles, B closes; the focused row shows a one-line description. Backed by GamepadMenuList, the vertical sibling of GamepadCarousel, and SettingsOptions — the option lists hoisted out of SettingsView statics and shared by the touch, tvOS and gamepad settings. - GamepadAddHostView + GamepadKeyboard: register a host end to end with a pad — field rows open an on-screen controller keyboard (dpad grid, A types, X backspaces, B done); the launcher carousel ends in an Add Host tile, so the dead-end "add one with touch first" empty state is gone. - Launcher polish: contextual hint bar with the pad's real button glyphs, controller name + battery chip, one shared console chrome. - GamepadScreenBackground: an animated aurora (TimelineView-driven drifting blobs in the brand's violet family, breathing radii, slow hue shift, legibility scrim; freezes under Reduce Motion). Pure SwiftUI on purpose — a .metal library only bundles reliably in one of the two build systems (SPM vs the xcodeproj's synced folders) these sources compile under. - macOS port: settings/add-host/library present as sized sheets (a macOS sheet takes its content's IDEAL size, and the GeometryReader-driven screens collapsed to nothing), NSScreen-based mode lists, scroll indicators .never (the "always show scroll bars" setting overrides .hidden), tray scrims so scrolled rows dim under the pinned title/hints, extra title clearance, and a PUNKTFUNK_FORCE_GAMEPAD_UI=1 dev hook — launcher/settings/add-host/keyboard/ library render-verified live on a real Mac + LAN hosts. - GamepadMenuInput: X button support, and (re)start now snapshots held buttons so a controller handoff press never fires twice (the B that closed the keyboard no longer also cancels the screen underneath). - Cleanups: one "Connection failed" alert in ContentView instead of one per home screen; HostDiscovery.advertises/unsaved shared by both home screens. - host: can_encode_444 stub for the non-Linux/Windows host build (the macOS synthetic-source loopback used by the Swift tests). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// App-wide brand chrome. SwiftUI has no single switch to put a custom font on every navigation
|
||||
// title, so the iOS large/inline nav titles are themed through UINavigationBar's appearance proxy
|
||||
// (set once at launch). Backgrounds are left at the system defaults — transparent at the scroll
|
||||
// edge (the large title floats on the content), blurred once scrolled — so only the typeface
|
||||
// changes: Geist, matching the cards and the website.
|
||||
|
||||
#if os(iOS)
|
||||
import PunktfunkKit
|
||||
import UIKit
|
||||
|
||||
enum BrandTheme {
|
||||
static func apply() {
|
||||
BrandFont.registerIfNeeded()
|
||||
|
||||
let scrollEdge = UINavigationBarAppearance()
|
||||
scrollEdge.configureWithTransparentBackground()
|
||||
applyFonts(to: scrollEdge)
|
||||
|
||||
let standard = UINavigationBarAppearance()
|
||||
standard.configureWithDefaultBackground()
|
||||
applyFonts(to: standard)
|
||||
|
||||
let proxy = UINavigationBar.appearance()
|
||||
proxy.scrollEdgeAppearance = scrollEdge
|
||||
proxy.standardAppearance = standard
|
||||
proxy.compactAppearance = standard
|
||||
}
|
||||
|
||||
/// Override only the title fonts; leave colors/backgrounds at the configured defaults.
|
||||
private static func applyFonts(to appearance: UINavigationBarAppearance) {
|
||||
if let large = UIFont(name: "Geist-Bold", size: 34) {
|
||||
appearance.largeTitleTextAttributes[.font] = large
|
||||
}
|
||||
if let inline = UIFont(name: "Geist-SemiBold", size: 17) {
|
||||
appearance.titleTextAttributes[.font] = inline
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
// GlassStyle.swift — the app's single, availability-gated entry point to Apple's "Liquid
|
||||
// Glass" (iOS / macOS / tvOS 26). Every Liquid Glass symbol (glassEffect, Glass, the
|
||||
// .glassProminent button style …) is HARD-gated to OS 26: referencing one with our
|
||||
// deployment targets (macOS 14 / iOS 17 / tvOS 17) is a COMPILE error, not a silent no-op,
|
||||
// unless it sits behind `if #available`. So all glass in the app routes through the two
|
||||
// helpers below, each of which falls back to the EXACT look the app shipped before
|
||||
// (.regularMaterial / .borderedProminent) — nothing regresses on older OSes, and the gating
|
||||
// lives in exactly one file.
|
||||
|
||||
import SwiftUI
|
||||
|
||||
// MARK: - Glass background
|
||||
|
||||
/// Liquid Glass behind a floating / overlay surface, with the pre-26 `.regularMaterial`
|
||||
/// look as the fallback. Use ONLY on the floating control / overlay layer (the streaming
|
||||
/// HUD, the trust card, the touch exit chip) — never on content tiles or dense forms (HIG).
|
||||
///
|
||||
/// `glassEffect()`'s own default shape is a Capsule, so panels MUST pass an explicit shape
|
||||
/// (a RoundedRectangle / Circle) or they render as a pill. `interactive` makes the glass
|
||||
/// react to press — only meaningful when the glass itself is the tap target.
|
||||
private struct GlassBackground<S: Shape>: ViewModifier {
|
||||
let shape: S
|
||||
var interactive = false
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
if #available(iOS 26, macOS 26, tvOS 26, *) {
|
||||
content.glassEffect(interactive ? .regular.interactive() : .regular, in: shape)
|
||||
} else {
|
||||
content.background(.regularMaterial, in: shape)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// Liquid Glass (26+) or the existing `.regularMaterial` (pre-26) behind a floating
|
||||
/// surface. Pass the surface's shape explicitly — glass defaults to a Capsule otherwise.
|
||||
func glassBackground<S: Shape>(_ shape: S, interactive: Bool = false) -> some View {
|
||||
modifier(GlassBackground(shape: shape, interactive: interactive))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Glass primary button
|
||||
|
||||
/// The single prominent action on a floating / overlay or sheet surface: the Liquid-Glass
|
||||
/// prominent button style on 26+, falling back to `.borderedProminent` (the app's current
|
||||
/// primary style) below. Apply directly to a `Button`; role / keyboardShortcut / disabled
|
||||
/// chain after it as usual. tvOS stays `.borderedProminent` always — glass chrome fights the
|
||||
/// focus engine, and keeping it preserves today's tvOS look exactly.
|
||||
private struct GlassProminentButton: ViewModifier {
|
||||
func body(content: Content) -> some View {
|
||||
#if os(tvOS)
|
||||
content.buttonStyle(.borderedProminent)
|
||||
#else
|
||||
if #available(iOS 26, macOS 26, *) {
|
||||
content.buttonStyle(.glassProminent)
|
||||
} else {
|
||||
content.buttonStyle(.borderedProminent)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// Liquid-Glass prominent style (26+, non-tvOS) or `.borderedProminent`. Drop-in for the
|
||||
/// `.buttonStyle(.borderedProminent)` on a surface's primary action.
|
||||
func glassProminentButtonStyle() -> some View {
|
||||
modifier(GlassProminentButton())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Hex encode/decode for the trust surface — pinned certificate fingerprints and the mDNS `fp`
|
||||
// TXT value travel as lowercase hex.
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Data {
|
||||
/// Lowercase hex, no separators — to compare a pinned fingerprint against the mDNS `fp`.
|
||||
var hexLower: String { map { String(format: "%02x", $0) }.joined() }
|
||||
|
||||
/// Parse an even-length hex string into bytes; nil on any non-hex character or odd length.
|
||||
/// Used to turn an mDNS-advertised cert fingerprint into a connect pin.
|
||||
init?(hexString: String) {
|
||||
let chars = Array(hexString)
|
||||
guard chars.count.isMultiple(of: 2) else { return nil }
|
||||
var bytes = [UInt8]()
|
||||
bytes.reserveCapacity(chars.count / 2)
|
||||
var i = 0
|
||||
while i < chars.count {
|
||||
guard let hi = chars[i].hexDigitValue, let lo = chars[i + 1].hexDigitValue else {
|
||||
return nil
|
||||
}
|
||||
bytes.append(UInt8(hi << 4 | lo))
|
||||
i += 2
|
||||
}
|
||||
self = Data(bytes)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
// The native tvOS text-entry experience: real tvOS apps never edit text inline —
|
||||
// selecting a field presents the SYSTEM full-screen keyboard (Apple's "Designing the
|
||||
// Keyboard Input Experience"). UIKit gives that for free: a UITextField that becomes
|
||||
// first responder presents the fullscreen keyboard UI with the field's placeholder as
|
||||
// the prompt. SwiftUI's inline TextField on tvOS is an expanding pill with stray
|
||||
// chrome — this bridge replaces it everywhere on tvOS.
|
||||
|
||||
#if os(tvOS)
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
/// Present inside a fullScreenCover: immediately raises the system keyboard for one
|
||||
/// value, then calls `onDone` with the result (also on Menu-button dismissal, with
|
||||
/// whatever was typed so far — match the system apps' "edits stick" behavior).
|
||||
struct TVTextEntry: UIViewControllerRepresentable {
|
||||
let title: String
|
||||
let text: String
|
||||
var keyboardType: UIKeyboardType = .default
|
||||
let onDone: (String) -> Void
|
||||
|
||||
func makeUIViewController(context: Context) -> TVTextEntryController {
|
||||
let controller = TVTextEntryController()
|
||||
controller.configure(
|
||||
title: title, text: text, keyboardType: keyboardType, onDone: onDone)
|
||||
return controller
|
||||
}
|
||||
|
||||
func updateUIViewController(_ controller: TVTextEntryController, context: Context) {}
|
||||
}
|
||||
|
||||
final class TVTextEntryController: UIViewController, UITextFieldDelegate {
|
||||
private let field = UITextField()
|
||||
private var onDone: ((String) -> Void)?
|
||||
private var finished = false
|
||||
|
||||
func configure(
|
||||
title: String, text: String, keyboardType: UIKeyboardType,
|
||||
onDone: @escaping (String) -> Void
|
||||
) {
|
||||
field.placeholder = title
|
||||
field.text = text
|
||||
field.keyboardType = keyboardType
|
||||
field.returnKeyType = .done
|
||||
self.onDone = onDone
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
view.backgroundColor = .clear
|
||||
field.delegate = self
|
||||
view.addSubview(field) // must be in a window to become first responder
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
field.becomeFirstResponder() // presents the tvOS fullscreen keyboard
|
||||
}
|
||||
|
||||
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
textField.resignFirstResponder()
|
||||
return true
|
||||
}
|
||||
|
||||
func textFieldDidEndEditing(_ textField: UITextField) {
|
||||
guard !finished else { return }
|
||||
finished = true
|
||||
onDone?(textField.text ?? "")
|
||||
}
|
||||
}
|
||||
|
||||
/// A Settings-app-style value row: label leading, current value trailing — the whole
|
||||
/// row is one system lozenge, and pressing it opens the fullscreen keyboard.
|
||||
struct TVFieldRow: View {
|
||||
let label: String
|
||||
let value: String
|
||||
let placeholder: String
|
||||
let action: () -> Void
|
||||
|
||||
var body: some View {
|
||||
Button(action: action) {
|
||||
HStack {
|
||||
Text(label)
|
||||
Spacer()
|
||||
Text(value.isEmpty ? placeholder : value)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// A Settings-app-style selection screen: pushed list of option rows, checkmark on the
|
||||
/// current value, selecting pops back. Replaces Picker(.navigationLink), whose internal
|
||||
/// list renders rows in the focused (dark-text) style while the push animates.
|
||||
struct TVSelectionList<Tag: Hashable>: View {
|
||||
let title: String
|
||||
let options: [(label: String, tag: Tag)]
|
||||
@Binding var selection: Tag
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(spacing: 16) {
|
||||
ForEach(options, id: \.tag) { option in
|
||||
Button {
|
||||
selection = option.tag
|
||||
dismiss()
|
||||
} label: {
|
||||
HStack {
|
||||
Text(option.label)
|
||||
Spacer()
|
||||
if option.tag == selection {
|
||||
Image(systemName: "checkmark")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: 900)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(60)
|
||||
}
|
||||
.navigationTitle(title)
|
||||
}
|
||||
}
|
||||
|
||||
/// The pushing row for a TVSelectionList: label leading, current value trailing.
|
||||
struct TVSelectionRow<Tag: Hashable>: View {
|
||||
let title: String
|
||||
let options: [(label: String, tag: Tag)]
|
||||
@Binding var selection: Tag
|
||||
|
||||
var body: some View {
|
||||
NavigationLink {
|
||||
TVSelectionList(title: title, options: options, selection: $selection)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(title)
|
||||
Spacer()
|
||||
Text(options.first { $0.tag == selection }?.label ?? "—")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user