From c71bf3ba2383f3edab19ff3382cdd799af84b59c Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 9 May 2022 15:55:35 -0400 Subject: [PATCH] Fix displaying toasts from non-main queue --- Tusker/Screens/Utilities/Previewing.swift | 20 ++++++++++++++----- .../Views/Toast/ToastableViewController.swift | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Tusker/Screens/Utilities/Previewing.swift b/Tusker/Screens/Utilities/Previewing.swift index 1f9f3d4c..5e74bbe9 100644 --- a/Tusker/Screens/Utilities/Previewing.swift +++ b/Tusker/Screens/Utilities/Previewing.swift @@ -146,7 +146,9 @@ extension MenuActionProvider { case .failure(let error): if let toastable = self.toastableViewController { let config = ToastConfiguration(from: error, with: "Error \(bookmarked ? "Unb" : "B")ookmarking", in: toastable, retryAction: nil) - toastable.showToast(configuration: config, animated: true) + DispatchQueue.main.async { + toastable.showToast(configuration: config, animated: true) + } } } } @@ -174,7 +176,9 @@ extension MenuActionProvider { case .failure(let error): if let toastable = self.toastableViewController { let config = ToastConfiguration(from: error, with: "Error \(muted ? "Unm" : "M")uting", in: toastable, retryAction: nil) - toastable.showToast(configuration: config, animated: true) + DispatchQueue.main.async { + toastable.showToast(configuration: config, animated: true) + } } } } @@ -196,7 +200,9 @@ extension MenuActionProvider { case .failure(let error): if let toastable = self.toastableViewController { let config = ToastConfiguration(from: error, with: "Error \(pinned ? "Unp" :"P")inning", in: toastable, retryAction: nil) - toastable.showToast(configuration: config, animated: true) + DispatchQueue.main.async { + toastable.showToast(configuration: config, animated: true) + } } } }) @@ -219,7 +225,9 @@ extension MenuActionProvider { case .failure(let error): if let toastable = self?.toastableViewController { let config = ToastConfiguration(from: error, with: "Error Refreshing Poll", in: toastable, retryAction: nil) - toastable.showToast(configuration: config, animated: true) + DispatchQueue.main.async { + toastable.showToast(configuration: config, animated: true) + } } } }) @@ -313,7 +321,9 @@ extension MenuActionProvider { case .failure(let error): if let toastable = self.toastableViewController { let config = ToastConfiguration(from: error, with: "Error \(following ? "Unf" : "F")ollowing", in: toastable, retryAction: nil) - toastable.showToast(configuration: config, animated: true) + DispatchQueue.main.async { + toastable.showToast(configuration: config, animated: true) + } } case .success(let relationship, _): mastodonController.persistentContainer.addOrUpdate(relationship: relationship) diff --git a/Tusker/Views/Toast/ToastableViewController.swift b/Tusker/Views/Toast/ToastableViewController.swift index e7d900f5..2c535d59 100644 --- a/Tusker/Views/Toast/ToastableViewController.swift +++ b/Tusker/Views/Toast/ToastableViewController.swift @@ -8,6 +8,7 @@ import UIKit +@MainActor protocol ToastableViewController: UIViewController { var toastParentView: UIView { get }