Skip to content

Commit 413d57e

Browse files
committed
refactor: modernize window handling and registry deps
Signed-off-by: William Richter <[email protected]>
1 parent ea7a033 commit 413d57e

20 files changed

+216
-112
lines changed

fearless.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
FAFEAA112DCF200100E5C0DE /* ReownWalletKit in Frameworks */ = {isa = PBXBuildFile; productRef = FAFEAA132DCF200100E5C0DE /* ReownWalletKit */; };
10+
FAE41F5B2C8CF4C900123456 /* SceneWindowFinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE41F5A2C8CF4C900123456 /* SceneWindowFinder.swift */; };
11+
FAFEAA112DCF200100E5C0DE /* ReownWalletKit in Frameworks */ = {isa = PBXBuildFile; productRef = FAFEAA132DCF200100E5C0DE /* ReownWalletKit */; };
1112
F1E2D3C4B5A60718293A4B5C /* GraphQLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1F2A3B4C5D60718293A4B5C /* GraphQLResponse.swift */; };
1213
BBCCDDEEAABB112233445566 /* XcmMinAmountInspectorShim.swift in Sources */ = {isa = PBXBuildFile; fileRef = AABBCCDDEEFF112233445566 /* XcmMinAmountInspectorShim.swift */; };
1314
012B4273E4109F0B65117BAE /* Identifiable+Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D4E5F60718293A4B5C /* Identifiable+Models.swift */; };
@@ -5840,6 +5841,7 @@ AA1111000011223344556678 /* WalletSelectAccountCommandFactory.swift in Sources *
58405841
FAD240DD2C64E97900B389FF /* KaiaHistoryResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KaiaHistoryResponse.swift; sourceTree = "<group>"; };
58415842
FAD240DF2C64EA1D00B389FF /* KaiaHistoryOperationFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KaiaHistoryOperationFactory.swift; sourceTree = "<group>"; };
58425843
FAD240E12C64EA6E00B389FF /* AssetTransactionData+KaiaHistory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AssetTransactionData+KaiaHistory.swift"; sourceTree = "<group>"; };
5844+
FAE41F5A2C8CF4C900123456 /* SceneWindowFinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneWindowFinder.swift; sourceTree = "<group>"; };
58435845
FAD428932A834A8E001D6A16 /* TopViewControllerHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopViewControllerHelper.swift; sourceTree = "<group>"; };
58445846
FAD428952A834BA8001D6A16 /* UIApplication+TopViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+TopViewController.swift"; sourceTree = "<group>"; };
58455847
FAD428972A860C9B001D6A16 /* EthereumNodeFetching.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumNodeFetching.swift; sourceTree = "<group>"; };
@@ -9396,6 +9398,7 @@ AA1111000011223344556676 /* WalletSelectAccountCommandFactory.swift */ = {isa =
93969398
C63FE88929000EB500E97E8E /* FearlessKeyboardHandler.swift */,
93979399
C665E4EF29C35801001946D1 /* TimeFormatter.swift */,
93989400
FAD428932A834A8E001D6A16 /* TopViewControllerHelper.swift */,
9401+
FAE41F5A2C8CF4C900123456 /* SceneWindowFinder.swift */,
93999402
FAD428972A860C9B001D6A16 /* EthereumNodeFetching.swift */,
94009403
FA584C792AB2BFE300F6F020 /* MediaType.swift */,
94019404
FAC6CDAE2BA81FA00013A17E /* WalletLoggerProtocol.swift */,
@@ -16677,6 +16680,7 @@ FAD429442A8A1A74001D6A16 /* Inject Google Keys */ = {
1667716680
8436EDE225895804004D9E97 /* RampProvider.swift in Sources */,
1667816681
849013AC24A80984008F705E /* AppDelegate.swift in Sources */,
1667916682
FAD428942A834A8E001D6A16 /* TopViewControllerHelper.swift in Sources */,
16683+
FAE41F5B2C8CF4C900123456 /* SceneWindowFinder.swift in Sources */,
1668016684
84CE69E82566750D00559427 /* ByteLengthProcessor.swift in Sources */,
1668116685
8494D87A2525350000614D8F /* SubscanStatusData.swift in Sources */,
1668216686
FA2FC7FF28B3807C00CC0A42 /* StakingPoolJoinChoosePoolAssembly.swift in Sources */,

fearless/ApplicationLayer/FearlessApplication.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,7 @@ class FearlessApplication: UIApplication {
4444
guard secretManager.checkSecret(for: KeystoreTag.pincode.rawValue) else {
4545
return
4646
}
47-
let window: UIWindow? = {
48-
if #available(iOS 13.0, *) {
49-
return UIApplication.shared.connectedScenes
50-
.compactMap { $0 as? UIWindowScene }
51-
.flatMap { $0.windows }
52-
.first { $0.isKeyWindow && !$0.isHidden }
53-
} else {
54-
return UIApplication.shared.keyWindow
55-
}
56-
}()
47+
let window = SceneWindowFinder.activeWindow()
5748
if let window = window {
5849
guard let pincodeViewController = PinViewFactory.createPinCheckView()?.controller else {
5950
return

fearless/Common/Animation/ModalSheetBlurPresentationAppearanceAnimator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension ModalSheetBlurPresentationAppearanceAnimator: UIViewControllerAnimated
5858
animator.animate(block: animationBlock, completionBlock: completionBlock)
5959
UIView.animate(withDuration: 0.1, delay: 0.15) {
6060
if
61-
let window = UIApplication.shared.keyWindow,
61+
let window = SceneWindowFinder.activeWindow(),
6262
let transitionView = window.subviews.first(where: { $0.tag == Self.UITransitionViewFearlessTag }),
6363
let blurView = transitionView.subviews.first(where: { $0.tag == Self.UIVisualEffectViewFearlessTag }) {
6464
blurView.alpha = 0

fearless/Common/Animation/ModalSheetBlurPresentationController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ final class ModalSheetBlurPresentationController: UIPresentationController {
7777

7878
override func dismissalTransitionWillBegin() {
7979
if
80-
let window = UIApplication.shared.keyWindow,
80+
let window = SceneWindowFinder.activeWindow(),
8181
let transitionView = window.subviews.first(
8282
where: { $0.tag == ModalSheetBlurPresentationAppearanceAnimator.UITransitionViewFearlessTag }
8383
),

fearless/Common/Animation/RootControllerAnimationCoordinator.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ extension RootControllerAnimationCoordinatorProtocol {
99
private func findWindow(from controller: UIViewController) -> UIWindow? {
1010
var window = controller.view.window
1111

12-
if window == nil, let appWindow = UIApplication.shared.delegate?.window {
13-
window = appWindow
12+
if window == nil {
13+
if #available(iOS 13.0, *) {
14+
window = SceneWindowFinder.activeWindow(from: controller.view.window?.windowScene)
15+
} else {
16+
window = UIApplication.shared.delegate?.window ?? UIApplication.shared.keyWindow
17+
}
1418
}
1519

1620
return window

fearless/Common/Extension/UIApplication+TopViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UIKit
22

33
extension UIApplication {
4-
class func topViewController(controller: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
4+
class func topViewController(controller: UIViewController? = SceneWindowFinder.activeWindow()?.rootViewController) -> UIViewController? {
55
if let navigationController = controller as? UINavigationController {
66
return topViewController(controller: navigationController.visibleViewController)
77
}

fearless/Common/Helpers/MainTransitionHelper.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ struct MainTransitionHelper {
1212
presentingController.dismiss(animated: animated, completion: nil)
1313
}
1414

15-
guard let tabBarController = UIApplication.shared
16-
.delegate?.window??.rootViewController as? UITabBarController
15+
guard let tabBarController = SceneWindowFinder.activeWindow()?.rootViewController as? UITabBarController
1716
else {
1817
return
1918
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import UIKit
2+
3+
enum SceneWindowFinder {
4+
static func activeWindow(from scene: UIWindowScene? = nil) -> UIWindow? {
5+
if #available(iOS 13.0, *) {
6+
let scenes: [UIWindowScene]
7+
if let scene = scene {
8+
scenes = [scene]
9+
} else {
10+
scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
11+
}
12+
13+
return scenes
14+
.filter { $0.activationState == .foregroundActive || $0.activationState == .foregroundInactive }
15+
.flatMap { $0.windows }
16+
.first { $0.isKeyWindow && !$0.isHidden }
17+
} else {
18+
return UIApplication.shared.keyWindow
19+
}
20+
}
21+
22+
static func statusPresentableWindow(from scene: UIWindowScene? = nil) -> ApplicationStatusPresentable? {
23+
activeWindow(from: scene) as? ApplicationStatusPresentable
24+
}
25+
}
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import UIKit
22

33
final class TopViewControllerHelper {
4-
static func getTopViewController() -> UIViewController? {
5-
let keyWindow = UIApplication.shared.windows.filter { $0.isKeyWindow }.first
6-
7-
if var topController = keyWindow?.rootViewController {
8-
while let presentedViewController = topController.presentedViewController {
9-
topController = presentedViewController
10-
}
4+
static func getTopViewController(from scene: UIWindowScene? = nil) -> UIViewController? {
5+
guard var topController = SceneWindowFinder.activeWindow(from: scene)?.rootViewController else {
6+
return nil
7+
}
118

12-
return topController
9+
while let presentedViewController = topController.presentedViewController {
10+
topController = presentedViewController
1311
}
1412

15-
return nil
13+
return topController
1614
}
1715
}

fearless/Common/Protocols/StatusPresentable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extension ApplicationStatusPresentable {
1111
with viewModel: ApplicationStatusAlertEvent,
1212
animated: Bool
1313
) {
14-
guard let window = UIApplication.shared.keyWindow as? ApplicationStatusPresentable else {
14+
guard let window = SceneWindowFinder.statusPresentableWindow() else {
1515
return
1616
}
1717
window.presentStatus(with: viewModel, animated: animated)
@@ -21,7 +21,7 @@ extension ApplicationStatusPresentable {
2121
with viewModel: ApplicationStatusAlertEvent?,
2222
animated: Bool
2323
) {
24-
guard let window = UIApplication.shared.keyWindow as? ApplicationStatusPresentable else {
24+
guard let window = SceneWindowFinder.statusPresentableWindow() else {
2525
return
2626
}
2727
window.dismissStatus(with: viewModel, animated: animated)

0 commit comments

Comments
 (0)