From 58fa0f82c6383e7c04216eafd98407baad5cb1bd Mon Sep 17 00:00:00 2001 From: Adam Borbas Date: Mon, 1 Dec 2025 11:09:07 +0100 Subject: [PATCH 1/3] Call initializeAfterDependenciesAreInitialized in SceneDelegaet --- WooCommerce/Classes/AppDelegate.swift | 8 +++----- WooCommerce/Classes/SceneDelegate.swift | 6 ++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/WooCommerce/Classes/AppDelegate.swift b/WooCommerce/Classes/AppDelegate.swift index 2fea14fc34e..a9fa40c0bf8 100644 --- a/WooCommerce/Classes/AppDelegate.swift +++ b/WooCommerce/Classes/AppDelegate.swift @@ -54,16 +54,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Setup Components setupStartupWaitingTimeTracker() - let stores = ServiceLocator.stores let analytics = ServiceLocator.analytics let pushNotesManager = ServiceLocator.pushNotesManager - stores.initializeAfterDependenciesAreInitialized() setupAnalytics(analytics) setupCocoaLumberjack() setupLibraryLogger() setupLogLevel(.verbose) - setupPushNotificationsManagerIfPossible(pushNotesManager, stores: stores) + setupPushNotificationsManagerIfPossible(pushNotesManager) setupAppRatingManager() setupWormholy() setupKeyboardStateProvider() @@ -268,7 +266,7 @@ extension AppDelegate { /// Push Notifications: Authorization + Registration! /// // periphery: ignore - Fails when build on simulator - func setupPushNotificationsManagerIfPossible(_ pushNotesManager: PushNotesManager, stores: StoresManager) { + func setupPushNotificationsManagerIfPossible(_ pushNotesManager: PushNotesManager) { #if targetEnvironment(simulator) DDLogVerbose("👀 Push Notifications are not supported in the Simulator!") #else @@ -417,7 +415,7 @@ extension AppDelegate { /// Runs whenever the Authentication Flow is completed successfully. /// func authenticatorWasDismissed() { - setupPushNotificationsManagerIfPossible(ServiceLocator.pushNotesManager, stores: ServiceLocator.stores) + setupPushNotificationsManagerIfPossible(ServiceLocator.pushNotesManager) requirementsChecker.checkEligibilityForDefaultStore() } } diff --git a/WooCommerce/Classes/SceneDelegate.swift b/WooCommerce/Classes/SceneDelegate.swift index 57556d603c5..4c7bf7d2694 100644 --- a/WooCommerce/Classes/SceneDelegate.swift +++ b/WooCommerce/Classes/SceneDelegate.swift @@ -21,6 +21,12 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate { self.appCoordinator = coordinator coordinator.start() + /// IMPORTANT: + /// `AppCoordinator.start()` must be called before this, so that + /// AuthenticationManager.initialize() has already initialized WordPressAuthenticator. + /// See AuthenticationManager.hasInitializedAuthenticator and restoreWordPressSite(). + ServiceLocator.stores.initializeAfterDependenciesAreInitialized() + // Scene-scoped initializations that need UI setupNoticePresenter() setupUniversalLinkRouter() From 68923c02a47eed864c465872003f1339b14b049e Mon Sep 17 00:00:00 2001 From: Adam Borbas Date: Mon, 1 Dec 2025 13:46:29 +0100 Subject: [PATCH 2/3] Rather explicitly call authenticationManager.initialize() --- WooCommerce/Classes/AppDelegate.swift | 2 ++ WooCommerce/Classes/SceneDelegate.swift | 6 ------ WooCommerce/Classes/ViewRelated/AppCoordinator.swift | 1 - 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/WooCommerce/Classes/AppDelegate.swift b/WooCommerce/Classes/AppDelegate.swift index a9fa40c0bf8..40b498ebf98 100644 --- a/WooCommerce/Classes/AppDelegate.swift +++ b/WooCommerce/Classes/AppDelegate.swift @@ -57,6 +57,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let analytics = ServiceLocator.analytics let pushNotesManager = ServiceLocator.pushNotesManager setupAnalytics(analytics) + ServiceLocator.authenticationManager.initialize() + ServiceLocator.stores.initializeAfterDependenciesAreInitialized() setupCocoaLumberjack() setupLibraryLogger() diff --git a/WooCommerce/Classes/SceneDelegate.swift b/WooCommerce/Classes/SceneDelegate.swift index 4c7bf7d2694..57556d603c5 100644 --- a/WooCommerce/Classes/SceneDelegate.swift +++ b/WooCommerce/Classes/SceneDelegate.swift @@ -21,12 +21,6 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate { self.appCoordinator = coordinator coordinator.start() - /// IMPORTANT: - /// `AppCoordinator.start()` must be called before this, so that - /// AuthenticationManager.initialize() has already initialized WordPressAuthenticator. - /// See AuthenticationManager.hasInitializedAuthenticator and restoreWordPressSite(). - ServiceLocator.stores.initializeAfterDependenciesAreInitialized() - // Scene-scoped initializations that need UI setupNoticePresenter() setupUniversalLinkRouter() diff --git a/WooCommerce/Classes/ViewRelated/AppCoordinator.swift b/WooCommerce/Classes/ViewRelated/AppCoordinator.swift index d68eada9efb..602d8de5ad8 100644 --- a/WooCommerce/Classes/ViewRelated/AppCoordinator.swift +++ b/WooCommerce/Classes/ViewRelated/AppCoordinator.swift @@ -238,7 +238,6 @@ private extension AppCoordinator { /// Configures the WPAuthenticator for usage in both logged-in and logged-out states. func configureAuthenticator() { - authenticationManager.initialize() authenticationManager.setLoggedOutAppSettings(loggedOutAppSettings) authenticationManager.displayAuthenticatorIfLoggedOut = { [weak self] in guard let self, self.isLoggedIn == false else { return nil } From 8c8e8284fa4c471ce7170ec27dc599f8eb5ea308 Mon Sep 17 00:00:00 2001 From: Adam Borbas Date: Mon, 1 Dec 2025 14:43:16 +0100 Subject: [PATCH 3/3] Protect againts double initi --- .../Classes/Authentication/AuthenticationManager.swift | 4 ++++ WooCommerce/Classes/ViewRelated/AppCoordinator.swift | 1 + 2 files changed, 5 insertions(+) diff --git a/WooCommerce/Classes/Authentication/AuthenticationManager.swift b/WooCommerce/Classes/Authentication/AuthenticationManager.swift index b553be3e604..2eaaf4aebb3 100644 --- a/WooCommerce/Classes/Authentication/AuthenticationManager.swift +++ b/WooCommerce/Classes/Authentication/AuthenticationManager.swift @@ -65,6 +65,8 @@ class AuthenticationManager: Authentication { private let userDefaults: UserDefaults + private var initialized: Bool = false + init(stores: StoresManager = ServiceLocator.stores, storageManager: StorageManagerType = ServiceLocator.storageManager, featureFlagService: FeatureFlagService = ServiceLocator.featureFlagService, @@ -84,6 +86,8 @@ class AuthenticationManager: Authentication { /// Initializes the WordPress Authenticator. /// func initialize() { + guard !initialized else { return } + initialized = true WordPressAuthenticator.initializeWithCustomConfigs() WordPressAuthenticator.shared.delegate = self } diff --git a/WooCommerce/Classes/ViewRelated/AppCoordinator.swift b/WooCommerce/Classes/ViewRelated/AppCoordinator.swift index 602d8de5ad8..d68eada9efb 100644 --- a/WooCommerce/Classes/ViewRelated/AppCoordinator.swift +++ b/WooCommerce/Classes/ViewRelated/AppCoordinator.swift @@ -238,6 +238,7 @@ private extension AppCoordinator { /// Configures the WPAuthenticator for usage in both logged-in and logged-out states. func configureAuthenticator() { + authenticationManager.initialize() authenticationManager.setLoggedOutAppSettings(loggedOutAppSettings) authenticationManager.displayAuthenticatorIfLoggedOut = { [weak self] in guard let self, self.isLoggedIn == false else { return nil }