From d5fe2eee38f4ce92a67abfaaf8fef179f80837a1 Mon Sep 17 00:00:00 2001 From: mat1th Date: Mon, 10 Jun 2024 08:03:13 +0000 Subject: [PATCH] Remove some depricated code pointed in #2655; (#2808) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary In issue #2655 there is some code referenced that is not needed anymore. So I've removed it. ## Screenshots The app still launches on a iPhone simulator. Could not test the macOS target. ## Link to pull request in Documentation repository Documentation: home-assistant/companion.home-assistant# ## Any other notes - --------- Co-authored-by: Bruno Pantaleão Gonçalves --- Sources/App/AppDelegate.swift | 24 --------------- .../Notifications/NotificationManager.swift | 9 ++++-- Sources/App/Scenes/SceneManager.swift | 29 +------------------ Sources/App/WebView/IncomingURLHandler.swift | 27 ++++++++++------- Sources/App/WebView/UIWindow+Additions.swift | 8 ----- Sources/App/WebView/WebViewController.swift | 2 +- .../App/WebView/WebViewWindowController.swift | 22 +------------- 7 files changed, 25 insertions(+), 96 deletions(-) diff --git a/Sources/App/AppDelegate.swift b/Sources/App/AppDelegate.swift index b1a956c17..2d454cd3a 100644 --- a/Sources/App/AppDelegate.swift +++ b/Sources/App/AppDelegate.swift @@ -37,16 +37,6 @@ extension AppEnvironment { @main class AppDelegate: UIResponder, UIApplicationDelegate { - @available(iOS, deprecated: 13.0) - var window: UIWindow? { - get { - sceneManager.compatibility.windowController?.window - } - set { // swiftlint:disable:this unused_setter_value - fatalError("window is not settable in app delegate") - } - } - let sceneManager = SceneManager() private let lifecycleManager = LifecycleManager() let notificationManager = NotificationManager() @@ -109,7 +99,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum) setupWatchCommunicator() - setupiOS12Features() return true } @@ -438,19 +427,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { _ = Communicator.shared } - private func setupiOS12Features() { - // Tell the system we have a app notification settings screen and want critical alerts - // This is effectively a migration - - UNUserNotificationCenter.current().getNotificationSettings { settings in - guard settings.authorizationStatus == .authorized else { return } - - UNUserNotificationCenter.current().requestAuthorization(options: .defaultOptions) { granted, error in - Current.Log.verbose("Requested critical alert access \(granted), \(String(describing: error))") - } - } - } - func setupLocalization() { Current.localized.add(stringProvider: { request in if prefs.bool(forKey: "showTranslationKeys") { diff --git a/Sources/App/Notifications/NotificationManager.swift b/Sources/App/Notifications/NotificationManager.swift index 68d4fb1ce..3f93be1ec 100644 --- a/Sources/App/Notifications/NotificationManager.swift +++ b/Sources/App/Notifications/NotificationManager.swift @@ -293,7 +293,7 @@ extension NotificationManager: UNUserNotificationCenterDelegate { return } - var methods: UNNotificationPresentationOptions = [.alert, .badge, .sound] + var methods: UNNotificationPresentationOptions = [.badge, .sound, .list, .banner] if let presentationOptions = notification.request.content.userInfo["presentation_options"] as? [String] { methods = [] if presentationOptions.contains("sound") || notification.request.content.sound != nil { @@ -302,8 +302,11 @@ extension NotificationManager: UNUserNotificationCenterDelegate { if presentationOptions.contains("badge") { methods.insert(.badge) } - if presentationOptions.contains("alert") { - methods.insert(.alert) + if presentationOptions.contains("list") { + methods.insert(.list) + } + if presentationOptions.contains("banner") { + methods.insert(.banner) } } return completionHandler(methods) diff --git a/Sources/App/Scenes/SceneManager.swift b/Sources/App/Scenes/SceneManager.swift index 50c19a78b..8496a9bfe 100644 --- a/Sources/App/Scenes/SceneManager.swift +++ b/Sources/App/Scenes/SceneManager.swift @@ -19,31 +19,7 @@ extension UIWindowSceneDelegate { } } -@available(iOS, deprecated: 13.0) -struct SceneManagerPreSceneCompatibility { - var windowController: WebViewWindowController? - var urlHandler: IncomingURLHandler? - let windowControllerPromise: Guarantee - let windowControllerSeal: (WebViewWindowController) -> Void - - init() { - (self.windowControllerPromise, self.windowControllerSeal) = Guarantee.pending() - } - - mutating func willFinishLaunching() { - let window = UIWindow(haForiOS12: ()) - let windowController = WebViewWindowController(window: window, restorationActivity: nil) - self.windowController = windowController - urlHandler = IncomingURLHandler(windowController: windowController) - windowControllerSeal(windowController) - } - - mutating func didFinishLaunching() { - windowController?.setup() - } -} - -class SceneManager { +final class SceneManager { // types too hard here fileprivate static let activityUserInfoKeyResolver = "resolver" @@ -64,9 +40,6 @@ class SceneManager { private var pendingResolvers: [String: PendingResolver] = [:] - @available(iOS, deprecated: 13.0) - var compatibility = SceneManagerPreSceneCompatibility() - var webViewWindowControllerPromise: Guarantee { firstly { () -> Guarantee in scene(for: .init(activity: .webView)) diff --git a/Sources/App/WebView/IncomingURLHandler.swift b/Sources/App/WebView/IncomingURLHandler.swift index 4c13417d4..e205b5bfd 100644 --- a/Sources/App/WebView/IncomingURLHandler.swift +++ b/Sources/App/WebView/IncomingURLHandler.swift @@ -59,8 +59,9 @@ class IncomingURLHandler { return false } - if let presenting = windowController.presentedViewController, - presenting is SFSafariViewController { + if + let presenting = windowController.presentedViewController, + presenting is SFSafariViewController { // Dismiss my.* controller if it's on top - we don't get any other indication presenting.dismiss(animated: true, completion: { [windowController] in windowController?.openSelectingServer( @@ -105,7 +106,7 @@ class IncomingURLHandler { autoStartRecording: autoStartRecording ) case let .rejected(error): - Current.Log.error("Failed to obtain webview to open Assist In App") + Current.Log.error("Failed to obtain webview to open Assist In App: \(error.localizedDescription)") } } @@ -137,8 +138,9 @@ class IncomingURLHandler { if let url = userActivity.webpageURL, url.host?.lowercased() == "my.home-assistant.io" { return showMy(for: url) } else if let interaction = userActivity.interaction { - if let intent = interaction.intent as? OpenPageIntent, - let panel = intent.page, let path = panel.identifier { + if + let intent = interaction.intent as? OpenPageIntent, + let panel = intent.page, let path = panel.identifier { Current.Log.info("launching from shortcuts with panel \(panel)") let urlString = "/" + path @@ -177,8 +179,9 @@ class IncomingURLHandler { }) }.asVoid() } else { - if let action = Current.realm().object(ofType: Action.self, forPrimaryKey: shortcutItem.type), - let server = Current.servers.server(for: action) { + if + let action = Current.realm().object(ofType: Action.self, forPrimaryKey: shortcutItem.type), + let server = Current.servers.server(for: action) { Current.sceneManager.showFullScreenConfirm( icon: MaterialDesignIcons(named: action.IconName), text: action.Text, @@ -517,8 +520,9 @@ extension IncomingURLHandler { } let source: HomeAssistantAPI.ActionSource = { - if let sourceString = serviceData["source"], - let source = HomeAssistantAPI.ActionSource(rawValue: sourceString) { + if + let sourceString = serviceData["source"], + let source = HomeAssistantAPI.ActionSource(rawValue: sourceString) { return source } else { return .URLHandler @@ -527,8 +531,9 @@ extension IncomingURLHandler { let actionID = url.pathComponents[1] - guard let action = Current.realm().object(ofType: Action.self, forPrimaryKey: actionID), - let server = Current.servers.server(for: action) else { + guard + let action = Current.realm().object(ofType: Action.self, forPrimaryKey: actionID), + let server = Current.servers.server(for: action) else { Current.sceneManager.showFullScreenConfirm( icon: .alertCircleIcon, text: L10n.UrlHandler.Error.actionNotFound, diff --git a/Sources/App/WebView/UIWindow+Additions.swift b/Sources/App/WebView/UIWindow+Additions.swift index b407609dd..7df068064 100644 --- a/Sources/App/WebView/UIWindow+Additions.swift +++ b/Sources/App/WebView/UIWindow+Additions.swift @@ -8,12 +8,4 @@ extension UIWindow { self.tintColor = Constants.tintColor makeKeyAndVisible() } - - @available(iOS, deprecated: 13.0) - convenience init(haForiOS12: ()) { - self.init(frame: UIScreen.main.bounds) - self.tintColor = Constants.tintColor - self.restorationIdentifier = StateRestorationKey.mainWindow.rawValue - makeKeyAndVisible() - } } diff --git a/Sources/App/WebView/WebViewController.swift b/Sources/App/WebView/WebViewController.swift index b1d069371..1d9ea73ff 100644 --- a/Sources/App/WebView/WebViewController.swift +++ b/Sources/App/WebView/WebViewController.swift @@ -496,7 +496,7 @@ final class WebViewController: UIViewController, WKNavigationDelegate, WKUIDeleg return .actionSheet case .mac: return .alert - case .pad, .unspecified: + case .pad, .unspecified, .vision: // without a touch to tell us where, an action sheet in the middle of the screen isn't great return .alert @unknown default: diff --git a/Sources/App/WebView/WebViewWindowController.swift b/Sources/App/WebView/WebViewWindowController.swift index 50578facf..506f3c278 100644 --- a/Sources/App/WebView/WebViewWindowController.swift +++ b/Sources/App/WebView/WebViewWindowController.swift @@ -4,13 +4,7 @@ import PromiseKit import Shared import UIKit -@available(iOS, deprecated: 13.0) -enum StateRestorationKey: String { - case mainWindow - case webViewNavigationController -} - -class WebViewWindowController { +final class WebViewWindowController { let window: UIWindow var restorationActivity: NSUserActivity? @@ -123,20 +117,6 @@ class WebViewWindowController { return currentController } - @available(iOS, deprecated: 13.0) - func viewController( - withRestorationIdentifierPath identifierComponents: [String] - ) -> UIViewController? { - // iOS 12 and below state restoration code path only - if identifierComponents == [StateRestorationKey.webViewNavigationController.rawValue] { - let navigationController = webViewNavigationController() - window.rootViewController = navigationController - return navigationController - } else { - return nil - } - } - func navigate(to url: URL, on server: Server) { open(server: server).done { webViewController in webViewController.open(inline: url)