-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
Generated by 🚫 Danger |
|
App Name | ![]() |
|
Configuration | Release-Alpha | |
Build Number | pr24216-f95be44 | |
Version | 25.8 | |
Bundle ID | org.wordpress.alpha | |
Commit | f95be44 | |
App Center Build | WPiOS - One-Offs #11719 |
|
App Name | ![]() |
|
Configuration | Release-Alpha | |
Build Number | pr24216-f95be44 | |
Version | 25.8 | |
Bundle ID | com.jetpack.alpha | |
Commit | f95be44 | |
App Center Build | jetpack-installable-builds #10748 |
c048ff5
to
287888f
Compare
// 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.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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... 😞
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) | ||
} | ||
} |
There was a problem hiding this comment.
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>"; }; |
There was a problem hiding this comment.
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 🤔
287888f
to
102c619
Compare
There was a problem hiding this 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!
Notice we implemented it one step at a time and used it in the Objective-C implementation all along to ensure the tests passed. Now that everything is green, we can swap at the consuming code level.
102c619
to
93d597c
Compare
Blog
andWPAccount
useWPUserAgent
. In the context of establishing a shared data layer, #24165, we need to first pushWPUserAgent
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.