From ae2c8feb0309320ce7523eefb77df71cd55029bb Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Tue, 12 Mar 2024 21:43:26 +0800 Subject: [PATCH] Fix slow operations are prohibited on EDT Fix: #5251 --- .../plugin/translate/diagnostic/ReportCredentials.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/diagnostic/ReportCredentials.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/diagnostic/ReportCredentials.kt index d74c9921e..cddaaaeb5 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/diagnostic/ReportCredentials.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/diagnostic/ReportCredentials.kt @@ -6,6 +6,7 @@ import com.intellij.credentialStore.generateServiceName import com.intellij.ide.passwordSafe.PasswordSafe import com.intellij.openapi.components.Service import com.intellij.openapi.components.service +import org.jetbrains.concurrency.runAsync import java.util.* @Service @@ -41,15 +42,17 @@ internal class ReportCredentials private constructor() { get() = PasswordSafe.instance.get(CredentialAttributes(SERVICE_NAME)) ?: anonymousCredentials fun clear() { - PasswordSafe.instance.set(CredentialAttributes(SERVICE_NAME), null) + runAsync { PasswordSafe.instance.set(CredentialAttributes(SERVICE_NAME), null) } lastUserName = "" } fun save(userName: String, token: String) { check(userName.isNotBlank()) { "User name must not be blank" } - val credentials = Credentials(userName, token) - val attributes = CredentialAttributes(SERVICE_NAME, userName) - PasswordSafe.instance.set(attributes, credentials) + runAsync { + val credentials = Credentials(userName, token) + val attributes = CredentialAttributes(SERVICE_NAME, userName) + PasswordSafe.instance.set(attributes, credentials) + } lastUserName = userName }