Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

paulb777
Copy link
Member

@paulb777 paulb777 commented Jul 9, 2024

WIP checkpoint

forName: UIApplication.didBecomeActiveNotification,
object: nil, queue: nil
) { notification in
self.isAppInBackground = false
Copy link
Contributor

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?

Copy link
Member Author

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.

FirebaseAuth/Sources/Swift/Auth/AuthWorker.swift Outdated Show resolved Hide resolved
@google-oss-bot
Copy link

1 Warning
⚠️ Did you forget to add a changelog entry? (Add #no-changelog to the PR description to silence this warning.)

Generated by 🚫 Danger

#if canImport(UIKit) // Is a similar mechanism needed on macOS?
applicationDidBecomeActiveObserver =
NotificationCenter.default.addObserver(
forName: UIApplication.didBecomeActiveNotification,
Copy link

@jesus-mg-ios jesus-mg-ios Jul 16, 2024

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

Copy link
Member Author

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?

Copy link

@jesus-mg-ios jesus-mg-ios Jul 20, 2024

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) {

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?

Copy link
Member Author

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.

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.

Copy link
Member Author

@paulb777 paulb777 left a 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,
Copy link
Member Author

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?

FirebaseAuth/Sources/Swift/Auth/Auth.swift Outdated Show resolved Hide resolved
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) {
Copy link
Member Author

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.

@jesus-mg-ios
Copy link

@jesus-mg-ios Thanks for taking a look!

Anytime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants