Fix displaying toasts from non-main queue

This commit is contained in:
Shadowfacts 2022-05-09 15:55:35 -04:00
parent 3e5c441b24
commit c71bf3ba23
2 changed files with 16 additions and 5 deletions

View File

@ -146,10 +146,12 @@ extension MenuActionProvider {
case .failure(let error): case .failure(let error):
if let toastable = self.toastableViewController { if let toastable = self.toastableViewController {
let config = ToastConfiguration(from: error, with: "Error \(bookmarked ? "Unb" : "B")ookmarking", in: toastable, retryAction: nil) let config = ToastConfiguration(from: error, with: "Error \(bookmarked ? "Unb" : "B")ookmarking", in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true) toastable.showToast(configuration: config, animated: true)
} }
} }
} }
}
}), }),
] ]
@ -174,10 +176,12 @@ extension MenuActionProvider {
case .failure(let error): case .failure(let error):
if let toastable = self.toastableViewController { if let toastable = self.toastableViewController {
let config = ToastConfiguration(from: error, with: "Error \(muted ? "Unm" : "M")uting", in: toastable, retryAction: nil) let config = ToastConfiguration(from: error, with: "Error \(muted ? "Unm" : "M")uting", in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true) toastable.showToast(configuration: config, animated: true)
} }
} }
} }
}
})) }))
} }
@ -196,9 +200,11 @@ extension MenuActionProvider {
case .failure(let error): case .failure(let error):
if let toastable = self.toastableViewController { if let toastable = self.toastableViewController {
let config = ToastConfiguration(from: error, with: "Error \(pinned ? "Unp" :"P")inning", in: toastable, retryAction: nil) let config = ToastConfiguration(from: error, with: "Error \(pinned ? "Unp" :"P")inning", in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true) toastable.showToast(configuration: config, animated: true)
} }
} }
}
}) })
})) }))
} }
@ -219,9 +225,11 @@ extension MenuActionProvider {
case .failure(let error): case .failure(let error):
if let toastable = self?.toastableViewController { if let toastable = self?.toastableViewController {
let config = ToastConfiguration(from: error, with: "Error Refreshing Poll", in: toastable, retryAction: nil) let config = ToastConfiguration(from: error, with: "Error Refreshing Poll", in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true) toastable.showToast(configuration: config, animated: true)
} }
} }
}
}) })
}), at: 0) }), at: 0)
} }
@ -313,8 +321,10 @@ extension MenuActionProvider {
case .failure(let error): case .failure(let error):
if let toastable = self.toastableViewController { if let toastable = self.toastableViewController {
let config = ToastConfiguration(from: error, with: "Error \(following ? "Unf" : "F")ollowing", in: toastable, retryAction: nil) let config = ToastConfiguration(from: error, with: "Error \(following ? "Unf" : "F")ollowing", in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true) toastable.showToast(configuration: config, animated: true)
} }
}
case .success(let relationship, _): case .success(let relationship, _):
mastodonController.persistentContainer.addOrUpdate(relationship: relationship) mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
} }

View File

@ -8,6 +8,7 @@
import UIKit import UIKit
@MainActor
protocol ToastableViewController: UIViewController { protocol ToastableViewController: UIViewController {
var toastParentView: UIView { get } var toastParentView: UIView { get }