diff --git a/Easydict/Feature/Service/Gemini/GeminiService.swift b/Easydict/Feature/Service/Gemini/GeminiService.swift index 706732b17..43331a553 100644 --- a/Easydict/Feature/Service/Gemini/GeminiService.swift +++ b/Easydict/Feature/Service/Gemini/GeminiService.swift @@ -108,7 +108,9 @@ public final class GeminiService: QueryService { resultString += line result.translatedResults = [resultString] - completion(result, nil) + await MainActor.run { + completion(result, nil) + } } } else { @@ -118,7 +120,9 @@ public final class GeminiService: QueryService { } result.translatedResults = [resultString] - completion(result, nil) + await MainActor.run { + completion(result, nil) + } } } catch { /** @@ -132,8 +136,9 @@ public final class GeminiService: QueryService { let errorString = String(describing: error) let errorMessage = errorString.extract(withPattern: "message: \"([^\"]*)\"") ?? errorString ezError?.errorDataMessage = errorMessage - - completion(result, ezError) + await MainActor.run { + completion(result, ezError) + } } } } diff --git a/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationSecretSectionView.swift b/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationSecretSectionView.swift index fb32250e6..29760170c 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationSecretSectionView.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationSecretSectionView.swift @@ -68,12 +68,10 @@ struct ServiceConfigurationSecretSectionView: View { func validate() { viewModel.isValidating.toggle() service.validate { _, error in - DispatchQueue.main.async { - viewModel.alertMessage = error == nil ? "service.configuration.validation_success" : "service.configuration.validation_fail" - print("\(service.serviceType()) validate \(error == nil ? "success" : "fail")!") - viewModel.isValidating.toggle() - viewModel.isAlertPresented.toggle() - } + viewModel.alertMessage = error == nil ? "service.configuration.validation_success" : "service.configuration.validation_fail" + print("\(service.serviceType()) validate \(error == nil ? "success" : "fail")!") + viewModel.isValidating.toggle() + viewModel.isAlertPresented.toggle() } } }