Files
Morgan Pretty 1dd8e8f197 Merge remote-tracking branch 'upstream/dev' into feature/groups-rebuild
# Conflicts:
#	Session.xcodeproj/project.pbxproj
#	Session/Calls/Views & Modals/IncomingCallBanner.swift
#	Session/Calls/WebRTC/WebRTCSession.swift
#	Session/Conversations/ConversationVC+Interaction.swift
#	Session/Conversations/ConversationVC.swift
#	Session/Conversations/ConversationViewModel.swift
#	Session/Conversations/Settings/ThreadSettingsViewModel.swift
#	Session/Home/GlobalSearch/GlobalSearchViewController.swift
#	Session/Home/HomeVC.swift
#	Session/Home/Message Requests/MessageRequestsViewModel.swift
#	Session/Meta/AppDelegate.swift
#	Session/Meta/AppEnvironment.swift
#	Session/Meta/SessionApp.swift
#	Session/Notifications/NotificationPresenter.swift
#	Session/Notifications/PushRegistrationManager.swift
#	Session/Notifications/UserNotificationsAdaptee.swift
#	Session/Onboarding/Onboarding.swift
#	Session/Open Groups/JoinOpenGroupVC.swift
#	Session/Utilities/IP2Country.swift
#	Session/Utilities/MockDataGenerator.swift
#	Session/Utilities/UIContextualAction+Utilities.swift
#	SessionMessagingKit/Calls/CallManagerProtocol.swift
#	SessionMessagingKit/Database/Migrations/_013_SessionUtilChanges.swift
#	SessionMessagingKit/Database/Migrations/_014_GenerateInitialUserConfigDumps.swift
#	SessionMessagingKit/Database/Models/ClosedGroup.swift
#	SessionMessagingKit/Database/Models/Interaction.swift
#	SessionMessagingKit/Database/Models/SessionThread.swift
#	SessionMessagingKit/Jobs/DisappearingMessagesJob.swift
#	SessionMessagingKit/Jobs/Types/GroupLeavingJob.swift
#	SessionMessagingKit/LibSession/Config Handling/LibSession+Contacts.swift
#	SessionMessagingKit/LibSession/Config Handling/LibSession+ConvoInfoVolatile.swift
#	SessionMessagingKit/LibSession/Config Handling/LibSession+Shared.swift
#	SessionMessagingKit/LibSession/Config Handling/LibSession+UserGroups.swift
#	SessionMessagingKit/LibSession/Config Handling/LibSession+UserProfile.swift
#	SessionMessagingKit/LibSession/Database/QueryInterfaceRequest+Utilities.swift
#	SessionMessagingKit/LibSession/LibSession+SessionMessagingKit.swift
#	SessionMessagingKit/Open Groups/OpenGroupManager.swift
#	SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+Calls.swift
#	SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+LegacyClosedGroups.swift
#	SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+MessageRequests.swift
#	SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+VisibleMessages.swift
#	SessionMessagingKit/Sending & Receiving/Message Handling/MessageSender+LegacyClosedGroups.swift
#	SessionMessagingKit/Sending & Receiving/Pollers/CurrentUserPoller.swift
#	SessionMessagingKit/Sending & Receiving/Pollers/OpenGroupPoller.swift
#	SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift
#	SessionMessagingKit/Sending & Receiving/Typing Indicators/TypingIndicators.swift
#	SessionMessagingKit/Utilities/AppReadiness.swift
#	SessionMessagingKit/Utilities/Preferences.swift
#	SessionMessagingKit/Utilities/ProfileManager.swift
#	SessionMessagingKit/Utilities/SessionEnvironment.swift
#	SessionMessagingKitTests/Jobs/MessageSendJobSpec.swift
#	SessionMessagingKitTests/Open Groups/OpenGroupManagerSpec.swift
#	SessionNotificationServiceExtension/NotificationServiceExtension.swift
#	SessionShareExtension/ShareNavController.swift
#	SessionSnodeKit/LibSession/LibSession+Networking.swift
#	SessionSnodeKit/Networking/SnodeAPI.swift
#	SessionUIKit/Components/PlaceholderIcon.swift
#	SessionUIKit/Utilities/UIContextualAction+Theming.swift
#	SessionUtilitiesKit/Crypto/Crypto.swift
#	SessionUtilitiesKit/Database/Storage.swift
#	SessionUtilitiesKit/Database/Types/Migration.swift
#	SessionUtilitiesKit/Database/Utilities/Database+Utilities.swift
#	SessionUtilitiesKit/General/AppContext.swift
#	SessionUtilitiesKit/General/Atomic.swift
#	SessionUtilitiesKit/General/Caches.swift
#	SessionUtilitiesKit/General/Dependencies.swift
#	SessionUtilitiesKit/General/FileSystem.swift
#	SessionUtilitiesKit/General/Logging.swift
#	SessionUtilitiesKit/General/SNUserDefaults.swift
#	SessionUtilitiesKit/JobRunner/JobRunner.swift
#	SessionUtilitiesKit/Types/BackgroundTaskManager.swift
#	SessionUtilitiesKit/Types/KeychainStorage.swift
#	SignalUtilitiesKit/Utilities/AppSetup.swift
#	_SharedTestUtilities/Mock.swift
#	_SharedTestUtilities/MockCaches.swift
#	_SharedTestUtilities/NimbleExtensions.swift
2025-01-09 09:15:13 +11:00

75 lines
2.4 KiB
Swift

// Copyright © 2024 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import SessionUtilitiesKit
// MARK: - Singleton
public extension Singleton {
static let appReadiness: SingletonConfig<AppReadiness> = Dependencies.create(
identifier: "appReadiness",
createInstance: { _ in AppReadiness() }
)
}
// MARK: - AppReadiness
public class AppReadiness {
public private(set) var isAppReady: Bool = false
@ThreadSafeObject private var appWillBecomeReadyBlocks: [() -> ()] = []
@ThreadSafeObject private var appDidBecomeReadyBlocks: [() -> ()] = []
public func setAppReady() {
guard Thread.isMainThread else {
DispatchQueue.main.async { [weak self] in self?.setAppReady() }
return
}
// Update the flag
isAppReady = true
// Trigure the closures
let willBecomeReadyClosures: [() -> ()] = appWillBecomeReadyBlocks
let didBecomeReadyClosures: [() -> ()] = appDidBecomeReadyBlocks
_appWillBecomeReadyBlocks.set(to: [])
_appDidBecomeReadyBlocks.set(to: [])
willBecomeReadyClosures.forEach { $0() }
didBecomeReadyClosures.forEach { $0() }
}
public func invalidate() {
isAppReady = false
}
public func runNowOrWhenAppWillBecomeReady(closure: @escaping () -> ()) {
// We don't need to do any "on app ready" work in the tests.
guard !SNUtilitiesKit.isRunningTests else { return }
guard !isAppReady else {
guard Thread.isMainThread else {
DispatchQueue.main.async { [weak self] in self?.runNowOrWhenAppWillBecomeReady(closure: closure) }
return
}
return closure()
}
_appWillBecomeReadyBlocks.performUpdate { $0.appending(closure) }
}
public func runNowOrWhenAppDidBecomeReady(closure: @escaping () -> ()) {
// We don't need to do any "on app ready" work in the tests.
guard !SNUtilitiesKit.isRunningTests else { return }
guard !isAppReady else {
guard Thread.isMainThread else {
DispatchQueue.main.async { [weak self] in self?.runNowOrWhenAppDidBecomeReady(closure: closure) }
return
}
return closure()
}
_appDidBecomeReadyBlocks.performUpdate { $0.appending(closure) }
}
}