Skip to content

Commit d5fe2ee

Browse files
mat1thbgoncal
andauthored
Remove some depricated code pointed in #2655; (#2808)
## 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 <[email protected]>
1 parent 9bbfbaa commit d5fe2ee

File tree

7 files changed

+25
-96
lines changed

7 files changed

+25
-96
lines changed

Sources/App/AppDelegate.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ extension AppEnvironment {
3737

3838
@main
3939
class AppDelegate: UIResponder, UIApplicationDelegate {
40-
@available(iOS, deprecated: 13.0)
41-
var window: UIWindow? {
42-
get {
43-
sceneManager.compatibility.windowController?.window
44-
}
45-
set { // swiftlint:disable:this unused_setter_value
46-
fatalError("window is not settable in app delegate")
47-
}
48-
}
49-
5040
let sceneManager = SceneManager()
5141
private let lifecycleManager = LifecycleManager()
5242
let notificationManager = NotificationManager()
@@ -109,7 +99,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
10999
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
110100

111101
setupWatchCommunicator()
112-
setupiOS12Features()
113102

114103
return true
115104
}
@@ -438,19 +427,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
438427
_ = Communicator.shared
439428
}
440429

441-
private func setupiOS12Features() {
442-
// Tell the system we have a app notification settings screen and want critical alerts
443-
// This is effectively a migration
444-
445-
UNUserNotificationCenter.current().getNotificationSettings { settings in
446-
guard settings.authorizationStatus == .authorized else { return }
447-
448-
UNUserNotificationCenter.current().requestAuthorization(options: .defaultOptions) { granted, error in
449-
Current.Log.verbose("Requested critical alert access \(granted), \(String(describing: error))")
450-
}
451-
}
452-
}
453-
454430
func setupLocalization() {
455431
Current.localized.add(stringProvider: { request in
456432
if prefs.bool(forKey: "showTranslationKeys") {

Sources/App/Notifications/NotificationManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ extension NotificationManager: UNUserNotificationCenterDelegate {
293293
return
294294
}
295295

296-
var methods: UNNotificationPresentationOptions = [.alert, .badge, .sound]
296+
var methods: UNNotificationPresentationOptions = [.badge, .sound, .list, .banner]
297297
if let presentationOptions = notification.request.content.userInfo["presentation_options"] as? [String] {
298298
methods = []
299299
if presentationOptions.contains("sound") || notification.request.content.sound != nil {
@@ -302,8 +302,11 @@ extension NotificationManager: UNUserNotificationCenterDelegate {
302302
if presentationOptions.contains("badge") {
303303
methods.insert(.badge)
304304
}
305-
if presentationOptions.contains("alert") {
306-
methods.insert(.alert)
305+
if presentationOptions.contains("list") {
306+
methods.insert(.list)
307+
}
308+
if presentationOptions.contains("banner") {
309+
methods.insert(.banner)
307310
}
308311
}
309312
return completionHandler(methods)

Sources/App/Scenes/SceneManager.swift

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,7 @@ extension UIWindowSceneDelegate {
1919
}
2020
}
2121

22-
@available(iOS, deprecated: 13.0)
23-
struct SceneManagerPreSceneCompatibility {
24-
var windowController: WebViewWindowController?
25-
var urlHandler: IncomingURLHandler?
26-
let windowControllerPromise: Guarantee<WebViewWindowController>
27-
let windowControllerSeal: (WebViewWindowController) -> Void
28-
29-
init() {
30-
(self.windowControllerPromise, self.windowControllerSeal) = Guarantee<WebViewWindowController>.pending()
31-
}
32-
33-
mutating func willFinishLaunching() {
34-
let window = UIWindow(haForiOS12: ())
35-
let windowController = WebViewWindowController(window: window, restorationActivity: nil)
36-
self.windowController = windowController
37-
urlHandler = IncomingURLHandler(windowController: windowController)
38-
windowControllerSeal(windowController)
39-
}
40-
41-
mutating func didFinishLaunching() {
42-
windowController?.setup()
43-
}
44-
}
45-
46-
class SceneManager {
22+
final class SceneManager {
4723
// types too hard here
4824
fileprivate static let activityUserInfoKeyResolver = "resolver"
4925

@@ -64,9 +40,6 @@ class SceneManager {
6440

6541
private var pendingResolvers: [String: PendingResolver] = [:]
6642

67-
@available(iOS, deprecated: 13.0)
68-
var compatibility = SceneManagerPreSceneCompatibility()
69-
7043
var webViewWindowControllerPromise: Guarantee<WebViewWindowController> {
7144
firstly { () -> Guarantee<WebViewSceneDelegate> in
7245
scene(for: .init(activity: .webView))

Sources/App/WebView/IncomingURLHandler.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ class IncomingURLHandler {
5959
return false
6060
}
6161

62-
if let presenting = windowController.presentedViewController,
63-
presenting is SFSafariViewController {
62+
if
63+
let presenting = windowController.presentedViewController,
64+
presenting is SFSafariViewController {
6465
// Dismiss my.* controller if it's on top - we don't get any other indication
6566
presenting.dismiss(animated: true, completion: { [windowController] in
6667
windowController?.openSelectingServer(
@@ -105,7 +106,7 @@ class IncomingURLHandler {
105106
autoStartRecording: autoStartRecording
106107
)
107108
case let .rejected(error):
108-
Current.Log.error("Failed to obtain webview to open Assist In App")
109+
Current.Log.error("Failed to obtain webview to open Assist In App: \(error.localizedDescription)")
109110
}
110111
}
111112

@@ -137,8 +138,9 @@ class IncomingURLHandler {
137138
if let url = userActivity.webpageURL, url.host?.lowercased() == "my.home-assistant.io" {
138139
return showMy(for: url)
139140
} else if let interaction = userActivity.interaction {
140-
if let intent = interaction.intent as? OpenPageIntent,
141-
let panel = intent.page, let path = panel.identifier {
141+
if
142+
let intent = interaction.intent as? OpenPageIntent,
143+
let panel = intent.page, let path = panel.identifier {
142144
Current.Log.info("launching from shortcuts with panel \(panel)")
143145

144146
let urlString = "/" + path
@@ -177,8 +179,9 @@ class IncomingURLHandler {
177179
})
178180
}.asVoid()
179181
} else {
180-
if let action = Current.realm().object(ofType: Action.self, forPrimaryKey: shortcutItem.type),
181-
let server = Current.servers.server(for: action) {
182+
if
183+
let action = Current.realm().object(ofType: Action.self, forPrimaryKey: shortcutItem.type),
184+
let server = Current.servers.server(for: action) {
182185
Current.sceneManager.showFullScreenConfirm(
183186
icon: MaterialDesignIcons(named: action.IconName),
184187
text: action.Text,
@@ -517,8 +520,9 @@ extension IncomingURLHandler {
517520
}
518521

519522
let source: HomeAssistantAPI.ActionSource = {
520-
if let sourceString = serviceData["source"],
521-
let source = HomeAssistantAPI.ActionSource(rawValue: sourceString) {
523+
if
524+
let sourceString = serviceData["source"],
525+
let source = HomeAssistantAPI.ActionSource(rawValue: sourceString) {
522526
return source
523527
} else {
524528
return .URLHandler
@@ -527,8 +531,9 @@ extension IncomingURLHandler {
527531

528532
let actionID = url.pathComponents[1]
529533

530-
guard let action = Current.realm().object(ofType: Action.self, forPrimaryKey: actionID),
531-
let server = Current.servers.server(for: action) else {
534+
guard
535+
let action = Current.realm().object(ofType: Action.self, forPrimaryKey: actionID),
536+
let server = Current.servers.server(for: action) else {
532537
Current.sceneManager.showFullScreenConfirm(
533538
icon: .alertCircleIcon,
534539
text: L10n.UrlHandler.Error.actionNotFound,

Sources/App/WebView/UIWindow+Additions.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,4 @@ extension UIWindow {
88
self.tintColor = Constants.tintColor
99
makeKeyAndVisible()
1010
}
11-
12-
@available(iOS, deprecated: 13.0)
13-
convenience init(haForiOS12: ()) {
14-
self.init(frame: UIScreen.main.bounds)
15-
self.tintColor = Constants.tintColor
16-
self.restorationIdentifier = StateRestorationKey.mainWindow.rawValue
17-
makeKeyAndVisible()
18-
}
1911
}

Sources/App/WebView/WebViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ final class WebViewController: UIViewController, WKNavigationDelegate, WKUIDeleg
496496
return .actionSheet
497497
case .mac:
498498
return .alert
499-
case .pad, .unspecified:
499+
case .pad, .unspecified, .vision:
500500
// without a touch to tell us where, an action sheet in the middle of the screen isn't great
501501
return .alert
502502
@unknown default:

Sources/App/WebView/WebViewWindowController.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ import PromiseKit
44
import Shared
55
import UIKit
66

7-
@available(iOS, deprecated: 13.0)
8-
enum StateRestorationKey: String {
9-
case mainWindow
10-
case webViewNavigationController
11-
}
12-
13-
class WebViewWindowController {
7+
final class WebViewWindowController {
148
let window: UIWindow
159
var restorationActivity: NSUserActivity?
1610

@@ -123,20 +117,6 @@ class WebViewWindowController {
123117
return currentController
124118
}
125119

126-
@available(iOS, deprecated: 13.0)
127-
func viewController(
128-
withRestorationIdentifierPath identifierComponents: [String]
129-
) -> UIViewController? {
130-
// iOS 12 and below state restoration code path only
131-
if identifierComponents == [StateRestorationKey.webViewNavigationController.rawValue] {
132-
let navigationController = webViewNavigationController()
133-
window.rootViewController = navigationController
134-
return navigationController
135-
} else {
136-
return nil
137-
}
138-
}
139-
140120
func navigate(to url: URL, on server: Server) {
141121
open(server: server).done { webViewController in
142122
webViewController.open(inline: url)

0 commit comments

Comments
 (0)