Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

fix(android): Continue on the intro guide's Ling key step keeps a working saved key when the field is empty

wquguru78e2dd8662b2
diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/OnboardingActivity.kt b/android/app/src/main/kotlin/com/wquguru/cicada/OnboardingActivity.kt
index 0784739..304517c 100644
--- a/android/app/src/main/kotlin/com/wquguru/cicada/OnboardingActivity.kt
+++ b/android/app/src/main/kotlin/com/wquguru/cicada/OnboardingActivity.kt
@@ -18,6 +18,7 @@ import cicada.Providers
import cicada.Strings
import cicada.Strings.L
import cicada.Strings.LF
+import cicada.keepsSavedKey
/// First run, three screens, one job each, the main button pinned at the bottom: Ling key → what
/// Cicada can hear and the permissions for it → try the sample meeting.
@@ -204,6 +205,8 @@ class OnboardingActivity : Activity() {
other.removeAllViews()
// Onboarding never blocks: a key that was checked and failed still goes on (the steps say why).
if (tried && !app.ling.aiCheck.running && (text.isEmpty() || text == app.ling.currentKey())) { checkShown = null; next(); return@submit }
+ // The guide opened again with a working key saved: an empty field keeps it.
+ if (!tried && keepsSavedKey(text, app.ling.currentKey(), app.ling.keyState)) { checkShown = null; next(); return@submit }
if (AiServiceActivity.keyHint(ui, text, "ling", status, other) { tried = true; checkKey = null; status.text = L("正在检查…") }) {
field.background = ui.rounded(Palette.card, 16, Palette.link, 2)
return@submit
diff --git a/android/cli/src/main/kotlin/cicada/cli/Tests.kt b/android/cli/src/main/kotlin/cicada/cli/Tests.kt
index ffab8e5..7c30175 100644
--- a/android/cli/src/main/kotlin/cicada/cli/Tests.kt
+++ b/android/cli/src/main/kotlin/cicada/cli/Tests.kt
@@ -62,6 +62,7 @@ object Tests {
"notesPromptIsTheMacs" to ::notesPromptIsTheMacs,
"loadsTheMacsTranslations" to ::loadsTheMacsTranslations,
"keyFileIsPrivate" to ::keyFileIsPrivate,
+ "onboardingKeepsAWorkingSavedKey" to ::onboardingKeepsAWorkingSavedKey,
"lingRequestShape" to ::lingRequestShape,
"lingDropsHijackedAndRefusedReplies" to ::lingDropsHijacked,
"lingHeardAudioRidesOutARunOf429s" to ::lingRidesOut429s,
@@ -522,6 +523,15 @@ object Tests {
equal("3 分钟", Strings.LF("%@ 分钟", 3), "LF fills %@")
}
+ fun onboardingKeepsAWorkingSavedKey() {
+ check(keepsSavedKey("", "sk-saved", KeyState.Ok), "empty field keeps a working key")
+ check(keepsSavedKey("", "sk-saved", KeyState.Unchecked), "empty field keeps a key not checked yet")
+ check(keepsSavedKey("sk-saved", "sk-saved", KeyState.Ok), "the same key again")
+ check(!keepsSavedKey("", "sk-saved", KeyState.Invalid), "an invalid key is not kept")
+ check(!keepsSavedKey("", null, KeyState.None), "no key saved")
+ check(!keepsSavedKey("sk-new", "sk-saved", KeyState.Ok), "a new key is checked")
+ }
+
fun keyFileIsPrivate() {
val key = AIKey(PlainProtector)
check(key.save("sk-test-0000000000"), "saved")
diff --git a/android/core/src/main/kotlin/cicada/Ling.kt b/android/core/src/main/kotlin/cicada/Ling.kt
index 5d48302..8d694cc 100644
--- a/android/core/src/main/kotlin/cicada/Ling.kt
+++ b/android/core/src/main/kotlin/cicada/Ling.kt
@@ -83,6 +83,12 @@ enum class Priority { Speak, Translate, Notes }
enum class KeyState { None, Unchecked, Checking, Ok, Invalid, Unreachable }
+/// 继续 on the key step with a key already saved (the guide opened again from 设置): an empty field,
+/// or the saved key again, keeps it, unless it was found invalid. Onboarding opens past the key step
+/// on the same condition.
+fun keepsSavedKey(typed: String, saved: String?, state: KeyState) =
+ saved != null && state != KeyState.Invalid && (typed.isEmpty() || typed == saved)
+
/// `retryAfter`: seconds the service asked us to wait (a 429's Retry-After), when it said.
class LingException(val kind: Kind, val status: Int = 0, val retryAfter: Double? = null) : Exception(if (kind == Kind.Http) "http$status" else kind.name) {
enum class Kind { NoKey, InvalidKey, RateLimited, Hijacked, Timeout, Http, Network, Parse }