Skip to content

Commit 952c259

Browse files
Fix: avoid initializing RootViewCoordinator from a background thread
when checking if JP features are enabled
1 parent 7631778 commit 952c259

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

WordPress/Classes/ViewRelated/Jetpack/Branding/Coordinator/JetpackFeaturesRemovalCoordinator.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,43 @@ class JetpackFeaturesRemovalCoordinator: NSObject {
138138
}
139139

140140
/// Used to determine if the Jetpack features are enabled based on the current app UI type.
141+
/// This way we ensure features are not removed before reloading the UI.
142+
/// But if this function is called from a background thread, we determine if the Jetpack Features
143+
/// are enabled based on the removal phase regardless of the app UI state.
141144
/// Default root view coordinator is used.
142145
@objc
143146
static func jetpackFeaturesEnabled() -> Bool {
147+
guard Thread.isMainThread else {
148+
return shouldEnableJetpackFeatures()
149+
}
144150
return jetpackFeaturesEnabled(rootViewCoordinator: .shared)
145151
}
146152

147153
/// Used to determine if the Jetpack features are enabled based on the current app UI type.
148154
/// This way we ensure features are not removed before reloading the UI.
155+
/// But if this function is called from a background thread, we determine if the Jetpack Features
156+
/// are enabled based on the removal phase regardless of the app UI state.
149157
/// Using two separate methods (rather than one method with a default argument) because Obj-C.
150158
/// - Returns: `true` if UI type is normal, and `false` if UI type is simplified.
151159
static func jetpackFeaturesEnabled(rootViewCoordinator: RootViewCoordinator) -> Bool {
160+
guard Thread.isMainThread else {
161+
return shouldEnableJetpackFeatures()
162+
}
152163
return rootViewCoordinator.currentAppUIType == .normal
153164
}
154165

166+
167+
/// Used to determine if the Jetpack features are enabled based on the removal phase regardless of the app UI state.
168+
private static func shouldEnableJetpackFeatures(featureFlagStore: RemoteFeatureFlagStore = RemoteFeatureFlagStore()) -> Bool {
169+
let phase = generalPhase()
170+
switch phase {
171+
case .four, .newUsers, .selfHosted:
172+
return false
173+
default:
174+
return true
175+
}
176+
}
177+
155178
/// Used to display feature-specific or feature-collection overlays.
156179
/// - Parameters:
157180
/// - viewController: The view controller where the overlay should be presented in.

0 commit comments

Comments
 (0)