mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 09:20:08 +00:00
Make app startup asynchronous
This commit is contained in:
parent
d8765b1b3d
commit
a3d7fe3006
@ -120,7 +120,7 @@ private enum QueuedWakeup: Int32 {
|
||||
case backgroundLocation
|
||||
}
|
||||
|
||||
private final class SharedApplicationContext {
|
||||
final class SharedApplicationContext {
|
||||
let sharedContext: SharedAccountContext
|
||||
let notificationManager: SharedNotificationManager
|
||||
let wakeupManager: SharedWakeupManager
|
||||
@ -571,14 +571,18 @@ private final class SharedApplicationContext {
|
||||
self.window?.rootViewController?.dismiss(animated: true, completion: nil)
|
||||
})
|
||||
|
||||
// Move back to signal
|
||||
let accountManagerSignal = Signal<AccountManager, NoError> { subscriber in
|
||||
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata")
|
||||
let upgradeSemaphore = DispatchSemaphore(value: 0)
|
||||
let _ = upgradedAccounts(accountManager: accountManager, rootPath: rootPath).start(completed: {
|
||||
upgradeSemaphore.signal()
|
||||
return upgradedAccounts(accountManager: accountManager, rootPath: rootPath).start(completed: {
|
||||
subscriber.putNext(accountManager)
|
||||
subscriber.putCompletion()
|
||||
})
|
||||
upgradeSemaphore.wait()
|
||||
return EmptyDisposable
|
||||
}
|
||||
|
||||
let sharedContextSignal = accountManagerSignal
|
||||
|> deliverOnMainQueue
|
||||
|> mapToSignal { accountManager -> Signal<(SharedApplicationContext, LoggingSettings), NoError> in
|
||||
var initialPresentationDataAndSettings: InitialPresentationDataAndSettings?
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
let _ = currentPresentationDataAndSettings(accountManager: accountManager).start(next: { value in
|
||||
@ -681,15 +685,17 @@ private final class SharedApplicationContext {
|
||||
return .single(nil)
|
||||
}
|
||||
}
|
||||
let wakeupManager = SharedWakeupManager(beginBackgroundTask: { name, expiration in application.beginBackgroundTask(withName: name, expirationHandler: expiration) }, endBackgroundTask: { id in application.endBackgroundTask(id) }, backgroundTimeRemaining: { application.backgroundTimeRemaining }, activeAccounts: sharedContext.activeAccounts |> map { ($0.0, $0.1.map { ($0.0, $0.1) }) }, liveLocationPolling: liveLocationPolling, watchTasks: watchTasks, inForeground: applicationBindings.applicationInForeground, hasActiveAudioSession: hasActiveAudioSession.get(), notificationManager: notificationManager, mediaManager: sharedContext.mediaManager, callManager: sharedContext.callManager, accountUserInterfaceInUse: { id in
|
||||
let wakeupManager = SharedWakeupManager(beginBackgroundTask: { name, expiration in application.beginBackgroundTask(withName: name, expirationHandler: expiration) }, endBackgroundTask: { id in application.endBackgroundTask(id) }, backgroundTimeRemaining: { application.backgroundTimeRemaining }, activeAccounts: sharedContext.activeAccounts |> map { ($0.0, $0.1.map { ($0.0, $0.1) }) }, liveLocationPolling: liveLocationPolling, watchTasks: watchTasks, inForeground: applicationBindings.applicationInForeground, hasActiveAudioSession: self.hasActiveAudioSession.get(), notificationManager: notificationManager, mediaManager: sharedContext.mediaManager, callManager: sharedContext.callManager, accountUserInterfaceInUse: { id in
|
||||
return sharedContext.accountUserInterfaceInUse(id)
|
||||
})
|
||||
let sharedApplicationContext = SharedApplicationContext(sharedContext: sharedContext, notificationManager: notificationManager, wakeupManager: wakeupManager)
|
||||
sharedApplicationContext.sharedContext.mediaManager.overlayMediaManager.attachOverlayMediaController(sharedApplicationContext.overlayMediaController)
|
||||
self.sharedContextPromise.set(
|
||||
accountManager.transaction { transaction -> (SharedApplicationContext, LoggingSettings) in
|
||||
|
||||
return accountManager.transaction { transaction -> (SharedApplicationContext, LoggingSettings) in
|
||||
return (sharedApplicationContext, transaction.getSharedData(SharedDataKeys.loggingSettings) as? LoggingSettings ?? LoggingSettings.defaultSettings)
|
||||
}
|
||||
}
|
||||
self.sharedContextPromise.set(sharedContextSignal
|
||||
|> mapToSignal { sharedApplicationContext, loggingSettings -> Signal<SharedApplicationContext, NoError> in
|
||||
Logger.shared.logToFile = loggingSettings.logToFile
|
||||
Logger.shared.logToConsole = loggingSettings.logToConsole
|
||||
@ -793,7 +799,7 @@ private final class SharedApplicationContext {
|
||||
|> map { accountAndSettings -> AuthorizedApplicationContext? in
|
||||
return accountAndSettings.flatMap { account, limitsConfiguration, callListSettings in
|
||||
let context = AccountContext(sharedContext: sharedApplicationContext.sharedContext, account: account, limitsConfiguration: limitsConfiguration)
|
||||
return AuthorizedApplicationContext(mainWindow: self.mainWindow, watchManagerArguments: watchManagerArgumentsPromise.get(), context: context, accountManager: sharedApplicationContext.sharedContext.accountManager, showCallsTab: callListSettings.showTab, reinitializedNotificationSettings: {
|
||||
return AuthorizedApplicationContext(sharedApplicationContext: sharedApplicationContext, mainWindow: self.mainWindow, watchManagerArguments: watchManagerArgumentsPromise.get(), context: context, accountManager: sharedApplicationContext.sharedContext.accountManager, showCallsTab: callListSettings.showTab, reinitializedNotificationSettings: {
|
||||
let _ = (self.context.get()
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { context in
|
||||
@ -932,7 +938,7 @@ private final class SharedApplicationContext {
|
||||
}
|
||||
return true
|
||||
})
|
||||
self.mainWindow.topLevelOverlayControllers = [sharedApplicationContext.overlayMediaController, context.notificationController]
|
||||
self.mainWindow.topLevelOverlayControllers = [context.sharedApplicationContext.overlayMediaController, context.notificationController]
|
||||
var authorizeNotifications = true
|
||||
if #available(iOS 10.0, *) {
|
||||
authorizeNotifications = false
|
||||
@ -979,7 +985,10 @@ private final class SharedApplicationContext {
|
||||
}))
|
||||
|
||||
self.watchCommunicationManagerPromise.set(watchCommunicationManager(context: self.context, allowBackgroundTimeExtension: { timeout in
|
||||
wakeupManager.allowBackgroundTimeExtension(timeout: timeout)
|
||||
let _ = (self.sharedContextPromise.get()
|
||||
|> take(1)).start(next: { sharedContext in
|
||||
sharedContext.wakeupManager.allowBackgroundTimeExtension(timeout: timeout)
|
||||
})
|
||||
}))
|
||||
let _ = self.watchCommunicationManagerPromise.get().start(next: { manager in
|
||||
if let manager = manager {
|
||||
@ -1059,9 +1068,11 @@ private final class SharedApplicationContext {
|
||||
}
|
||||
}))
|
||||
}
|
||||
if let sharedContext = strongSelf.contextValue?.context.sharedContext {
|
||||
let presentationData = sharedContext.currentPresentationData.with { $0 }
|
||||
strongSelf.mainWindow.present(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: presentationData.theme), title: alert.title, text: alert.message ?? "", actions: actions), on: .root)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
BITHockeyBaseManager.setPresentView({ [weak self] controller in
|
||||
|
||||
@ -46,6 +46,7 @@ private struct PasscodeState: Equatable {
|
||||
}
|
||||
|
||||
final class AuthorizedApplicationContext {
|
||||
let sharedApplicationContext: SharedApplicationContext
|
||||
let mainWindow: Window1
|
||||
let lockedCoveringView: LockedWindowCoveringView
|
||||
|
||||
@ -99,7 +100,9 @@ final class AuthorizedApplicationContext {
|
||||
private var showCallsTabDisposable: Disposable?
|
||||
private var enablePostboxTransactionsDiposable: Disposable?
|
||||
|
||||
init(mainWindow: Window1, watchManagerArguments: Signal<WatchManagerArguments?, NoError>, context: AccountContext, accountManager: AccountManager, showCallsTab: Bool, reinitializedNotificationSettings: @escaping () -> Void) {
|
||||
init(sharedApplicationContext: SharedApplicationContext, mainWindow: Window1, watchManagerArguments: Signal<WatchManagerArguments?, NoError>, context: AccountContext, accountManager: AccountManager, showCallsTab: Bool, reinitializedNotificationSettings: @escaping () -> Void) {
|
||||
self.sharedApplicationContext = sharedApplicationContext
|
||||
|
||||
setupLegacyComponents(context: context)
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 5debb55eb0cd0154b866857476bdfb8122308664
|
||||
Subproject commit eca5668fc9834be348e65edde3f4ec07eeffef0c
|
||||
@ -1 +1 @@
|
||||
Subproject commit eb72b51295e0b0b937d4c0af59adb4fdce4d67a7
|
||||
Subproject commit fdcc098f8050834dd936f53a4476ac529abe6a58
|
||||
@ -1 +1 @@
|
||||
Subproject commit ae83518e5a5fc2b79a9425891ad33962c3066ff9
|
||||
Subproject commit 40ad8ff62822372c08d7b4cb726316e5d0e5ac71
|
||||
Loading…
x
Reference in New Issue
Block a user