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(windows): turning the system proxy on or off makes Cicada check the AI service again when it couldn't reach it

wquguru123026bfbd1c
diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.cs
index bfba98d..0f91eb4 100644
--- a/windows/src/Cicada/App.cs
+++ b/windows/src/Cicada/App.cs
@@ -180,6 +180,7 @@ sealed class Controller
void Changed() => Dispatch.BeginInvoke(() =>
{
+ WatchProxy();
notesWindow?.Refresh();
mainWindow?.Refresh();
if (flyout?.IsVisible == true) flyout.Refresh();
@@ -894,6 +895,35 @@ sealed class Controller
System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged += (_, e) => { if (e.IsAvailable) Changed(); };
}
+ /// Turning the system proxy on or off (or pointing it elsewhere) changes no address, so the
+ /// watch above misses it. While the service is unreachable the proxy settings are read every
+ /// 3 s (three registry values; HttpClient follows them by itself) and a change is checked like
+ /// a network change. Not polled otherwise.
+ void WatchProxy()
+ {
+ var unreachable = Ling.HasKey && Ling.Health.Failure?.Why == AICheck.Reason.Unreachable;
+ if (!unreachable) { proxyPoll?.Stop(); return; }
+ if (proxyPoll is null)
+ {
+ proxyPoll = new DispatcherTimer { Interval = TimeSpan.FromSeconds(3) };
+ proxyPoll.Tick += (_, _) =>
+ {
+ var now = WinProxy.Snapshot();
+ // A check under way may have started on the old settings: the change waits for it.
+ if (now == proxySeen || Ling.Health.IsRunning) return;
+ Log.Debug("proxy: system proxy settings changed");
+ proxySeen = now;
+ Ling.NetworkChanged();
+ };
+ }
+ if (proxyPoll.IsEnabled) return;
+ proxySeen = WinProxy.Snapshot();
+ proxyPoll.Start();
+ }
+
+ DispatcherTimer? proxyPoll;
+ string? proxySeen;
+
/// The service, its address, models or key changed: forget the old check and check again.
public void AIChanged()
{
diff --git a/windows/src/Cicada/Platform.cs b/windows/src/Cicada/Platform.cs
index c6c9616..63a09dc 100644
--- a/windows/src/Cicada/Platform.cs
+++ b/windows/src/Cicada/Platform.cs
@@ -181,4 +181,15 @@ static class WinProxy
}
catch (Exception e) { Log.Debug($"proxy: unreadable ({e.GetType().Name})"); return false; }
}
+
+ /// The settings that decide where requests go, as one string to compare (WatchProxy).
+ public static string Snapshot()
+ {
+ try
+ {
+ using var k = Registry.CurrentUser.OpenSubKey(Key);
+ return $"{k?.GetValue("ProxyEnable")}|{k?.GetValue("ProxyServer")}|{k?.GetValue("AutoConfigURL")}|{k?.GetValue("ProxyOverride")}";
+ }
+ catch { return ""; }
+ }
}