Try to register for remote notifications when feed inspector appears

This commit is contained in:
Angelo Stavrow 2020-08-01 11:52:33 -04:00
parent 927db2c375
commit 1123a0be86
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
1 changed files with 17 additions and 2 deletions

View File

@ -50,6 +50,10 @@ final class WebFeedInspectorViewController: NSViewController, Inspector {
NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .ImageDidBecomeAvailable, object: nil)
}
override func viewDidAppear() {
updateNotificationSettings()
}
// MARK: Actions
@IBAction func isNotifyAboutNewArticlesChanged(_ sender: Any) {
feed?.isNotifyAboutNewArticles = (isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
@ -136,6 +140,17 @@ private extension WebFeedInspectorViewController {
urlTextField?.stringValue = feed?.url ?? ""
}
func updateNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
DispatchQueue.main.async {
self.userNotificationSettings = settings
if settings.authorizationStatus == .authorized {
NSApplication.shared.registerForRemoteNotifications()
}
}
}
}
func updateNotifyAboutNewArticles() {
isNotifyAboutNewArticlesCheckBox?.state = (feed?.isNotifyAboutNewArticles ?? false) ? .on : .off
}