From bb19f8473e0e69fa97ec2630a9796428f284816c Mon Sep 17 00:00:00 2001 From: Peter <> Date: Fri, 26 Jul 2019 15:07:05 +0100 Subject: [PATCH] Wait for auth context to become ready, display progress --- submodules/TelegramUI/TelegramUI/AppDelegate.swift | 11 ++++++----- .../TelegramUI/TelegramUI/ApplicationContext.swift | 3 +++ .../TelegramUI/AuthorizationSequenceController.swift | 10 ++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/submodules/TelegramUI/TelegramUI/AppDelegate.swift b/submodules/TelegramUI/TelegramUI/AppDelegate.swift index 24d8d7fec5..aabd122420 100644 --- a/submodules/TelegramUI/TelegramUI/AppDelegate.swift +++ b/submodules/TelegramUI/TelegramUI/AppDelegate.swift @@ -1046,15 +1046,16 @@ final class SharedApplicationContext { } self.authContextValue = context if let context = context { - let isReady: Signal = .single(true) + let presentationData = context.sharedContext.currentPresentationData.with({ $0 }) + let statusController = OverlayStatusController(theme: presentationData.theme, strings: presentationData.strings, type: .loading(cancelled: nil)) + self.mainWindow.present(statusController, on: .root) + let isReady: Signal = context.isReady.get() authContextReadyDisposable.set((isReady |> filter { $0 } |> take(1) |> deliverOnMainQueue).start(next: { _ in - self.mainWindow.present(context.rootController, on: .root) - //self.mainWindow.viewController = context.rootController - //self.mainWindow.topLevelOverlayControllers = context.overlayControllers - })) + statusController.dismiss() + self.mainWindow.present(context.rootController, on: .root) })) } else { authContextReadyDisposable.set(nil) } diff --git a/submodules/TelegramUI/TelegramUI/ApplicationContext.swift b/submodules/TelegramUI/TelegramUI/ApplicationContext.swift index f9a7928f99..a9bc9d1e58 100644 --- a/submodules/TelegramUI/TelegramUI/ApplicationContext.swift +++ b/submodules/TelegramUI/TelegramUI/ApplicationContext.swift @@ -23,12 +23,15 @@ final class UnauthorizedApplicationContext { let rootController: AuthorizationSequenceController + let isReady = Promise() + init(apiId: Int32, apiHash: String, sharedContext: SharedAccountContext, account: UnauthorizedAccount, otherAccountPhoneNumbers: ((String, AccountRecordId, Bool)?, [(String, AccountRecordId, Bool)])) { self.sharedContext = sharedContext self.account = account let presentationData = sharedContext.currentPresentationData.with { $0 } self.rootController = AuthorizationSequenceController(sharedContext: sharedContext, account: account, otherAccountPhoneNumbers: otherAccountPhoneNumbers, strings: presentationData.strings, theme: presentationData.theme, openUrl: sharedContext.applicationBindings.openUrl, apiId: apiId, apiHash: apiHash) + self.isReady.set(self.rootController.ready.get()) account.shouldBeServiceTaskMaster.set(sharedContext.applicationBindings.applicationInForeground |> map { value -> AccountServiceTaskMasterMode in if value { diff --git a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceController.swift b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceController.swift index 323be5f7c1..5e46070eee 100644 --- a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceController.swift +++ b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceController.swift @@ -38,6 +38,12 @@ public final class AuthorizationSequenceController: NavigationController, MFMail private var didPlayPresentationAnimation = false + private let _ready = Promise() + override public var ready: Promise { + return self._ready + } + private var didSetReady = false + public init(sharedContext: SharedAccountContext, account: UnauthorizedAccount, otherAccountPhoneNumbers: ((String, AccountRecordId, Bool)?, [(String, AccountRecordId, Bool)]), strings: PresentationStrings, theme: PresentationTheme, openUrl: @escaping (String) -> Void, apiId: Int32, apiHash: String) { self.sharedContext = sharedContext self.account = account @@ -770,6 +776,10 @@ public final class AuthorizationSequenceController: NavigationController, MFMail if wasEmpty { self.topViewController?.view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3) } + if !self.didSetReady { + self.didSetReady = true + self._ready.set(.single(true)) + } } public func applyConfirmationCode(_ code: Int) {