Remove comments, and move post-request actions to the main queue

This commit is contained in:
Angelo Stavrow 2020-08-01 13:09:33 -04:00
parent 42cfe2380a
commit 619ddc6ea2
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -57,40 +57,30 @@ final class WebFeedInspectorViewController: NSViewController, Inspector {
// MARK: Actions // MARK: Actions
@IBAction func isNotifyAboutNewArticlesChanged(_ sender: Any) { @IBAction func isNotifyAboutNewArticlesChanged(_ sender: Any) {
guard let settings = userNotificationSettings else { guard let settings = userNotificationSettings else {
// Something went wront fetching the user notification settings,
// so toggle the checkbox back to its original state and return.
isNotifyAboutNewArticlesCheckBox.setNextState() isNotifyAboutNewArticlesCheckBox.setNextState()
return return
} }
if settings.authorizationStatus == .denied { if settings.authorizationStatus == .denied {
// Notifications are not authorized, so toggle the checkbox back
// to its original state...
isNotifyAboutNewArticlesCheckBox.setNextState() isNotifyAboutNewArticlesCheckBox.setNextState()
// ...then alert the user to the issue...
showNotificationsDeniedError() showNotificationsDeniedError()
} else if settings.authorizationStatus == .authorized { } else if settings.authorizationStatus == .authorized {
// Notifications are authorized, so set the feed's isNotifyAboutNewArticles
// property to match the state of isNotifyAboutNewArticlesCheckbox.
feed?.isNotifyAboutNewArticles = (isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false feed?.isNotifyAboutNewArticles = (isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
} else { } else {
// We're not sure what the status may be but we've /probably/ not requested
// permission to send notifications, so do that:
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in
self.updateNotificationSettings() self.updateNotificationSettings()
if granted { if granted {
// We've been given permission, so set the feed's isNotifyAboutNewArticles DispatchQueue.main.async {
// property to match the state of isNotifyAboutNewArticlesCheckbox and then
// register for remote notifications.
self.feed?.isNotifyAboutNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false self.feed?.isNotifyAboutNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
NSApplication.shared.registerForRemoteNotifications() NSApplication.shared.registerForRemoteNotifications()
}
} else { } else {
// We weren't given permission, so toggle the checkbox back to its DispatchQueue.main.async {
// original state.
self.isNotifyAboutNewArticlesCheckBox.setNextState() self.isNotifyAboutNewArticlesCheckBox.setNextState()
} }
} }
} }
} }
}
@IBAction func isReaderViewAlwaysOnChanged(_ sender: Any) { @IBAction func isReaderViewAlwaysOnChanged(_ sender: Any) {
feed?.isArticleExtractorAlwaysOn = (isReaderViewAlwaysOnCheckBox?.state ?? .off) == .on ? true : false feed?.isArticleExtractorAlwaysOn = (isReaderViewAlwaysOnCheckBox?.state ?? .off) == .on ? true : false