Fix race condition between getting and checking notification settings

This commit is contained in:
Angelo Stavrow 2020-08-02 08:47:14 -04:00
parent 88ac27ef50
commit a0fea768bf
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -60,11 +60,19 @@ final class WebFeedInspectorViewController: NSViewController, Inspector {
isNotifyAboutNewArticlesCheckBox.setNextState()
return
}
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
self.updateNotificationSettings()
if settings.authorizationStatus == .denied {
isNotifyAboutNewArticlesCheckBox.setNextState()
showNotificationsDeniedError()
DispatchQueue.main.async {
self.isNotifyAboutNewArticlesCheckBox.setNextState()
self.showNotificationsDeniedError()
}
} else if settings.authorizationStatus == .authorized {
feed?.isNotifyAboutNewArticles = (isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
DispatchQueue.main.async {
self.feed?.isNotifyAboutNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
}
} else {
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in
self.updateNotificationSettings()
@ -81,6 +89,7 @@ final class WebFeedInspectorViewController: NSViewController, Inspector {
}
}
}
}
@IBAction func isReaderViewAlwaysOnChanged(_ sender: Any) {
feed?.isArticleExtractorAlwaysOn = (isReaderViewAlwaysOnCheckBox?.state ?? .off) == .on ? true : false