Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some depricated code pointed in #2655; #2808

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions Sources/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -109,7 +99,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)

setupWatchCommunicator()
setupiOS12Features()

return true
}
Expand Down Expand Up @@ -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") {
Expand Down
9 changes: 6 additions & 3 deletions Sources/App/Notifications/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ extension NotificationManager: UNUserNotificationCenterDelegate {
return
}

var methods: UNNotificationPresentationOptions = [.alert, .badge, .sound]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@bgoncal bgoncal Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should follow the deprecation message?
"
Deprecated
Use list and banner instead.
"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I've added them.

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 {
Expand All @@ -302,8 +302,11 @@ extension NotificationManager: UNUserNotificationCenterDelegate {
if presentationOptions.contains("badge") {
methods.insert(.badge)
}
if presentationOptions.contains("alert") {
methods.insert(.alert)
mat1th marked this conversation as resolved.
Show resolved Hide resolved
if presentationOptions.contains("list") {
methods.insert(.list)
}
if presentationOptions.contains("banner") {
methods.insert(.banner)
}
}
return completionHandler(methods)
Expand Down
29 changes: 1 addition & 28 deletions Sources/App/Scenes/SceneManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,7 @@ extension UIWindowSceneDelegate {
}
}

@available(iOS, deprecated: 13.0)
struct SceneManagerPreSceneCompatibility {
var windowController: WebViewWindowController?
var urlHandler: IncomingURLHandler?
let windowControllerPromise: Guarantee<WebViewWindowController>
let windowControllerSeal: (WebViewWindowController) -> Void

init() {
(self.windowControllerPromise, self.windowControllerSeal) = Guarantee<WebViewWindowController>.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"

Expand All @@ -64,9 +40,6 @@ class SceneManager {

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

@available(iOS, deprecated: 13.0)
var compatibility = SceneManagerPreSceneCompatibility()

var webViewWindowControllerPromise: Guarantee<WebViewWindowController> {
firstly { () -> Guarantee<WebViewSceneDelegate> in
scene(for: .init(activity: .webView))
Expand Down
27 changes: 16 additions & 11 deletions Sources/App/WebView/IncomingURLHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)")
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions Sources/App/WebView/UIWindow+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
2 changes: 1 addition & 1 deletion Sources/App/WebView/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 1 addition & 21 deletions Sources/App/WebView/WebViewWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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)
Expand Down
Loading