|
| 1 | +// Button comes from the swift-ui entry, NOT universal: universal Button |
| 2 | +// prepends a variant-derived `buttonStyle()` at modifier index 0, and |
| 3 | +// SwiftUI's innermost buttonStyle wins — a user-passed |
| 4 | +// `buttonStyle("glassProminent")` is silently inert there. swift-ui |
| 5 | +// Button injects nothing, so ours is the only one. Host/Column/Icon/Text |
| 6 | +// stay universal: their iOS impls are thin swift-ui wrappers (Host is a |
| 7 | +// literal re-export), so the mixed tree is native-identical. |
| 8 | +import { Column, Host, Icon, Text as UIText } from "@expo/ui"; |
| 9 | +import { Button } from "@expo/ui/swift-ui"; |
| 10 | +import { |
| 11 | + buttonStyle, |
| 12 | + controlSize, |
| 13 | + frame, |
| 14 | + tint, |
| 15 | +} from "@expo/ui/swift-ui/modifiers"; |
| 16 | +import { useCallback } from "react"; |
| 17 | +import { Alert, Linking, Pressable, Text, View } from "react-native"; |
| 18 | +import { useDaemonClient } from "@/lib/daemon-client-context"; |
| 19 | + |
| 20 | +// Website redirect, not a hardcoded App Store id — the site can point at |
| 21 | +// TestFlight today and the store listing later without an app release. |
| 22 | +const IOS_UPDATE_URL = "https://sidecode.app/ios"; |
| 23 | + |
| 24 | +/** |
| 25 | + * `/update-required` — protocol-mismatch gate (only reachable while |
| 26 | + * `isProtocolBlocked` is true; see `(main)/_layout.tsx` for why this is |
| 27 | + * a route gate and not a banner). |
| 28 | + * |
| 29 | + * One route for both directions in V0; the copy + primary action branch |
| 30 | + * on `protocolError.outdatedSide`: |
| 31 | + * |
| 32 | + * - `"app"` → this app is too old. Primary = open the update page |
| 33 | + * (the one direction we can never self-heal — iOS apps can't update |
| 34 | + * themselves). Conceptually this branch is the screen's terminal |
| 35 | + * identity: in a multi-daemon future, the `"daemon"` branch leaves |
| 36 | + * the route gate (per-daemon badge + daemon self-update) and this |
| 37 | + * route narrows to the app-outdated force-update screen. |
| 38 | + * - `"daemon"` → the Mac app is too old. Primary = Try Again, for |
| 39 | + * after the user updates the Mac side (menu bar → Check for |
| 40 | + * updates). Becomes a transient "Mac is updating…" state once |
| 41 | + * daemon self-update-on-mismatch lands. |
| 42 | + * - `"unknown"` → no usable daemon version (shouldn't happen against |
| 43 | + * a real daemon) — neutral both-sides copy, Retry. |
| 44 | + * |
| 45 | + * Layout follows the onboarding idiom: RN owns layout/text/theming, |
| 46 | + * the bottom CTA bar is the only `@expo/ui` Host island so the buttons |
| 47 | + * get the native iOS control look. |
| 48 | + */ |
| 49 | +export default function UpdateRequiredRoute() { |
| 50 | + const { protocolError, paired, isLoading, reset, unpair } = useDaemonClient(); |
| 51 | + |
| 52 | + const handleRetry = useCallback(() => reset(), [reset]); |
| 53 | + |
| 54 | + const handleOpenUpdatePage = useCallback(() => { |
| 55 | + void Linking.openURL(IOS_UPDATE_URL); |
| 56 | + }, []); |
| 57 | + |
| 58 | + const handleForget = useCallback(() => { |
| 59 | + Alert.alert( |
| 60 | + "Forget this Mac?", |
| 61 | + "You'll need to scan its QR code again to reconnect.", |
| 62 | + [ |
| 63 | + { text: "Cancel", style: "cancel" }, |
| 64 | + { text: "Forget", style: "destructive", onPress: () => void unpair() }, |
| 65 | + ], |
| 66 | + ); |
| 67 | + }, [unpair]); |
| 68 | + |
| 69 | + // Guard-unmount race: the route can render one frame after a successful |
| 70 | + // retry cleared the error. Render nothing; the gate is about to flip. |
| 71 | + if (!protocolError) return null; |
| 72 | + |
| 73 | + const side = protocolError.outdatedSide; |
| 74 | + const serviceName = paired?.serviceName; |
| 75 | + |
| 76 | + return ( |
| 77 | + <View className="flex-1 bg-white dark:bg-black px-6 pb-safe-offset-4 pt-safe"> |
| 78 | + <View className="flex-1 justify-center"> |
| 79 | + <Host matchContents style={{ alignSelf: "flex-start" }}> |
| 80 | + <Icon name="arrow.up.circle" size={56} color="#EE5722" /> |
| 81 | + </Host> |
| 82 | + <Text className="mt-4 text-3xl font-bold text-black dark:text-white"> |
| 83 | + Update Required |
| 84 | + </Text> |
| 85 | + <Text className="mt-2 text-base text-gray-500 dark:text-gray-400"> |
| 86 | + {protocolError.message} |
| 87 | + </Text> |
| 88 | + {serviceName ? ( |
| 89 | + <Text className="mt-1 text-sm text-gray-500 dark:text-gray-400"> |
| 90 | + Paired with {serviceName}. |
| 91 | + </Text> |
| 92 | + ) : null} |
| 93 | + {/* Diagnostics footnote — protocol (wire) versions, not marketing |
| 94 | + versions. Useful in a bug report screenshot. */} |
| 95 | + <Text className="mt-3 text-xs text-gray-400 dark:text-gray-500"> |
| 96 | + App protocol {protocolError.appProtocolVersion} · Mac protocol{" "} |
| 97 | + {protocolError.daemonProtocolVersion ?? "unknown"} |
| 98 | + </Text> |
| 99 | + </View> |
| 100 | + |
| 101 | + {side === "daemon" ? ( |
| 102 | + <Text className="mb-3 text-sm text-gray-500 dark:text-gray-400 text-center"> |
| 103 | + On your Mac: Sidecode menu → Check for updates. |
| 104 | + </Text> |
| 105 | + ) : null} |
| 106 | + |
| 107 | + <Host |
| 108 | + matchContents={{ vertical: true }} |
| 109 | + style={{ alignSelf: "stretch" }} |
| 110 | + ignoreSafeArea="keyboard" |
| 111 | + > |
| 112 | + <Column spacing={8}> |
| 113 | + {side === "app" ? ( |
| 114 | + <Button |
| 115 | + onPress={handleOpenUpdatePage} |
| 116 | + modifiers={[ |
| 117 | + buttonStyle("glassProminent"), |
| 118 | + controlSize("extraLarge"), |
| 119 | + tint("#EE5722"), |
| 120 | + ]} |
| 121 | + > |
| 122 | + <UIText |
| 123 | + textStyle={{ fontWeight: "600", textAlign: "center" }} |
| 124 | + modifiers={[frame({ maxWidth: Infinity })]} |
| 125 | + > |
| 126 | + Get the Update |
| 127 | + </UIText> |
| 128 | + </Button> |
| 129 | + ) : null} |
| 130 | + {/* Primary when it's the only action (daemon/unknown), secondary |
| 131 | + next to Get the Update (app). Secondary is `bordered`, not |
| 132 | + `glass`: plain glass has nothing to refract on this flat |
| 133 | + content-layer background and reads as a barely-visible frosted |
| 134 | + capsule (verified on-device; matches Apple's own practice — |
| 135 | + content-layer CTAs on plain backgrounds stay bordered/filled). */} |
| 136 | + <Button |
| 137 | + onPress={handleRetry} |
| 138 | + modifiers={[ |
| 139 | + buttonStyle(side === "app" ? "bordered" : "glassProminent"), |
| 140 | + controlSize("extraLarge"), |
| 141 | + tint("#EE5722"), |
| 142 | + ]} |
| 143 | + > |
| 144 | + <UIText |
| 145 | + textStyle={ |
| 146 | + side === "app" |
| 147 | + ? { textAlign: "center" } |
| 148 | + : { fontWeight: "600", textAlign: "center" } |
| 149 | + } |
| 150 | + modifiers={[frame({ maxWidth: Infinity })]} |
| 151 | + > |
| 152 | + {isLoading ? "Retrying…" : "Try Again"} |
| 153 | + </UIText> |
| 154 | + </Button> |
| 155 | + </Column> |
| 156 | + </Host> |
| 157 | + |
| 158 | + {/* Escape hatch — without it a user who wants to pair a different |
| 159 | + (already-updated) Mac is soft-locked on this screen. */} |
| 160 | + <Pressable |
| 161 | + onPress={handleForget} |
| 162 | + hitSlop={8} |
| 163 | + className="mt-4 self-center" |
| 164 | + > |
| 165 | + <Text className="text-sm text-gray-500 dark:text-gray-400"> |
| 166 | + Forget this Mac |
| 167 | + </Text> |
| 168 | + </Pressable> |
| 169 | + </View> |
| 170 | + ); |
| 171 | +} |
0 commit comments