-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[v11] Replace Auth worker queue with an actor - checkpoint WIP #13246
base: main
Are you sure you want to change the base?
Conversation
forName: UIApplication.didBecomeActiveNotification, | ||
object: nil, queue: nil | ||
) { notification in | ||
self.isAppInBackground = false |
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 is ported unchanged from the old PR, but why not use applicationState
instead of manually tracking the state?
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.
Looks like it would be a good improvement to eliminate self.isAppInBackground
, but outside the scope of this PR.
Generated by 🚫 Danger |
#if canImport(UIKit) // Is a similar mechanism needed on macOS? | ||
applicationDidBecomeActiveObserver = | ||
NotificationCenter.default.addObserver( | ||
forName: UIApplication.didBecomeActiveNotification, |
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'm wondering what happen with app extensions, in this way I think UIApplication.didBecomeActiveNotification and didEnterBackgroundNotification would not be fired @paulb777
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.
Good question. This implementation should match the current Objective-C one. Do you see an issue?
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.
Sure, even the didBecomeActiveNotification is available on extensions (imported via UIKit) and the other one as well, it won't be fired. so I would check if it is an extension or not using for example the following code:
var isRunningInExtension: Bool {
// Check if the bundle path ends with `.appex` (for iOS)
let bundlePath = Bundle.main.bundlePath
let isBundlePathExtension = bundlePath.hasSuffix(".appex")
// Check if the `NSExtension` key exists in the `Info.plist`
let isNSExtensionPresent = (Bundle.main.infoDictionary?["NSExtension"] as? [String: Any]) != nil
return isBundlePathExtension || isNSExtensionPresent
}
And In case of being true (the output) try to make a check in other way. Dispatch Queues with async after a time don't work on certain extensions as well as timers ... (Because apple timers and dispatch async after tend to sleep when the device is locked or with no activity for a long time) So you can take another approach like going with a counter with the system clock or infinite loop. They are not good approaches but extensions are very restricted. My suggestion in this case is surround with an if the observers and delegate in developers to run any kinda code, calling a func, when activity is registered on their extensions, in this way you won't impact performance in extensions.
kAuthGlobalWorkQueue.sync { | ||
self.requestConfiguration.languageCode = Locale.preferredLanguages.first | ||
} | ||
setLanguageCode(Locale.preferredLanguages.first) | ||
} | ||
|
||
/// Configures Firebase Auth to connect to an emulated host instead of the remote backend. | ||
@objc open func useEmulator(withHost host: String, port: Int) { |
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 think this code shouldn't be on a production framework cause it won't happen. Is there any way get rid of it without removing the ability to use it whereas developers are coding or testing on pre-production environments?
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 could be possible, but I'm not convinced the usability impact would be worth the relatively small size overhead increase.
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.
Sure, maybe an approach like surrounding the function with a comment (one above and one to close it) or any kinda special macro compiler for those who wants to remove it from production could make the trick. Who wants to remove it from prod, could build the frameworks by itself.
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.
@jesus-mg-ios Thanks for taking a look!
#if canImport(UIKit) // Is a similar mechanism needed on macOS? | ||
applicationDidBecomeActiveObserver = | ||
NotificationCenter.default.addObserver( | ||
forName: UIApplication.didBecomeActiveNotification, |
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.
Good question. This implementation should match the current Objective-C one. Do you see an issue?
kAuthGlobalWorkQueue.sync { | ||
self.requestConfiguration.languageCode = Locale.preferredLanguages.first | ||
} | ||
setLanguageCode(Locale.preferredLanguages.first) | ||
} | ||
|
||
/// Configures Firebase Auth to connect to an emulated host instead of the remote backend. | ||
@objc open func useEmulator(withHost host: String, port: Int) { |
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 could be possible, but I'm not convinced the usability impact would be worth the relatively small size overhead increase.
Anytime |
Parts of this PR have been implemented in other PRs. The bulk of moving the auth worker to an actor may need to wait for a breaking change release since public APIs doing dispatch_sync's may need to be converted to async APIs - or other alternatives like part of initialization. Marking to be considered with Firebase 12 |
WIP checkpoint