Skip to content

Commit e5bec03

Browse files
authored
Fix crash caused by modifying the UI from a background thread (#20275)
2 parents 2ebf4a4 + 1724d71 commit e5bec03

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

RELEASE-NOTES.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
21.9
22
-----
33

4+
* [*] [internal] Refactored fetching posts in the Reader tab, including post related operations (i.e. like/unlike, save for latter, etc.) [#20197]
5+
* [**] Reader: Add a button in the post menu to block an author and stop seeing their posts. [#20193]
6+
* [**] [Jetpack-only] Jetpack individual plugin support: Warns user about sites with only individual plugins not supporting all features of the app yet and gives the ability to install the full Jetpack plugin. [#20223]
7+
* [**] [Jetpack-only] Help: Display the Jetpack app FAQ card on Help screen when switching from the WordPress app to the Jetpack app is complete. [#20232]
8+
* [***] [Jetpack-only] Blaze: We added support for Blaze in the app. The user can now promote a post or page from the app to reach new audiences. [#20253]
9+
10+
21.8.1
11+
-----
12+
13+
* [**] [internal] Fixes a crash that happens in the background when the weekly roundup notification is being processed. [#20275]
414

515
21.8
616
-----

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

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

117117
/// Used to determine if the Jetpack features are enabled based on the current app UI type.
118+
/// This way we ensure features are not removed before reloading the UI.
119+
/// But if this function is called from a background thread, we determine if the Jetpack Features
120+
/// are enabled based on the removal phase regardless of the app UI state.
118121
/// Default root view coordinator is used.
119122
@objc
120123
static func jetpackFeaturesEnabled() -> Bool {
124+
guard Thread.isMainThread else {
125+
return shouldEnableJetpackFeatures()
126+
}
121127
return jetpackFeaturesEnabled(rootViewCoordinator: .shared)
122128
}
123129

124130
/// Used to determine if the Jetpack features are enabled based on the current app UI type.
125131
/// This way we ensure features are not removed before reloading the UI.
132+
/// But if this function is called from a background thread, we determine if the Jetpack Features
133+
/// are enabled based on the removal phase regardless of the app UI state.
126134
/// Using two separate methods (rather than one method with a default argument) because Obj-C.
127135
/// - Returns: `true` if UI type is normal, and `false` if UI type is simplified.
128136
static func jetpackFeaturesEnabled(rootViewCoordinator: RootViewCoordinator) -> Bool {
137+
guard Thread.isMainThread else {
138+
return shouldEnableJetpackFeatures()
139+
}
129140
return rootViewCoordinator.currentAppUIType == .normal
130141
}
131142

143+
144+
/// Used to determine if the Jetpack features are enabled based on the removal phase regardless of the app UI state.
145+
private static func shouldEnableJetpackFeatures(featureFlagStore: RemoteFeatureFlagStore = RemoteFeatureFlagStore()) -> Bool {
146+
let phase = generalPhase()
147+
switch phase {
148+
case .four, .newUsers, .selfHosted:
149+
return false
150+
default:
151+
return true
152+
}
153+
}
154+
132155
/// Used to display feature-specific or feature-collection overlays.
133156
/// - Parameters:
134157
/// - viewController: The view controller where the overlay should be presented in.

0 commit comments

Comments
 (0)