Use MainActor Task instead of GCD.

This commit is contained in:
Brent Simmons
2023-07-09 22:54:55 -07:00
parent 1fa9fa5e10
commit 1be7e680d0
5 changed files with 19 additions and 20 deletions

View File

@@ -223,7 +223,7 @@ var appDelegate: AppDelegate!
NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
DispatchQueue.main.async {
Task { @MainActor in
self.unreadCount = AccountManager.shared.unreadCount
}
@@ -241,7 +241,7 @@ var appDelegate: AppDelegate!
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
if settings.authorizationStatus == .authorized {
DispatchQueue.main.async {
Task { @MainActor in
NSApplication.shared.registerForRemoteNotifications()
}
}
@@ -258,9 +258,9 @@ var appDelegate: AppDelegate!
refreshTimer!.update()
syncTimer!.update()
} else {
DispatchQueue.main.async {
self.refreshTimer!.timedRefresh(nil)
self.syncTimer!.timedRefresh(nil)
Task { @MainActor in
refreshTimer!.timedRefresh(nil)
syncTimer!.timedRefresh(nil)
}
}
#endif
@@ -279,7 +279,7 @@ var appDelegate: AppDelegate!
}
#if !MAC_APP_STORE
DispatchQueue.main.async {
Task { @MainActor in
CrashReporter.check(crashReporter: self.crashReporter)
}
#endif
@@ -371,13 +371,13 @@ var appDelegate: AppDelegate!
informativeText = error.localizedDescription
}
DispatchQueue.main.async {
Task { @MainActor in
let alert = NSAlert()
alert.alertStyle = .warning
alert.messageText = NSLocalizedString("alert.title.theme-error", comment: "Theme error")
alert.informativeText = informativeText
alert.addButton(withTitle: NSLocalizedString("button.title.ok", comment: "OK"))
alert.buttons[0].keyEquivalent = "\r"
_ = alert.runModal()
@@ -429,7 +429,7 @@ var appDelegate: AppDelegate!
let url = userInfo["url"] as? URL else {
return
}
DispatchQueue.main.async {
Task { @MainActor in
self.importTheme(filename: url.path)
}
}
@@ -960,7 +960,7 @@ extension AppDelegate {
assert(shouldShowTwitterDeprecationAlert())
AppDefaults.shared.twitterDeprecationAlertShown = true
DispatchQueue.main.async {
Task { @MainActor in
let alert = NSAlert()
alert.alertStyle = .warning
alert.messageText = NSLocalizedString("Twitter Integration Removed", comment: "Twitter Integration Removed")
@@ -987,7 +987,7 @@ extension AppDelegate {
assert(shouldShowRedditDeprecationAlert())
AppDefaults.shared.redditDeprecationAlertShown = true
DispatchQueue.main.async {
Task { @MainActor in
let alert = NSAlert()
alert.alertStyle = .warning
alert.messageText = NSLocalizedString("Reddit API Integration Removed", comment: "Reddit API Integration Removed")

View File

@@ -66,11 +66,11 @@ import RSParser
}
account.createFeed(url: url.absoluteString, name: title, container: container, validateFeed: true) { result in
DispatchQueue.main.async {
Task { @MainActor in
self.endShowingProgress()
}
switch result {
case .success(let feed):
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
@@ -81,7 +81,7 @@ import RSParser
case AccountError.createErrorNotFound:
self.showNoFeedsErrorMessage()
default:
DispatchQueue.main.async {
Task { @MainActor in
NSApplication.shared.presentError(error)
}
}

View File

@@ -106,11 +106,10 @@ enum TimelineSourceMode {
NotificationCenter.default.addObserver(self, selector: #selector(articleThemeNamesDidChangeNotification(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(currentArticleThemeDidChangeNotification(_:)), name: .CurrentArticleThemeDidChangeNotification, object: nil)
DispatchQueue.main.async {
Task { @MainActor in
self.updateWindowTitle()
}
}
// MARK: - API

View File

@@ -88,7 +88,7 @@ import Account
panel.beginSheetModal(for: hostWindow!) { result in
if result == NSApplication.ModalResponse.OK, let url = panel.url {
DispatchQueue.main.async {
Task { @MainActor in
let filename = url.lastPathComponent
let opmlString = OPMLExporter.OPMLString(with: account, title: filename)
do {

View File

@@ -320,7 +320,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
if let selectedIndex = articles.firstIndex(where: { $0.articleID == articleID }) {
tableView.selectRow(selectedIndex)
DispatchQueue.main.async {
Task { @MainActor in
self.tableView.scrollTo(row: selectedIndex)
}
focus()