Skip to content

Extract WPUserAgent to WordPressShared #24216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 19, 2025
Merged

Conversation

mokagio
Copy link
Contributor

@mokagio mokagio commented Mar 14, 2025

Blog and WPAccount use WPUserAgent. In the context of establishing a shared data layer, #24165, we need to first push WPUserAgent to a shared location as well.

This turned out to be more complex than a simple file move to WordPressShared because WPUserAgent's implementation was spread between Objective-C and Swift, with the former accessing the latter.

I first rewrote WPUserAgent in Swift, then moved it.

I did this in small steps, see commits history, so that I could at least use the existing unit tests as a safety net.

I have some doubts on the implementation, previous and current, but I keep prioritizing getting the shared data layer in place to unblock building more apps than taking the time to better understand the code and maybe remove obsolete parts.

More in p1741863922055329-slack-C08HQR4C2TS

Testing I run WordPress on my device and tried loading a few different screens.

@dangermattic
Copy link
Collaborator

dangermattic commented Mar 14, 2025

3 Warnings
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ This PR is assigned to the milestone 25.9. This milestone is due in less than 4 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 14, 2025

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr24216-f95be44
Version25.8
Bundle IDorg.wordpress.alpha
Commitf95be44
App Center BuildWPiOS - One-Offs #11719
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 14, 2025

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr24216-f95be44
Version25.8
Bundle IDcom.jetpack.alpha
Commitf95be44
App Center Buildjetpack-installable-builds #10748
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@mokagio mokagio force-pushed the mokagio/extract-wpuseragent branch from c048ff5 to 287888f Compare March 14, 2025 05:20
@mokagio mokagio added this to the 25.9 milestone Mar 14, 2025
@mokagio mokagio self-assigned this Mar 14, 2025
@mokagio mokagio marked this pull request as ready for review March 14, 2025 05:31
Comment on lines 12 to 13
// TODO: Original implementation logged a message to Tracks/Sentry
DDLogError("This method for retrieveing the user agent seems to be no longer working. We need to figure out an alternative.")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like a job for wpAssertionFailure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly.

But wpAssertionFailure depends on Sentry and Tracks extracting that is it's own can of worms... 😞

Comment on lines +98 to +116
public extension WPUserAgent {

private static let userDefaults = UserPersistentStoreFactory.userDefaultsInstance()

@objc
static func defaultUserAgent() -> String {
defaultUserAgent(userDefaults: userDefaults)
}

@objc(wordPressUserAgent)
static func wordPress() -> String {
wordPressUserAgent(userDefaults: userDefaults)
}

@objc
static func useWordPressInWebViews() {
useWordPressInWebViews(userDefaults: userDefaults)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this thinking that the code would not have access to UserPersistentStoreFactory, so this would have stayed in the app target.

But I had forgotten about #24210

I suppose I could rewrite the definitions to use the default arguments? Or, this could stay the way it is and work as a reminder for code we should remove (i.e. the Objective-C implementation)?

@@ -2171,6 +2170,7 @@
3236F7A024B61B950088E8F3 /* ReaderInterestsDataSourceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReaderInterestsDataSourceTests.swift; sourceTree = "<group>"; };
32C6CDDA23A1FF0D002556FF /* SiteCreationRotatingMessageViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteCreationRotatingMessageViewTests.swift; sourceTree = "<group>"; };
374CB16115B93C0800DD0EBC /* AudioToolbox.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
3F03CD1B2D83BDA20047508B /* WPUserAgentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WPUserAgentTests.swift; sourceTree = "<group>"; };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should no longer be here 🤔

@mokagio mokagio force-pushed the mokagio/extract-wpuseragent branch from 287888f to 102c619 Compare March 14, 2025 05:42
Copy link
Contributor

@kean kean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see docs and modern tests. Thank you!

@mokagio mokagio force-pushed the mokagio/extract-wpuseragent branch from 102c619 to 93d597c Compare March 19, 2025 00:02
@mokagio mokagio enabled auto-merge March 19, 2025 00:35
@mokagio mokagio added this pull request to the merge queue Mar 19, 2025
Merged via the queue into trunk with commit b1c9731 Mar 19, 2025
25 checks passed
@mokagio mokagio deleted the mokagio/extract-wpuseragent branch March 19, 2025 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants