From 14bda67509fa16f97cf4db8fb17363c5a89536a9 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Thu, 18 Dec 2025 19:09:53 -0500 Subject: [PATCH] task isolation for notification --- fcitx5 | 2 +- iosnotifications/notify.swift | 8 +++++--- iosnotifications/toast.swift | 2 ++ src/ContentView.swift | 18 ++++++++---------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/fcitx5 b/fcitx5 index 70fe117..5db547e 160000 --- a/fcitx5 +++ b/fcitx5 @@ -1 +1 @@ -Subproject commit 70fe117d4458d2598331161e59fd4585b2df4558 +Subproject commit 5db547e2cd95fe91ed6e79a4e1de23a92a50b562 diff --git a/iosnotifications/notify.swift b/iosnotifications/notify.swift index 31bea83..bde204d 100644 --- a/iosnotifications/notify.swift +++ b/iosnotifications/notify.swift @@ -1,6 +1,8 @@ public func showTip(_ icon: String, _ body: String, _ timeout: Int32) { - guard let showToastCallback = showToastCallback else { - return + Task { @MainActor in + guard let showToastCallback = showToastCallback else { + return + } + showToastCallback(icon, body, timeout) } - showToastCallback(icon, body, timeout) } diff --git a/iosnotifications/toast.swift b/iosnotifications/toast.swift index 22c745a..d37703c 100644 --- a/iosnotifications/toast.swift +++ b/iosnotifications/toast.swift @@ -1,5 +1,7 @@ +@MainActor var showToastCallback: ((String, String, Int32) -> Void)? +@MainActor public func setShowToastCallback(_ callback: @escaping (String, String, Int32) -> Void) { showToastCallback = callback } diff --git a/src/ContentView.swift b/src/ContentView.swift index 3a1e45e..88c79f1 100644 --- a/src/ContentView.swift +++ b/src/ContentView.swift @@ -107,16 +107,14 @@ struct ContentView: View { try? "".write( to: documents.appendingPathComponent("placeholder"), atomically: true, encoding: .utf8) setShowToastCallback({ icon, message, duration in - DispatchQueue.main.async { - self.duration = Double(duration) / 1000.0 - self.message = message - self.icon = icon - if icon == "running" { - self.showLoadingToast = true - } else { - self.showLoadingToast = false - self.showToast = true - } + self.duration = Double(duration) / 1000.0 + self.message = message + self.icon = icon + if icon == "running" { + self.showLoadingToast = true + } else { + self.showLoadingToast = false + self.showToast = true } }) viewModel.refresh()