Wait for auth context to become ready, display progress

This commit is contained in:
Peter 2019-07-26 15:07:05 +01:00
parent 3999c124b8
commit bb19f8473e
3 changed files with 19 additions and 5 deletions

View File

@ -1046,15 +1046,16 @@ final class SharedApplicationContext {
} }
self.authContextValue = context self.authContextValue = context
if let context = context { if let context = context {
let isReady: Signal<Bool, NoError> = .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<Bool, NoError> = context.isReady.get()
authContextReadyDisposable.set((isReady authContextReadyDisposable.set((isReady
|> filter { $0 } |> filter { $0 }
|> take(1) |> take(1)
|> deliverOnMainQueue).start(next: { _ in |> deliverOnMainQueue).start(next: { _ in
self.mainWindow.present(context.rootController, on: .root) statusController.dismiss()
//self.mainWindow.viewController = context.rootController self.mainWindow.present(context.rootController, on: .root) }))
//self.mainWindow.topLevelOverlayControllers = context.overlayControllers
}))
} else { } else {
authContextReadyDisposable.set(nil) authContextReadyDisposable.set(nil)
} }

View File

@ -23,12 +23,15 @@ final class UnauthorizedApplicationContext {
let rootController: AuthorizationSequenceController let rootController: AuthorizationSequenceController
let isReady = Promise<Bool>()
init(apiId: Int32, apiHash: String, sharedContext: SharedAccountContext, account: UnauthorizedAccount, otherAccountPhoneNumbers: ((String, AccountRecordId, Bool)?, [(String, AccountRecordId, Bool)])) { init(apiId: Int32, apiHash: String, sharedContext: SharedAccountContext, account: UnauthorizedAccount, otherAccountPhoneNumbers: ((String, AccountRecordId, Bool)?, [(String, AccountRecordId, Bool)])) {
self.sharedContext = sharedContext self.sharedContext = sharedContext
self.account = account self.account = account
let presentationData = sharedContext.currentPresentationData.with { $0 } 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.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 account.shouldBeServiceTaskMaster.set(sharedContext.applicationBindings.applicationInForeground |> map { value -> AccountServiceTaskMasterMode in
if value { if value {

View File

@ -38,6 +38,12 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
private var didPlayPresentationAnimation = false private var didPlayPresentationAnimation = false
private let _ready = Promise<Bool>()
override public var ready: Promise<Bool> {
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) { 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.sharedContext = sharedContext
self.account = account self.account = account
@ -770,6 +776,10 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
if wasEmpty { if wasEmpty {
self.topViewController?.view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3) 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) { public func applyConfirmationCode(_ code: Int) {