知了 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
feat(windows): Share… copies the link and password together as one message in the app's language
wqugurub01fe7fc5921
diff --git a/windows/src/Cicada.Core/Share.cs b/windows/src/Cicada.Core/Share.csindex c7261e7..29ca01c 100644--- a/windows/src/Cicada.Core/Share.cs+++ b/windows/src/Cicada.Core/Share.cs@@ -195,6 +195,21 @@ public sealed class ShareRecord[JsonPropertyName("scope")] public string Scope { get; set; } = "notes";[JsonPropertyName("token")] public string Token { get; set; } = "";[JsonPropertyName("url")] public string Url { get; set; } = "";++ /// What 生成并复制 and 复制 put on the clipboard, in the UI's language (the Mac's+ /// ShareSheet.clipboardText): the title, the link on a line of its own (chat apps then make it+ /// a link), the password and how long it stays open.+ public string Message(string title, DateTimeOffset now)+ {+ var left = DaysLeft(now);+ var valid = left >= 365 ? Strings.L("1 年内有效") : Strings.LF("%lld 天内有效", left);+ var last = Password is { } pw ? Strings.LF("密码:%@(%@)", pw, valid) : valid;+ return string.Join("\n", Strings.LF("「%@」会议记录", title), Url, last);+ }++ /// Whole days until the link closes, at least 1. The server sets the expiry from its own clock,+ /// so a computer a second behind it would round a fresh 7-day link up to 8: an hour's slack.+ public int DaysLeft(DateTimeOffset now) => Math.Max(1, (int)Math.Ceiling((ExpiresAt - now - TimeSpan.FromHours(1)).TotalDays));}/// Where the review found a problem: the notes, or lines `from`…`to` of what was sent.diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.csindex 61a080a..3b6008f 100644--- a/windows/src/Cicada/App.cs+++ b/windows/src/Cicada/App.cs@@ -1430,13 +1430,16 @@ static class DebugServer_ = Task.Run(async () => Log.Debug($"share: revoked {await app.Sharing.Revoke(r, arg)}"));break;}- // sharesheet <record id>[,full][,pw][,names][,30|365][,go] opens 分享… (go presses 生成链接);- // sharesheet leaveout presses 去掉这些内容后分享; sharesheet alone closes it.+ // sharesheet <record id>[,full][,pw][,names][,30|365][,more][,go] opens 分享… (more presses 更改,+ // go 生成并复制); sharesheet leaveout presses 去掉这些内容后分享; on the done step+ // sharesheet copy|copylink|copypw|menu presses 复制, its menu's items, or opens the menu;+ // sharesheet alone closes it.case "sharesheet" or "shareSheet":{var p = arg.Split(',', StringSplitOptions.RemoveEmptyEntries);if (p.Length == 0) { ShareDialog.Current?.Close(); break; }if (p[0] == "leaveout") { ShareDialog.Current?.DebugLeaveOut(); break; }+ if (p[0] is "copy" or "copylink" or "copypw" or "menu") { ShareDialog.Current?.Debug(p); break; }if (app.Store.Get(p[0]) is not { } s) return new JsonObject { ["error"] = "no such record" };app.ShowRecords(p[0]);app.Dispatcher().BeginInvoke(() => app.ShareSheet(s).Debug(p));diff --git a/windows/src/Cicada/ShareDialog.cs b/windows/src/Cicada/ShareDialog.csindex 237283d..b6791ad 100644--- a/windows/src/Cicada/ShareDialog.cs+++ b/windows/src/Cicada/ShareDialog.cs@@ -19,7 +19,7 @@ sealed class ShareDialog : WindowStep step = Step.Settings;ShareScope scope = ShareScope.Notes;int days = 7;- bool names, usePassword, summaryInPreview, dropNotes, confirmRevoke;+ bool names, usePassword, summaryInPreview, dropNotes, confirmRevoke, showOptions;string password = SharePassword.Make();readonly HashSet<int> removed = [];List<ShareHit> hits = [];@@ -78,36 +78,67 @@ sealed class ShareDialog : Windowp.Children.Add(Gap(Ui.Text(L("内容"), 12, Palette.Secondary, FontWeights.SemiBold), 16));p.Children.Add(Gap(Radio(L("只分享纪要"), scope == ShareScope.Notes, HasNotes, () => scope = ShareScope.Notes), 6));p.Children.Add(Gap(Radio(L("纪要和双语全文"), scope == ShareScope.Full, true, () => scope = ShareScope.Full), 6));- p.Children.Add(Gap(Row(L("有效期"), Ui.Choice([("7", L("7 天")), ("30", L("30 天")), ("365", L("1 年"))], days.ToString(), v => days = int.Parse(v), width: 140)), 16));- p.Children.Add(Gap(Row(L("显示说话人名字"), Ui.Switch(names, v => names = v, L("显示说话人名字"))), 12));- p.Children.Add(Gap(Row(L("用密码保护"), Ui.Switch(usePassword, v => { usePassword = v; Render(); }, L("用密码保护"))), 12));Button? make = null;- if (usePassword)+ if (showOptions){- var box = new TextBox { Text = password, FontFamily = new FontFamily("Cascadia Mono, Consolas") };- System.Windows.Automation.AutomationProperties.SetName(box, L("用密码保护"));- box.TextChanged += (_, _) => { password = box.Text; if (make is not null) make.IsEnabled = password.Trim().Length >= 6; };- var again = Ui.Button(L("换一个"), () => { password = SharePassword.Make(); Render(); }, height: 34);- again.MinWidth = 0; again.Margin = new Thickness(8, 0, 0, 0);- var grid = new DockPanel();- DockPanel.SetDock(again, Dock.Right);- grid.Children.Add(again); grid.Children.Add(Ui.Field(box));- p.Children.Add(Gap(grid, 8));+ p.Children.Add(Gap(Row(L("用密码保护"), Ui.Switch(usePassword, v => { usePassword = v; Render(); }, L("用密码保护"))), 16));+ if (usePassword)+ {+ var box = new TextBox { Text = password, FontFamily = new FontFamily("Cascadia Mono, Consolas") };+ System.Windows.Automation.AutomationProperties.SetName(box, L("用密码保护"));+ box.TextChanged += (_, _) => { password = box.Text; if (make is not null) make.IsEnabled = password.Trim().Length >= 6; };+ var again = Ui.Button(L("换一个"), () => { password = SharePassword.Make(); Render(); }, height: 34);+ again.MinWidth = 0; again.Margin = new Thickness(8, 0, 0, 0);+ var grid = new DockPanel();+ DockPanel.SetDock(again, Dock.Right);+ grid.Children.Add(again); grid.Children.Add(Ui.Field(box));+ p.Children.Add(Gap(grid, 8));+ }+ p.Children.Add(Gap(Row(L("有效期"), Ui.Choice([("7", L("7 天")), ("30", L("30 天")), ("365", L("1 年"))], days.ToString(), v => days = int.Parse(v), width: 140)), 12));+ p.Children.Add(Gap(Row(L("显示说话人名字"), Ui.Switch(names, v => names = v, L("显示说话人名字"))), 12));+ if (!usePassword && HasNotes)+ p.Children.Add(Gap(Row(L("预览卡显示摘要"), Ui.Switch(summaryInPreview, v => summaryInPreview = v, L("预览卡显示摘要"))), 12));+ }+ else+ {+ // The choices already made, in one line; 更改 opens them in place.+ var change = Ui.Button(L("更改"), () => { showOptions = true; Render(); }, height: 28);+ change.MinWidth = 0; change.Padding = new Thickness(12, 0, 12, 0); change.Margin = new Thickness(8, 0, 0, 0);+ var line = Ui.Text(Summary, 13, Palette.Secondary, wrap: false);+ line.TextTrimming = TextTrimming.CharacterEllipsis; line.VerticalAlignment = VerticalAlignment.Center;+ var d = new DockPanel();+ DockPanel.SetDock(change, Dock.Right);+ d.Children.Add(change); d.Children.Add(line);+ p.Children.Add(Gap(d, 16));}- else if (HasNotes)- p.Children.Add(Gap(Row(L("预览卡显示摘要"), Ui.Switch(summaryInPreview, v => summaryInPreview = v, L("预览卡显示摘要"))), 12));- p.Children.Add(Gap(Ui.Helper(usePassword ? L("建议把链接和密码分两条消息发送。") : L("内容将上传至 cicada.indaloop.app,拿到链接的人都能看。")), 16));- make = Ui.Button(L("生成链接"), Go, Ui.Kind.Primary);+ if (!usePassword) p.Children.Add(Gap(Ui.Helper(L("内容将上传至 cicada.indaloop.app,拿到链接的人都能看。")), 16));+ make = Ui.Button(L("生成并复制"), Go, Ui.Kind.Primary);make.IsDefault = true;make.IsEnabled = !usePassword || password.Trim().Length >= 6;p.Children.Add(Gap(Buttons(Ui.Button(L("取消"), Close), make), 24));return p;}- /// Takes the dialog's settings from the debug pipe: `sharesheet <id>[,full][,pw][,names][,30][,go]`.+ string Summary => string.Join(" · ",+ usePassword ? L("密码保护") : L("无密码"),+ days == 365 ? L("1 年有效") : LF("%lld 天有效", days),+ names ? L("显示名字") : L("不显示名字"));++ /// Takes the dialog's settings from the debug pipe: `sharesheet <id>[,full][,pw][,names][,30][,more][,go]`+ /// (more presses 更改); on the done step, `copy`, `copylink` and `copypw` press 复制 and its menu's items.public void Debug(IReadOnlyCollection<string> p){+ if (step == Step.Done && record is { } r)+ {+ if (p.Contains("menu")) { copyMenu?.Invoke(); return; }+ if (p.Contains("copy")) Copy(MessageOf(r), "all");+ else if (p.Contains("copylink")) Copy(r.Url, "link");+ else if (p.Contains("copypw") && r.Password is { } pw) Copy(pw, "password");+ Render();+ return;+ }if (step != Step.Settings) return;+ if (p.Contains("more")) showOptions = true;if (p.Contains("full")) scope = ShareScope.Full;if (p.Contains("pw")) usePassword = true;if (p.Contains("names")) names = true;@@ -135,7 +166,7 @@ sealed class ShareDialog : Window{case ShareOutcome.Shared s:record = s.Record;- Copy(s.Record.Url, "link");+ Copy(MessageOf(s.Record), "all");views = 0;step = Step.Done;break;@@ -244,9 +275,8 @@ sealed class ShareDialog : WindowUIElement DoneView(ShareRecord r){var p = new StackPanel();- p.Children.Add(Header(copied == "link" ? L("链接已复制") : L("已分享")));- p.Children.Add(Gap(Copyable(r.Url, "link", L("复制链接")), 16));- if (r.Password is { } pw) p.Children.Add(Gap(Copyable(pw, "password", L("复制密码")), 8));+ p.Children.Add(Header(copied == "all" ? (r.Password is null ? L("链接已复制") : L("链接和密码已复制")) : L("已分享")));+ p.Children.Add(Gap(Link(r), 16));p.Children.Add(Gap(Ui.Text(Status(r), 12, Palette.Secondary), 12));p.Children.Add(Gap(new Border { Height = 1, Background = Palette.Line }, 16));if (confirmRevoke)@@ -281,27 +311,52 @@ sealed class ShareDialog : Windowreturn p;}- FrameworkElement Copyable(string text, string what, string label)+ /// The link and, under it, the password in one grey box; beside it one 复制 that copies both as+ /// one message, its arrow either alone for whoever sends them apart (the Mac's Menu with a+ /// primary action). Without a password it is a plain button.+ FrameworkElement Link(ShareRecord r){- var value = new TextBox+ TextBox Value(string text, Brush color) => new(){Text = text, IsReadOnly = true, BorderThickness = new Thickness(0), Background = Brushes.Transparent, FontSize = 12,- FontFamily = new FontFamily("Cascadia Mono, Consolas"), Foreground = Palette.Ink, VerticalAlignment = VerticalAlignment.Center,- Padding = new Thickness(0), MinHeight = 0, VerticalContentAlignment = VerticalAlignment.Center,+ FontFamily = new FontFamily("Cascadia Mono, Consolas"), Foreground = color, Padding = new Thickness(0), MinHeight = 0,};- var box = new Border { Background = Palette.Subtle, CornerRadius = new CornerRadius(6), Padding = new Thickness(6, 0, 8, 0), Child = value, Height = 32, VerticalAlignment = VerticalAlignment.Center };- var b = Ui.Button(copied == what ? L("已复制") : label, () => { Copy(text, what); Render(); }, height: 32);- b.MinWidth = 0; b.Margin = new Thickness(8, 0, 0, 0);+ var lines = new StackPanel { VerticalAlignment = VerticalAlignment.Center };+ lines.Children.Add(Value(r.Url, Palette.Ink));+ if (r.Password is { } pw) lines.Children.Add(Gap(Value(LF("密码:%@", pw), Palette.Secondary), 4));+ var box = new Border { Background = Palette.Subtle, CornerRadius = new CornerRadius(6), Padding = new Thickness(6, 7, 8, 7), Child = lines, MinHeight = 32 };+ var label = copied is null ? L("复制") : L("已复制");+ void All() { Copy(MessageOf(r), "all"); Render(); }+ FrameworkElement copy;+ if (r.Password is { } p)+ {+ (copy, copyMenu) = Ui.SplitButton(label, All, [+ (L("只复制链接"), () => { Copy(r.Url, "link"); Render(); }),+ (L("只复制密码"), () => { Copy(p, "password"); Render(); }),+ ]);+ }+ else+ {+ var b = Ui.Button(label, All, height: 32);+ b.MinWidth = 0;+ copy = b;+ copyMenu = null;+ }+ copy.Margin = new Thickness(8, 0, 0, 0);+ copy.VerticalAlignment = VerticalAlignment.Center;var d = new DockPanel();- DockPanel.SetDock(b, Dock.Right);- d.Children.Add(b); d.Children.Add(box);+ DockPanel.SetDock(copy, Dock.Right);+ d.Children.Add(copy); d.Children.Add(box);return d;}+ Action? copyMenu;++ string MessageOf(ShareRecord r) => r.Message(SessionStore.DisplayTitle(session), DateTimeOffset.Now);+string Status(ShareRecord r){- var left = Math.Max(1, (int)Math.Ceiling((r.ExpiresAt - DateTimeOffset.Now).TotalDays));- var expiry = LF("%lld 天后失效", left);+ var expiry = LF("%lld 天后失效", r.DaysLeft(DateTimeOffset.Now));return views is { } v ? expiry + " · " + LF("打开 %lld 次", v) : expiry;}diff --git a/windows/src/Cicada/Ui.cs b/windows/src/Cicada/Ui.csindex fe31655..0712f93 100644--- a/windows/src/Cicada/Ui.cs+++ b/windows/src/Cicada/Ui.cs@@ -187,6 +187,44 @@ static class Uireturn b;}+ /// A split button, as Windows' own: the label does the usual thing, the chevron beside it opens+ /// a menu of the alternatives. One soft-grey button with a hairline between the halves; `Open`+ /// is the chevron's click, for the debug pipe.+ public static (FrameworkElement Button, Action Open) SplitButton(string label, Action onClick, IReadOnlyList<(string label, Action act)> items, double height = 32)+ {+ Button Half(UIElement content, Thickness padding)+ {+ var b = new Button { Content = content, Background = Palette.Mica, Foreground = Palette.Ink, BorderThickness = new Thickness(0), Height = height, Padding = padding, Cursor = Cursors.Hand };+ b.Template = Template(plain: true, radius: 0, soft: true);+ return b;+ }+ var main = Half(Text(label, 14, Palette.Ink, wrap: false), new Thickness(14, 0, 12, 0));+ main.Click += (_, _) => onClick();+ AutomationName(main, label);+ var arrow = Half(Icon(Icons.Chevron, 14, Palette.Secondary, stroke: 1.8), new Thickness(7, 0, 7, 0));+ AutomationName(arrow, string.Join(" / ", items.Select(i => i.label)));+ var line = new Border { Width = 1, Background = Palette.Line, Margin = new Thickness(0, 7, 0, 7) };+ var g = new Grid { Background = Palette.Mica, VerticalAlignment = VerticalAlignment.Center };+ for (int i = 0; i < 3; i++) g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });+ Grid.SetColumn(line, 1); Grid.SetColumn(arrow, 2);+ g.Children.Add(main); g.Children.Add(line); g.Children.Add(arrow);+ // The halves are square; the whole is clipped to the usual 10-point corners.+ g.SizeChanged += (_, e) => g.Clip = new RectangleGeometry(new Rect(e.NewSize), 10, 10);+ void Open()+ {+ var menu = new ContextMenu { PlacementTarget = g, Placement = PlacementMode.Bottom, FontFamily = Palette.Font };+ foreach (var (text, act) in items)+ {+ var item = new MenuItem { Header = text };+ item.Click += (_, _) => act();+ menu.Items.Add(item);+ }+ menu.IsOpen = true;+ }+ arrow.Click += (_, _) => Open();+ return (g, Open);+ }+/// A square icon-only button with a tooltip and an accessible name.public static Button IconButton(string icon, string name, Action onClick, Brush? color = null, double size = 40, double iconSize = 16, bool fill = false, bool onDark = false){diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.csindex 5a12790..9365ca6 100644--- a/windows/tests/Cicada.Tests/Program.cs+++ b/windows/tests/Cicada.Tests/Program.cs@@ -3264,6 +3264,27 @@ static class TestsEqual("Emma,Kenji", string.Join(",", ShareProjection.Doc(s, ShareScope.Full, true).Lines.Select(l => l.Who).Distinct().Order()), "names");}+ public static void ShareCopiesOneMessage()+ {+ var now = new DateTimeOffset(2026, 11, 8, 10, 0, 0, TimeSpan.Zero);+ var r = new ShareRecord { Url = "https://cicada.indaloop.app/s/abc", Password = "k7m2p9", ExpiresAt = now.AddDays(7).AddSeconds(-3) };+ Equal("「周会」会议记录\nhttps://cicada.indaloop.app/s/abc\n密码:k7m2p9(7 天内有效)", r.Message("周会", now), "Chinese, with a password");+ var open = new ShareRecord { Url = r.Url, ExpiresAt = now.AddDays(365) };+ Equal("「周会」会议记录\nhttps://cicada.indaloop.app/s/abc\n1 年内有效", open.Message("周会", now), "no password, a year");+ Equal(7, new ShareRecord { ExpiresAt = now.AddDays(7).AddSeconds(2) }.DaysLeft(now), "a clock a little behind the server's still says 7");+ Equal(7, new ShareRecord { ExpiresAt = now.AddDays(6.5) }.DaysLeft(now), "part of a day counts");+ Equal(1, new ShareRecord { ExpiresAt = now.AddMinutes(10) }.DaysLeft(now), "never 0");+ var res = Path.Combine(AppContext.BaseDirectory, "Resources");+ try+ {+ Strings.Load(res, "en");+ Equal("Meeting record: Weekly\nhttps://cicada.indaloop.app/s/abc\nPassword: k7m2p9 (valid for 7 days)", r.Message("Weekly", now), "English");+ Strings.Load(res, "ja");+ Equal("パスワード:k7m2p9(7 日間有効)", r.Message("x", now).Split('\n')[2], "Japanese");+ }+ finally { Strings.Load(res, "zh-Hans"); }+ }+public static void ShareRoundsAndLanguages(){var s = ShareSession();