refactor: Reduce duplication code with UIApplication.keyWindow and .topController and improve alert function

This commit is contained in:
naturecodevoid
2023-06-01 07:35:07 -07:00
parent f69ad9830a
commit 175b5bec95
9 changed files with 57 additions and 57 deletions

View File

@@ -297,7 +297,7 @@ private extension AuthenticationOperation
func present(_ viewController: UIViewController) -> Bool
{
if UnstableFeatures.enabled(.swiftUI) {
UIApplication.shared.keyWindow?.rootViewController?.present(viewController, animated: true)
UIApplication.topController?.present(viewController, animated: true)
} else {
guard let presentingViewController = self.presentingViewController else { return false }
@@ -324,7 +324,7 @@ private extension AuthenticationOperation
if let presentingViewController {
presentingViewController.dismiss(animated: true)
}
// UIApplication.shared.keyWindow?.rootViewController?.presentedViewController?.dismiss(animated: true)
// UIApplication.topController?.dismiss(animated: true)
}
}
@@ -450,15 +450,7 @@ private extension AuthenticationOperation
completionHandler(nil)
})
let keyWindow = UIApplication.shared.windows.filter { $0.isKeyWindow }.first
if var topController = keyWindow?.rootViewController {
while let presentedViewController = topController.presentedViewController {
topController = presentedViewController
}
topController.present(alertController, animated: true, completion: nil)
}
UIApplication.topController?.present(alertController, animated: true, completion: nil)
}
}

View File

@@ -156,14 +156,8 @@ final class FetchAnisetteDataOperation: ResultOperation<ALTAnisetteData>, WebSoc
self.finish(.failure(OperationError.cancelled))
}))
let keyWindow = UIApplication.shared.windows.filter { $0.isKeyWindow }.first
DispatchQueue.main.async {
if let presentingController = keyWindow?.rootViewController?.presentedViewController {
presentingController.present(alert, animated: true)
} else {
keyWindow?.rootViewController?.present(alert, animated: true)
}
UIApplication.topController?.present(alert, animated: true)
}
}

View File

@@ -187,11 +187,7 @@ final class InstallAppOperation: ResultOperation<InstalledApp>
}))
DispatchQueue.main.async {
let keyWindow = UIApplication.shared.windows.filter { $0.isKeyWindow }.first
if var topController = keyWindow?.rootViewController {
while let presentedViewController = topController.presentedViewController {
topController = presentedViewController
}
if var topController = UIApplication.topController {
topController.present(alert, animated: true)
} else {
print("No key window? Let's just open Safari")