Fix race condition between getting and checking notification settings
This commit is contained in:
parent
88ac27ef50
commit
a0fea768bf
@ -60,22 +60,31 @@ final class WebFeedInspectorViewController: NSViewController, Inspector {
|
|||||||
isNotifyAboutNewArticlesCheckBox.setNextState()
|
isNotifyAboutNewArticlesCheckBox.setNextState()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if settings.authorizationStatus == .denied {
|
|
||||||
isNotifyAboutNewArticlesCheckBox.setNextState()
|
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
|
||||||
showNotificationsDeniedError()
|
self.updateNotificationSettings()
|
||||||
} else if settings.authorizationStatus == .authorized {
|
|
||||||
feed?.isNotifyAboutNewArticles = (isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
|
if settings.authorizationStatus == .denied {
|
||||||
} else {
|
DispatchQueue.main.async {
|
||||||
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in
|
self.isNotifyAboutNewArticlesCheckBox.setNextState()
|
||||||
self.updateNotificationSettings()
|
self.showNotificationsDeniedError()
|
||||||
if granted {
|
}
|
||||||
DispatchQueue.main.async {
|
} else if settings.authorizationStatus == .authorized {
|
||||||
self.feed?.isNotifyAboutNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
|
DispatchQueue.main.async {
|
||||||
NSApplication.shared.registerForRemoteNotifications()
|
self.feed?.isNotifyAboutNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DispatchQueue.main.async {
|
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in
|
||||||
self.isNotifyAboutNewArticlesCheckBox.setNextState()
|
self.updateNotificationSettings()
|
||||||
|
if granted {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.feed?.isNotifyAboutNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
|
||||||
|
NSApplication.shared.registerForRemoteNotifications()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isNotifyAboutNewArticlesCheckBox.setNextState()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user