diff --git a/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationSecretSectionView.swift b/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationSecretSectionView.swift index 56b20efcb..7827063b3 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationSecretSectionView.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationSecretSectionView.swift @@ -61,7 +61,7 @@ struct ServiceConfigurationSecretSectionView: View { } .alert(viewModel.alertMessage, isPresented: $viewModel.isAlertPresented, actions: { Button("ok") { - viewModel.isAlertPresented = false + viewModel.reset() } }) } @@ -70,12 +70,11 @@ struct ServiceConfigurationSecretSectionView: View { viewModel.isValidating.toggle() service.validate { _, error in DispatchQueue.main.async { - service.result.isFinished = true - guard !viewModel.isAlertPresented else { return } + guard viewModel.isValidating else { return } + viewModel.isValidating = false 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.isAlertPresented = true } } } @@ -105,6 +104,12 @@ private class ServiceValidationViewModel: ObservableObject { } ) } + + func reset() { + isValidating = false + alertMessage = "" + isAlertPresented = false + } } @available(macOS 13.0, *)