From 42cfe2380a4324a3b948003783ab9013e60a37e1 Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Sat, 1 Aug 2020 13:02:24 -0400 Subject: [PATCH] Present an alert to the user if notifications are denied in System Prefs --- .../WebFeedInspectorViewController.swift | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Mac/Inspector/WebFeedInspectorViewController.swift b/Mac/Inspector/WebFeedInspectorViewController.swift index 92f7ab7e5..04dccc4b4 100644 --- a/Mac/Inspector/WebFeedInspectorViewController.swift +++ b/Mac/Inspector/WebFeedInspectorViewController.swift @@ -66,8 +66,8 @@ final class WebFeedInspectorViewController: NSViewController, Inspector { // Notifications are not authorized, so toggle the checkbox back // to its original state... isNotifyAboutNewArticlesCheckBox.setNextState() - // ...and then alert the user to the issue - // TODO: present alert to user + // ...then alert the user to the issue... + showNotificationsDeniedError() } else if settings.authorizationStatus == .authorized { // Notifications are authorized, so set the feed's isNotifyAboutNewArticles // property to match the state of isNotifyAboutNewArticlesCheckbox. @@ -184,6 +184,19 @@ private extension WebFeedInspectorViewController { } } + func showNotificationsDeniedError() { + let updateAlert = NSAlert() + updateAlert.alertStyle = .informational + updateAlert.messageText = NSLocalizedString("Enable Notifications", comment: "Notifications") + updateAlert.informativeText = NSLocalizedString("Notifications need to be enabled in System Preferences > Notifications.", comment: "Notifications need to be enabled in System Preferences > Notifications.") + updateAlert.addButton(withTitle: NSLocalizedString("Open System Preferences", comment: "Open System Preferences")) + updateAlert.addButton(withTitle: NSLocalizedString("Close", comment: "Close")) + let modalResponse = updateAlert.runModal() + if modalResponse == .alertFirstButtonReturn { + NSWorkspace.shared.open(URL(fileURLWithPath: "x-apple.systempreferences:com.apple.preference")) + } + } + func updateNotifyAboutNewArticles() { isNotifyAboutNewArticlesCheckBox?.state = (feed?.isNotifyAboutNewArticles ?? false) ? .on : .off }