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

Add deprecation alert for notification categories #1976

Merged
merged 1 commit into from
Dec 7, 2021
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
43 changes: 43 additions & 0 deletions Sources/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion Sources/App/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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?";
Expand Down Expand Up @@ -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
Expand Up @@ -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 {
Expand Down