From 4689c8e78fc9e59c0cf1d6cac516e5d13dba5e0e Mon Sep 17 00:00:00 2001 From: Chase Carroll Date: Mon, 5 Dec 2022 16:01:41 -0500 Subject: [PATCH] Use modern APIs for accessing key window Shouldn't be relying on deprecated API. Tsk. Tsk. --- Mastodon/Extension/UIApplication.swift | 8 ++++++++ .../HomeTimelineViewController+DebugAction.swift | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Mastodon/Extension/UIApplication.swift b/Mastodon/Extension/UIApplication.swift index 38080fdab..74019b0ae 100644 --- a/Mastodon/Extension/UIApplication.swift +++ b/Mastodon/Extension/UIApplication.swift @@ -22,5 +22,13 @@ extension UIApplication { return version == build ? "v\(version)" : "v\(version) (\(build))" } + + func getKeyWindow() -> UIWindow? { + return UIApplication + .shared + .connectedScenes + .flatMap { ($0 as? UIWindowScene)?.windows ?? [] } + .first { $0.isKeyWindow } + } } diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift index 6bded8c37..8ad798165 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift @@ -122,8 +122,8 @@ extension HomeTimelineViewController { identifier: nil, options: [], children: [ - UIAction(title: "Toggle Visible Touches", image: UIImage(systemName: "hand.tap"), attributes: []) { [weak self] action in - guard let window = UIApplication.shared.keyWindow as? TouchesVisibleWindow else { return } + UIAction(title: "Toggle Visible Touches", image: UIImage(systemName: "hand.tap"), attributes: []) { _ in + guard let window = UIApplication.shared.getKeyWindow() as? TouchesVisibleWindow else { return } window.touchesVisible = !window.touchesVisible }, UIAction(title: "Toggle EmptyView", image: UIImage(systemName: "clear"), attributes: []) { [weak self] action in