Integrate live phone and watch remote prototype with guarded motion control
This commit is contained in:
@@ -33,8 +33,12 @@ private final class WatchWCSessionSending: RelaySessionSending {
|
||||
@MainActor
|
||||
public final class WatchWCSessionDelegate: NSObject, WCSessionDelegate {
|
||||
public let bridge: WatchRelayBridge
|
||||
public var onContext: ((RelayApplicationContext) -> Void)?
|
||||
public private(set) var latestContext: RelayApplicationContext?
|
||||
private let session: WCSession
|
||||
|
||||
public init(session: WCSession = .default) {
|
||||
self.session = session
|
||||
bridge = WatchRelayBridge(session: WatchWCSessionSending(session: session))
|
||||
super.init()
|
||||
session.delegate = self
|
||||
@@ -48,6 +52,21 @@ public final class WatchWCSessionDelegate: NSObject, WCSessionDelegate {
|
||||
guard let self else { return }
|
||||
if case .inactive = self.bridge.state { } else { self.bridge.didDeactivate() }
|
||||
self.bridge.activationDidComplete(error: error)
|
||||
self.receiveContext(self.session.receivedApplicationContext)
|
||||
}
|
||||
}
|
||||
|
||||
private func receiveContext(_ dictionary: [String: Any]) {
|
||||
guard let context = try? RelayApplicationContext(dictionary: dictionary) else { return }
|
||||
latestContext = context
|
||||
onContext?(context)
|
||||
}
|
||||
|
||||
nonisolated public func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String: Any]) {
|
||||
guard let context = try? RelayApplicationContext(dictionary: applicationContext) else { return }
|
||||
Task { @MainActor [weak self] in
|
||||
self?.latestContext = context
|
||||
self?.onContext?(context)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user