知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
fix(windows): starting to listen while the AI service is unreachable asks within about 2 seconds, and Check Again and Start shows Checking… while it looks
wqugurudccfa215b809
diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.csindex 0f91eb4..cd1c6a7 100644--- a/windows/src/Cicada/App.cs+++ b/windows/src/Cicada/App.cs@@ -448,8 +448,10 @@ sealed class Controller/// The user's 开始听: blocked only by a failure the last result knows of. A hear model that/// can't hear asks to switch to the recommended one; an unreachable service is looked at once- /// more first. Unknown or busy starts as usual. A dialog comes after a yield, so the debug pipe- /// that asked for the start replies first; a start that needs none has happened by then.+ /// more, but only waited for briefly (a check that can't connect takes 10–20 s): still unknown+ /// then, the dialog says what the last check found and its 重新检查并开始 waits in place, with+ /// 正在检查… on the button. Unknown or busy starts as usual. A dialog comes after a yield, so+ /// the debug pipe that asked for the start replies first; a start that needs none has happened by then.public async Task StartChecked(Func<IAudioSource> source){if (Listen.Listening || starting) return;@@ -457,8 +459,15 @@ sealed class Controllerstarting = true;try{- if (Ling.Health.Failure?.Why == AICheck.Reason.Unreachable) await Ling.Check();- var f = Ling.Health.Failure;+ var shown = Ling.Health;+ Task? recheck = null;+ if (shown.Failure?.Why == AICheck.Reason.Unreachable)+ {+ recheck = Ling.Check();+ if (await Task.WhenAny(recheck, Task.Delay(QuickLook)) == recheck) shown = Ling.Health;+ else Log.Debug($"listen: start, the service still unreachable after {QuickLook.TotalSeconds:0} s, asking");+ }+ var f = shown.Failure;if (f?.Why == AICheck.Reason.Deaf){var service = Ling.ServiceName;@@ -476,14 +485,25 @@ sealed class Controller}if (f?.Why == AICheck.Reason.Unreachable){- var h = Ling.Health;- var body = h.Message(Ling.ServiceName, Ling.ServiceHost, Ling.Config.TextModel, Ling.HearName) ?? "";- if (h.ProxyLine(Ling.ServiceName, Ling.ServiceHost) is { } proxy) body += "\n" + proxy;+ string Body(AICheck h) => (h.Message(Ling.ServiceName, Ling.ServiceHost, Ling.Config.TextModel, Ling.HearName) ?? "")+ + (h.ProxyLine(Ling.ServiceName, Ling.ServiceHost) is { } proxy ? "\n" + proxy : "");await Task.Yield();- var choice = Dialogs.Choose(VisibleWindow(), LF("连不上 %@", Ling.ServiceName), body, L("重新检查并开始"), L("打开设置"));+ // 重新检查并开始: the check already under way (or one that finished reachable while the+ // dialog was up), else a new one; reachable closes the dialog.+ async Task<string?> Retry()+ {+ var under = recheck;+ recheck = null;+ if (under is null || under.IsCompleted && Ling.Health.Failure?.Why == AICheck.Reason.Unreachable) await Ling.Check();+ else await under;+ var h = Ling.Health;+ return h.Failure?.Why == AICheck.Reason.Unreachable ? Body(h) : null;+ }+ var choice = Dialogs.Choose(VisibleWindow(), LF("连不上 %@", Ling.ServiceName), Body(shown), L("重新检查并开始"), L("打开设置"), Retry);if (choice == 2) ShowAISettings();else if (choice == 1){+ // Reached now; the check may still have found something else (a deaf model): ask again.starting = false;await StartChecked(source);}@@ -495,6 +515,8 @@ sealed class Controller}bool starting;+ /// How long 开始听 waits for a fresh look at an unreachable service before asking.+ static readonly TimeSpan QuickLook = TimeSpan.FromSeconds(2);/// A window of ours to put a dialog over; null (the screen's centre) from the tray.Window? VisibleWindow() => new Window?[] { settingsWindow, mainWindow, onboarding }.FirstOrDefault(w => w?.IsVisible == true && w.WindowState != WindowState.Minimized);diff --git a/windows/src/Cicada/Dialogs.cs b/windows/src/Cicada/Dialogs.csindex db38560..9737250 100644--- a/windows/src/Cicada/Dialogs.cs+++ b/windows/src/Cicada/Dialogs.cs@@ -22,13 +22,16 @@ static class Dialogs/// Two ways on, both named (开始听 blocked: 换成推荐的并开始 / 打开设置): 1 for `primary`, 2 for/// `other`, 0 when closed. No `primary`: just `other` and 取消. No owner: the screen's centre.- public static int Choose(Window? owner, string title, string body, string? primary, string other)+ /// `retry` makes `primary` work in place (重新检查并开始): the dialog stays with 正在检查… on the+ /// button, then closes as 1 when it returns null, or shows the body it returns and waits again.+ public static int Choose(Window? owner, string title, string body, string? primary, string other, Func<Task<string?>>? retry = null){int chosen = 0;var text = Ui.Text(body, 14, Palette.Body);if (primary is null) return Show(owner, title, text, other, danger: false, null) is null ? 0 : 2;var second = Ui.Button(other, () => { chosen = 2; Window.GetWindow(text)?.Close(); });- var r = Show(owner, title, text, primary, danger: false, null, secondary: second);+ var r = Show(owner, title, text, primary, danger: false, null, secondary: second,+ work: retry is null ? null : async () => { if (await retry() is not { } again) return true; text.Text = again; return false; });return r is not null ? 1 : chosen;}@@ -42,7 +45,7 @@ static class Dialogsreturn Show(owner, title, content, ok, danger: false, box);}- static string? Show(Window? owner, string title, FrameworkElement content, string ok, bool danger, TextBox? field, bool single = false, Button? secondary = null)+ static string? Show(Window? owner, string title, FrameworkElement content, string ok, bool danger, TextBox? field, bool single = false, Button? secondary = null, Func<Task<bool>>? work = null){string? result = null;var dialog = new Window@@ -51,9 +54,24 @@ static class DialogsResizeMode = ResizeMode.NoResize, ShowInTaskbar = false, SizeToContent = SizeToContent.Height, Width = 456 + 32,WindowStartupLocation = owner is null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner, Topmost = owner is null, FontFamily = Palette.Font, Title = title,};- void Accept() { result = field?.Text.Trim() ?? ""; dialog.Close(); }- var primary = Ui.Button(ok, Accept, danger ? Ui.Kind.Danger : Ui.Kind.Primary);- var cancel = secondary ?? Ui.Button(L("取消"), dialog.Close);+ Button? primary = null, cancel = null;+ async void Accept()+ {+ if (work is not null)+ {+ var label = ((StackPanel)primary!.Content).Children.OfType<TextBlock>().First();+ primary.IsEnabled = cancel!.IsEnabled = false;+ label.Text = L("正在检查…");+ var done = await work();+ label.Text = ok;+ primary.IsEnabled = cancel.IsEnabled = true;+ if (!done) { primary.Focus(); return; }+ }+ result = field?.Text.Trim() ?? "";+ dialog.Close();+ }+ primary = Ui.Button(ok, Accept, danger ? Ui.Kind.Danger : Ui.Kind.Primary);+ cancel = secondary ?? Ui.Button(L("取消"), dialog.Close);// A named second way on isn't 取消: Esc just closes.primary.IsDefault = true; cancel.IsCancel = secondary is null;if (secondary is not null) dialog.KeyDown += (_, e) => { if (e.Key == Key.Escape) dialog.Close(); };