mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-13 00:33:28 +01:00
refactor: Reduce duplication code with UIApplication.keyWindow and .topController and improve alert function
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user