Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(native): the watch bridge stays silent on an iPad

Maurice9c1e63e64b4a
diff --git a/client/ios/App/App/TrekShellPlugin.swift b/client/ios/App/App/TrekShellPlugin.swift
index ec3b9b621..2a5f7a06d 100644
--- a/client/ios/App/App/TrekShellPlugin.swift
+++ b/client/ios/App/App/TrekShellPlugin.swift
@@ -55,7 +55,11 @@ public class TrekShellPlugin: CAPPlugin, CAPBridgedPlugin, ASWebAuthenticationPr
/// and a server can require a minimum (minNativeShellApi in /api/health/features).
static let shellApi = 2
/// The native features by name, so the UI can turn each on by itself.
- static let features: [String] = ["capabilities", "edgeBack", "tileCache", "biometricLock", "geolocation", "sharedFiles", "nativePush", "widgets", "liveActivity", "widgetTrips", "storeKit", "shareSheet", "wallet", "watch"]
+ /// "watch" only where WatchConnectivity is (an iPhone, not an iPad), so the UI never builds a snapshot for nothing.
+ static var features: [String] {
+ ["capabilities", "edgeBack", "tileCache", "biometricLock", "geolocation", "sharedFiles", "nativePush", "widgets", "liveActivity", "widgetTrips", "storeKit", "shareSheet", "wallet"]
+ + (TrekWatchLink.isAvailable ? ["watch"] : [])
+ }
// MARK: - Shared booking documents
@@ -144,6 +148,10 @@ public class TrekShellPlugin: CAPPlugin, CAPBridgedPlugin, ASWebAuthenticationPr
/// Passes what the watch app shows (native/watch.ts builds it) on to the watch.
@objc func setWatchSnapshot(_ call: CAPPluginCall) {
+ guard TrekWatchLink.isAvailable else {
+ call.resolve()
+ return
+ }
guard let json = call.getString("json"), let data = json.data(using: .utf8) else {
call.reject("json is required")
return
diff --git a/client/ios/App/App/TrekWatchLink.swift b/client/ios/App/App/TrekWatchLink.swift
index 2ca2512c2..87d5e0228 100644
--- a/client/ios/App/App/TrekWatchLink.swift
+++ b/client/ios/App/App/TrekWatchLink.swift
@@ -23,8 +23,12 @@ final class TrekWatchLink: NSObject, WCSessionDelegate {
/// The most WatchConnectivity carries in one application context, with room to spare.
private let maxBytes = 60_000
+ /// False on an iPad (and anything else without a paired watch): then this is
+ /// a no-op throughout, and the UI is not offered the feature at all.
+ static var isAvailable: Bool { WCSession.isSupported() }
+
func activate() {
- guard WCSession.isSupported() else { return }
+ guard Self.isAvailable else { return }
WCSession.default.delegate = self
WCSession.default.activate()
}
@@ -32,6 +36,7 @@ final class TrekWatchLink: NSObject, WCSessionDelegate {
// MARK: Snapshots to the watch
func publish(_ json: Data) {
+ guard Self.isAvailable else { return }
let data = withSmallCover(json)
queue.async {
UserDefaults.standard.set(data, forKey: self.snapshotKey)
@@ -40,8 +45,9 @@ final class TrekWatchLink: NSObject, WCSessionDelegate {
}
private func send(_ data: Data) {
+ guard Self.isAvailable else { return }
let session = WCSession.default
- guard WCSession.isSupported(), session.activationState == .activated, session.isPaired, session.isWatchAppInstalled else { return }
+ guard session.activationState == .activated, session.isPaired, session.isWatchAppInstalled else { return }
try? session.updateApplicationContext(["snapshot": data])
let digest = complicationDigest(data)
if session.isComplicationEnabled, session.remainingComplicationUserInfoTransfers > 0,