From 79df7fe34aebd9a929c3b98ee7cd2dcc4e799ad8 Mon Sep 17 00:00:00 2001 From: lougeniac64 Date: Wed, 30 Oct 2024 14:29:42 -0400 Subject: [PATCH] Refactored sendEventToDevice to return closeTabs result --- CHANGELOG.md | 5 +++++ .../FxAccountDeviceConstellation.swift | 20 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe88fdb9..8700338db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # v134.0 (In progress) +## 🦊 What's Changed 🦊 + +### FxA Client +- Updated the iOS `sendToDevice` function to return the `closeTab` call's result when applicable. ([#6448](https://github.com/mozilla/application-services/pull/6448)) + ## ⚠️ Breaking Changes ⚠️ ### Nimbus SDK ⛅️🔬🔭 diff --git a/components/fxa-client/ios/FxAClient/FxAccountDeviceConstellation.swift b/components/fxa-client/ios/FxAClient/FxAccountDeviceConstellation.swift index 62640ddeb..7118abe05 100644 --- a/components/fxa-client/ios/FxAClient/FxAccountDeviceConstellation.swift +++ b/components/fxa-client/ios/FxAClient/FxAccountDeviceConstellation.swift @@ -13,6 +13,11 @@ public struct ConstellationState { public let remoteDevices: [Device] } +public enum SendEventError: Error { + case tabsNotClosed(urls: [String]) + case other(Error) +} + public class DeviceConstellation { var constellationState: ConstellationState? let account: PersistedFirefoxAccount @@ -87,18 +92,29 @@ public class DeviceConstellation { } /// Send an event to another device such as Send Tab. - public func sendEventToDevice(targetDeviceId: String, e: DeviceEventOutgoing) { + public func sendEventToDevice(targetDeviceId: String, + e: DeviceEventOutgoing, + completionHandler: ((Result) -> Void)? = nil) + { DispatchQueue.global().async { do { switch e { case let .sendTab(title, url): do { try self.account.sendSingleTab(targetDeviceId: targetDeviceId, title: title, url: url) + completionHandler?(.success(())) } case let .closeTabs(urls): - _ = try self.account.closeTabs(targetDeviceId: targetDeviceId, urls: urls) + let result = try self.account.closeTabs(targetDeviceId: targetDeviceId, urls: urls) + switch result { + case .ok: + completionHandler?(.success(())) + case let .tabsNotClosed(urls): + completionHandler?(.failure(.tabsNotClosed(urls: urls))) + } } } catch { FxALog.error("Error sending event to another device: \(error).") + completionHandler?(.failure(.other(error))) } } }