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.

chore(windows): bring records forward on a second launch, theme dialogs, log gate waits

wqugurud3321c5009cb
diff --git a/windows/src/Cicada.Core/Ling.cs b/windows/src/Cicada.Core/Ling.cs
index 8b6ff5d..bf5d0ac 100644
--- a/windows/src/Cicada.Core/Ling.cs
+++ b/windows/src/Cicada.Core/Ling.cs
@@ -188,8 +188,10 @@ public sealed class LingClient
double delay = 1;
for (int attempt = 1; ; attempt++)
{
+ var queued = DateTime.UtcNow;
await Acquire(priority, cancel);
var started = DateTime.UtcNow;
+ if ((started - queued).TotalSeconds > 1) Log.Debug($"ling: {priority} waited {(started - queued).TotalMilliseconds:F0} ms at the gate");
try
{
var root = await Post("chat/completions", payload, k, timeout, cancel);
diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.cs
index a7ffa31..73710a7 100644
--- a/windows/src/Cicada/App.cs
+++ b/windows/src/Cicada/App.cs
@@ -16,7 +16,7 @@ static class Program
Paths.Dev = Paths.Dev || args.Contains("--dev");
// One Cicada per user: a second launch just opens the records of the running one.
using var single = new Mutex(true, Paths.Dev ? "com.wquguru.cicada.dev" : "com.wquguru.cicada", out bool first);
- if (!first) { DebugServer.Send("show records"); return 0; }
+ if (!first) { Native.LetOthersTakeForeground(); DebugServer.Send("show records"); return 0; }
var app = new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown };
app.DispatcherUnhandledException += (_, e) => { Log.Debug($"ui: unhandled {e.Exception.GetType().Name}: {e.Exception.Message}"); e.Handled = true; };
var controller = new Controller(app);
diff --git a/windows/src/Cicada/MainWindow.cs b/windows/src/Cicada/MainWindow.cs
index 7d654ae..bf0bcce 100644
--- a/windows/src/Cicada/MainWindow.cs
+++ b/windows/src/Cicada/MainWindow.cs
@@ -15,6 +15,30 @@ sealed class MainWindow : Window
string? selected;
bool refreshQueued;
+ /// A record row: grey ground when selected, a lighter one under the mouse; no Windows blue.
+ static readonly Style RowStyle = MakeRowStyle();
+
+ static Style MakeRowStyle()
+ {
+ var template = new ControlTemplate(typeof(ListBoxItem));
+ var border = new FrameworkElementFactory(typeof(Border), "bg");
+ border.SetValue(Border.CornerRadiusProperty, new CornerRadius(8));
+ border.SetValue(Border.BackgroundProperty, Brushes.Transparent);
+ border.SetValue(Border.MarginProperty, new Thickness(0, 0, 0, 2));
+ border.AppendChild(new FrameworkElementFactory(typeof(ContentPresenter)));
+ template.VisualTree = border;
+ var hover = new Trigger { Property = UIElement.IsMouseOverProperty, Value = true };
+ hover.Setters.Add(new Setter(Border.BackgroundProperty, Palette.Ground, "bg"));
+ var chosen = new Trigger { Property = ListBoxItem.IsSelectedProperty, Value = true };
+ chosen.Setters.Add(new Setter(Border.BackgroundProperty, Palette.Line, "bg"));
+ template.Triggers.Add(hover); template.Triggers.Add(chosen);
+ var style = new Style(typeof(ListBoxItem));
+ style.Setters.Add(new Setter(Control.TemplateProperty, template));
+ style.Setters.Add(new Setter(FrameworkElement.FocusVisualStyleProperty, null));
+ style.Seal();
+ return style;
+ }
+
public MainWindow(Controller app)
{
this.app = app;
@@ -66,7 +90,7 @@ sealed class MainWindow : Window
Ui.Text(SessionStore.DisplayTitle(s), 13, Palette.Ink, FontWeights.SemiBold, wrap: false),
Ui.Text(live ? L("正在听") : $"{s.StartedAt.ToLocalTime():yyyy-MM-dd HH:mm} · {Languages.Clock(s.Duration.TotalSeconds)}", 11, live ? Palette.Accent : Palette.Tertiary, wrap: false));
row.Margin = new Thickness(6, 6, 6, 6);
- list.Items.Add(new ListBoxItem { Content = row, Tag = s.Id });
+ list.Items.Add(new ListBoxItem { Content = row, Tag = s.Id, Style = RowStyle });
}
if (sessions.Count == 0) { selected = null; detail.Content = Empty(); return; }
selected ??= sessions[0].Id;
diff --git a/windows/src/Cicada/Native.cs b/windows/src/Cicada/Native.cs
index c21982b..adcf8e3 100644
--- a/windows/src/Cicada/Native.cs
+++ b/windows/src/Cicada/Native.cs
@@ -16,6 +16,11 @@ static class Native
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtrW")] static extern IntPtr GetWindowLongPtr(IntPtr hwnd, int index);
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtrW")] static extern IntPtr SetWindowLongPtr(IntPtr hwnd, int index, IntPtr value);
[DllImport("user32.dll")] static extern bool SetWindowDisplayAffinity(IntPtr hwnd, uint affinity);
+ [DllImport("user32.dll")] static extern bool AllowSetForegroundWindow(int processId);
+
+ /// A second launch has the foreground (the user just opened it); this lets the running Cicada
+ /// bring its records window forward instead of flashing in the taskbar behind other windows.
+ public static void LetOthersTakeForeground() => AllowSetForegroundWindow(-1 /* ASFW_ANY */);
/// Makes a window like the Mac's non-activating panel: clicks and drags work, but the app the
/// user is in keeps the keyboard focus, and the window isn't in Alt+Tab or the taskbar.
diff --git a/windows/src/Cicada/app.manifest b/windows/src/Cicada/app.manifest
index 146dcfb..b0bfce4 100644
--- a/windows/src/Cicada/app.manifest
+++ b/windows/src/Cicada/app.manifest
@@ -7,6 +7,12 @@
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
+ <!-- Common Controls 6: message boxes and the tray menu get today's Windows look, not Windows 2000's. -->
+ <dependency>
+ <dependentAssembly>
+ <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
+ </dependentAssembly>
+ </dependency>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>