Skip to content

Commit

Permalink
Add deprecation alert for notification categories (#1976)
Browse files Browse the repository at this point in the history
## Summary
Alerts if there are any notification categories (local or synced) if the user is an admin on any of their servers.

The configuration is marked as deprecated in home-assistant/core#61078 and will produce warnings until it's removed from there as well.
  • Loading branch information
zacwest authored Dec 7, 2021
1 parent b465c94 commit e788cfe
Showing 3 changed files with 57 additions and 1 deletion.
43 changes: 43 additions & 0 deletions Sources/App/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -433,6 +433,49 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}.catch { error in
Current.Log.error("check error: \(error)")
}

showNotificationCategoryAlertIfNeeded()
}

private func showNotificationCategoryAlertIfNeeded() {
guard Current.realm().objects(NotificationCategory.self).isEmpty == false else {
return
}

let userDefaults = UserDefaults.standard
let seenKey = "category-deprecation-2-" + Current.clientVersion().description

guard !userDefaults.bool(forKey: seenKey) else {
return
}

when(fulfilled: Current.apis.map { $0.connection.caches.user.once().promise }).done { [sceneManager] users in
guard users.contains(where: \.isAdmin) else {
Current.Log.info("not showing because not an admin anywhere")
return
}

let alert = UIAlertController(
title: L10n.Alerts.Deprecations.NotificationCategory.title,
message: L10n.Alerts.Deprecations.NotificationCategory.message("iOS-2021.2"),
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: L10n.Nfc.List.learnMore, style: .default, handler: { _ in
userDefaults.set(true, forKey: seenKey)
openURLInBrowser(
URL(string: "https://companion.home-assistant.io/app/ios/actionable-notifications")!,
nil
)
}))
alert.addAction(UIAlertAction(title: L10n.okLabel, style: .cancel, handler: { _ in
userDefaults.set(true, forKey: seenKey)
}))
sceneManager.webViewWindowControllerPromise.done {
$0.present(alert)
}
}.catch { error in
Current.Log.error("couldn't check for if user: \(error)")
}
}

func setupWatchCommunicator() {
5 changes: 4 additions & 1 deletion Sources/App/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -33,6 +33,9 @@
"alerts.auth_required.title" = "You must sign in to continue";
"alerts.confirm.cancel" = "Cancel";
"alerts.confirm.ok" = "OK";
/* value filled in will be like iOS-2021.2 */
"alerts.deprecations.notification_category.message" = "You must migrate to actions defined in the notification itself before %1$@.";
"alerts.deprecations.notification_category.title" = "Notification Categories are deprecated";
"alerts.open_url_from_deep_link.message" = "Open URL (%@) from deep link?";
"alerts.open_url_from_notification.message" = "Open URL (%@) found in notification?";
"alerts.open_url_from_notification.title" = "Open URL?";
@@ -742,4 +745,4 @@ Home Assistant is free and open source home automation software with a focus on
"widgets.open_page.description" = "Open a frontend page in Home Assistant.";
"widgets.open_page.not_configured" = "No Pages Available";
"widgets.open_page.title" = "Open Page";
"yes_label" = "Yes";
"yes_label" = "Yes";
10 changes: 10 additions & 0 deletions Sources/Shared/Resources/Swiftgen/Strings.swift
Original file line number Diff line number Diff line change
@@ -180,6 +180,16 @@ public enum L10n {
/// OK
public static var ok: String { return L10n.tr("Localizable", "alerts.confirm.ok") }
}
public enum Deprecations {
public enum NotificationCategory {
/// You must migrate to actions defined in the notification itself before %1$@.
public static func message(_ p1: Any) -> String {
return L10n.tr("Localizable", "alerts.deprecations.notification_category.message", String(describing: p1))
}
/// Notification Categories are deprecated
public static var title: String { return L10n.tr("Localizable", "alerts.deprecations.notification_category.title") }
}
}
public enum OpenUrlFromDeepLink {
/// Open URL (%@) from deep link?
public static func message(_ p1: Any) -> String {

0 comments on commit e788cfe

Please sign in to comment.