Skip to content

Commit 57476c1

Browse files
committed
Check for activationState in watch session
1 parent 5d57685 commit 57476c1

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,6 @@ enum WooAnalyticsStat: String {
12501250
case watchConnectingOpened = "watch_connecting_opened"
12511251
case watchSyncingFailed = "watch_syncing_failed"
12521252
case watchMyStoreOpened = "watch_my_store_opened"
1253-
case watchActivationCompleted = "watch_activation_completed"
12541253
case watchOrdersListOpened = "watch_orders_list_opened"
12551254
case watchPushNotificationTapped = "watch_push_notification_tapped"
12561255
case watchOrderDetailOpened = "watch_order_detail_opened"

WooCommerce/Classes/System/WatchDependenciesSynchronizer.swift

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ final class WatchDependenciesSynchronizer: NSObject, WCSessionDelegate {
3737
///
3838
@Published var account: Account?
3939

40-
/// Tracks if the current watch session is active or not
41-
///
42-
@Published private var isSessionActive: Bool = false
43-
4440
/// Toggle this value to force a credentials sync.
4541
///
4642
@Published private var syncTrigger = false
@@ -99,15 +95,17 @@ final class WatchDependenciesSynchronizer: NSObject, WCSessionDelegate {
9995
.debounce(for: 0.5, scheduler: DispatchQueue.main)
10096

10197
// Syncs the dependencies to the paired counterpart when the session becomes available.
102-
Publishers.CombineLatest3(watchDependencies, $isSessionActive, $syncTrigger)
103-
.sink { [weak self, watchSession] dependencies, isSessionActive, forceSync in
98+
watchDependencies.combineLatest($syncTrigger)
99+
.sink { [weak self, watchSession] dependencies, forceSync in
104100

105101
// Do not update the context if the session is not active, the watch is not paired or the watch app is not installed.
106-
guard isSessionActive, watchSession.isPaired, watchSession.isWatchAppInstalled else {
102+
guard watchSession.activationState == .activated,
103+
watchSession.isPaired,
104+
watchSession.isWatchAppInstalled else {
107105
self?.analytics.track(
108106
.watchSyncingFailed,
109107
properties: [
110-
"session_active": isSessionActive,
108+
"session_active": watchSession.activationState == .activated,
111109
"session_paired": watchSession.isPaired,
112110
"watch_app_installed": watchSession.isWatchAppInstalled
113111
],
@@ -147,12 +145,6 @@ final class WatchDependenciesSynchronizer: NSObject, WCSessionDelegate {
147145

148146
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
149147
DDLogInfo("🔵 WatchSession activated \(activationState)")
150-
analytics.track(
151-
.watchActivationCompleted,
152-
properties: ["state": activationState.rawValue],
153-
error: error
154-
)
155-
self.isSessionActive = activationState == .activated
156148
}
157149

158150
func sessionDidBecomeInactive(_ session: WCSession) {
@@ -161,7 +153,6 @@ final class WatchDependenciesSynchronizer: NSObject, WCSessionDelegate {
161153

162154
func sessionDidDeactivate(_ session: WCSession) {
163155
// Try to guarantee an active session
164-
self.isSessionActive = false
165156
watchSession.activate()
166157
}
167158
}
@@ -201,10 +192,8 @@ extension WatchDependenciesSynchronizer {
201192

202193
extension WatchDependenciesSynchronizer {
203194
enum SyncError: Error {
204-
case missingStoreDetailsOrCredentials
205195
case watchSessionInactiveOrNotPaired
206196
case noDependenciesFound
207-
case invalidApplicationContext
208197
case encodingApplicationContextFailed
209198
}
210199
}

WooCommerce/Woo Watch App/ConnectView.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ struct ConnectView: View {
77

88
@EnvironmentObject private var tracksProvider: WatchTracksProvider
99

10+
@State private var didRequestSyncing = false
11+
1012
let synchronizer: PhoneDependenciesSynchronizer
1113

1214
let message: String = Localization.connectMessage
@@ -18,9 +20,11 @@ struct ConnectView: View {
1820
.multilineTextAlignment(.center)
1921
.fixedSize(horizontal: false, vertical: true)
2022

21-
Text(Localization.workaroundTip)
22-
.multilineTextAlignment(.center)
23-
.fixedSize(horizontal: false, vertical: true)
23+
if didRequestSyncing {
24+
Text(Localization.workaroundTip)
25+
.multilineTextAlignment(.center)
26+
.fixedSize(horizontal: false, vertical: true)
27+
}
2428

2529
Image(systemName: "bolt.fill")
2630
.renderingMode(.original)
@@ -30,6 +34,7 @@ struct ConnectView: View {
3034

3135
Button(Localization.itsNotWorking) {
3236
synchronizer.requestCredentialSync()
37+
didRequestSyncing = true
3338
}
3439
}
3540
}

0 commit comments

Comments
 (0)