@sonicloud/dsh-sonicloud-device 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +44 -1
  2. package/CHANGELOG.zh.md +44 -1
  3. package/README.md +36 -11
  4. package/README.zh.md +26 -1
  5. package/dist/build.json +1 -1
  6. package/dist/client.js +1594 -98
  7. package/docs/contributing/development.md +35 -5
  8. package/docs/specs/ci-cd.md +5 -4
  9. package/docs/specs/multilingual.md +98 -0
  10. package/docs/specs/smart-mouse-plugin.md +31 -1
  11. package/locale/de.json +7 -0
  12. package/locale/en.json +7 -0
  13. package/locale/es.json +7 -0
  14. package/locale/fr.json +7 -0
  15. package/locale/ja.json +7 -0
  16. package/locale/pt.json +7 -0
  17. package/locale/ru.json +7 -0
  18. package/locale/zh.json +7 -0
  19. package/native/README.md +4 -0
  20. package/native/desktop/VOICE_SOURCE.json +16 -0
  21. package/native/desktop/VoicePanel.cs +70 -33
  22. package/native/desktop/VoicePanel.swift +83 -19
  23. package/native/desktop/darwin-arm64/Sonicloud Voice.app/Contents/MacOS/sonicloud-voice +0 -0
  24. package/native/desktop/darwin-arm64/Sonicloud Voice.app/Contents/_CodeSignature/CodeResources +115 -0
  25. package/native/screenshot/README.md +34 -0
  26. package/native/screenshot/SOURCE.json +218 -0
  27. package/native/screenshot/darwin-arm64/screentool-macos-1.2.2.zip +0 -0
  28. package/native/screenshot/patches/hide-cloud-actions.patch +202 -0
  29. package/native/screenshot/patches/mac-permissions.patch +545 -0
  30. package/native/screenshot/patches/upstream-files.json +22 -0
  31. package/native/screenshot/win32-x64/PixPinScrollCapture.dll +0 -0
  32. package/native/screenshot/win32-x64/Qt5Core.dll +0 -0
  33. package/native/screenshot/win32-x64/Qt5Gui.dll +0 -0
  34. package/native/screenshot/win32-x64/Qt5Network.dll +0 -0
  35. package/native/screenshot/win32-x64/Qt5Svg.dll +0 -0
  36. package/native/screenshot/win32-x64/Qt5Widgets.dll +0 -0
  37. package/native/screenshot/win32-x64/iconengines/qsvgicon.dll +0 -0
  38. package/native/screenshot/win32-x64/imageformats/qjpeg.dll +0 -0
  39. package/native/screenshot/win32-x64/imageformats/qsvg.dll +0 -0
  40. package/native/screenshot/win32-x64/libcrypto-1_1-x64.dll +0 -0
  41. package/native/screenshot/win32-x64/libssl-1_1-x64.dll +0 -0
  42. package/native/screenshot/win32-x64/msvcp140.dll +0 -0
  43. package/native/screenshot/win32-x64/platforms/qwindows.dll +0 -0
  44. package/native/screenshot/win32-x64/qwindowsvistastyle.dll +0 -0
  45. package/native/screenshot/win32-x64/screenhelper.exe +0 -0
  46. package/native/screenshot/win32-x64/screentool.dll +0 -0
  47. package/native/screenshot/win32-x64/vcruntime140.dll +0 -0
  48. package/native/screenshot/win32-x64/vcruntime140_1.dll +0 -0
  49. package/package.json +5 -3
  50. package/src/asr/auth.mjs +9 -8
  51. package/src/asr/config.mjs +1 -1
  52. package/src/asr/stream.mjs +25 -24
  53. package/src/desktop/presentation.mjs +31 -11
  54. package/src/desktop/screenshot-worker.mjs +226 -0
  55. package/src/desktop/screenshot.mjs +186 -0
  56. package/src/devices/actions.mjs +7 -6
  57. package/src/devices/config.mjs +2 -1
  58. package/src/devices/diagnostics.mjs +4 -3
  59. package/src/devices/manager.mjs +72 -37
  60. package/src/devices/native-worker.mjs +4 -3
  61. package/src/devices/native.mjs +9 -8
  62. package/src/devices/queue.mjs +4 -3
  63. package/src/devices/recognition.mjs +5 -4
  64. package/src/devices/store.mjs +3 -2
  65. package/src/devices/translate.mjs +11 -10
  66. package/src/host/ai-conversation.mjs +8 -7
  67. package/src/host/index.mjs +12 -3
  68. package/src/host/locale.mjs +42 -0
  69. package/src/shared/devices.mjs +13 -12
  70. package/src/shared/i18n.mjs +47 -0
  71. package/src/shared/locales/de.json +155 -0
  72. package/src/shared/locales/en.json +155 -0
  73. package/src/shared/locales/es.json +155 -0
  74. package/src/shared/locales/fr.json +155 -0
  75. package/src/shared/locales/ja.json +155 -0
  76. package/src/shared/locales/pt.json +155 -0
  77. package/src/shared/locales/ru.json +155 -0
  78. package/src/shared/locales/zh.json +155 -0
  79. package/src/shared/remote.mjs +7 -1
@@ -82,11 +82,11 @@ namespace Sonicloud {
82
82
  public int Abort() { return context == IntPtr.Zero ? Typer.ErrNotSupported : Typer.typer_session_abort(context); }
83
83
  public static string ErrorText(int code) {
84
84
  switch (code) {
85
- case Typer.ErrInvalidArg: return "文本包含不支持的字符";
86
- case Typer.ErrAccessDenied: return "目标窗口拒绝模拟输入";
87
- case Typer.ErrWrongState: return "打字会话已中断";
88
- case Typer.ErrQueueFull: return "打字任务过多,请稍候";
89
- default: return "打字失败(代码 " + code + ")";
85
+ case Typer.ErrInvalidArg: return "panel.invalidText";
86
+ case Typer.ErrAccessDenied: return "panel.denied";
87
+ case Typer.ErrWrongState: return "panel.interrupted";
88
+ case Typer.ErrQueueFull: return "panel.queueFull";
89
+ default: return VoiceLocale.Encode("panel.typingError", "code", code);
90
90
  }
91
91
  }
92
92
  static byte[] Bytes(string text) {
@@ -110,7 +110,7 @@ namespace Sonicloud {
110
110
  public SingleLineText() { SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); }
111
111
  protected override void OnPaint(PaintEventArgs e) {
112
112
  TextRenderer.DrawText(e.Graphics, Text, Font, ClientRectangle, ForeColor,
113
- TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.NoPadding);
113
+ TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPrefix | TextFormatFlags.NoPadding);
114
114
  }
115
115
  protected override void OnTextChanged(EventArgs e) { base.OnTextChanged(e); Invalidate(); }
116
116
  }
@@ -127,13 +127,37 @@ namespace Sonicloud {
127
127
  }
128
128
  }
129
129
  }
130
+ static class VoiceLocale {
131
+ public static Dictionary<string, object> Dictionary = new Dictionary<string, object>();
132
+ static readonly JavaScriptSerializer Json = new JavaScriptSerializer { MaxJsonLength = 300000 };
133
+ public static string Encode(string key, string name, object value) {
134
+ return "sonicloud:" + Json.Serialize(new Dictionary<string, object> { { "key", key }, { "params", new Dictionary<string, object> { { name, value } } } });
135
+ }
136
+ public static string Text(string value, int depth = 0) {
137
+ if (String.IsNullOrEmpty(value)) return "";
138
+ object translated;
139
+ if (Dictionary.TryGetValue(value, out translated)) return Convert.ToString(translated);
140
+ if (depth < 5 && value.StartsWith("sonicloud:", StringComparison.Ordinal)) {
141
+ try {
142
+ var data = Json.Deserialize<Dictionary<string, object>>(value.Substring(10));
143
+ string result = Text(Convert.ToString(data["key"]), depth + 1);
144
+ foreach (var item in (Dictionary<string, object>)data["params"]) {
145
+ string raw = Convert.ToString(item.Value);
146
+ result = result.Replace("{" + item.Key + "}", raw.StartsWith("sonicloud:", StringComparison.Ordinal) || Dictionary.ContainsKey(raw) ? Text(raw, depth + 1) : raw);
147
+ }
148
+ return result;
149
+ } catch { }
150
+ }
151
+ return Dictionary.TryGetValue("error.generic", out translated) ? Convert.ToString(translated) : "Operation failed. Please retry.";
152
+ }
153
+ }
130
154
  public sealed class VoicePanel : Form {
131
155
  readonly SingleLineText text = new SingleLineText();
132
156
  readonly Waveform waveform = new Waveform();
133
157
  readonly Button close = new Button(), copy = new Button(), submit = new Button();
134
158
  readonly JavaScriptSerializer json = new JavaScriptSerializer { MaxJsonLength = 300000 };
135
159
  readonly System.Windows.Forms.Timer pulse = new System.Windows.Forms.Timer { Interval = 40 };
136
- string session = "", preview = "", phase = "", message = "";
160
+ string session = "", preview = "", phase = "", message = "", copyKey = "panel.copy";
137
161
  bool active;
138
162
  TyperEngine typer;
139
163
  bool sessionTyping; // typer 会话已 begin 且未 end/abort
@@ -155,8 +179,8 @@ namespace Sonicloud {
155
179
  VoicePanel() {
156
180
  FormBorderStyle = FormBorderStyle.None; ShowInTaskbar = false; TopMost = true;
157
181
  BackColor = Color.White; Font = new Font("Microsoft YaHei UI", 10);
158
- AccessibleName = "声云语音";
159
- text.AccessibleName = "语音识别结果";
182
+ AccessibleName = "Sonicloud Voice";
183
+ text.AccessibleName = "Speech recognition result";
160
184
  close.Text = ""; close.FlatStyle = FlatStyle.Flat; close.FlatAppearance.BorderSize = 0;
161
185
  var icon = new Bitmap(16, 16);
162
186
  using (var graphics = Graphics.FromImage(icon))
@@ -165,16 +189,16 @@ namespace Sonicloud {
165
189
  pen.StartCap = pen.EndCap = LineCap.Round;
166
190
  graphics.DrawLine(pen, 3, 3, 12, 12); graphics.DrawLine(pen, 12, 3, 3, 12);
167
191
  }
168
- close.Image = icon; close.AccessibleName = "取消";
169
- copy.Text = "复制结果";
170
- submit.Text = "一键提交"; submit.AccessibleName = "一键提交";
192
+ close.Image = icon; close.AccessibleName = "Cancel";
193
+ copyKey = "panel.copy";
194
+ submit.Text = "Insert text"; submit.AccessibleName = "Insert text";
171
195
  Controls.AddRange(new Control[] { text, waveform, close, copy, submit });
172
196
  close.Click += delegate {
173
197
  if (active) Emit(new Dictionary<string, object> { { "event", "cancel" }, { "sessionId", session } });
174
198
  EndSession(); preview = message = ""; pendingSubmit = false; Hide();
175
199
  };
176
200
  submit.Click += delegate { SubmitPending(); };
177
- copy.Click += delegate { try { Clipboard.SetText(preview); copy.Text = "已复制"; } catch { copy.Text = "复制失败"; } };
201
+ copy.Click += delegate { try { Clipboard.SetText(preview); copyKey = "panel.copied"; Render(); } catch { copyKey = "panel.copyFailed"; Render(); } };
178
202
  pulse.Tick += delegate { waveform.Phase += 0.25; waveform.Invalidate(); };
179
203
  VisibleChanged += delegate { pulse.Enabled = Visible && active; };
180
204
  Microsoft.Win32.SystemEvents.DisplaySettingsChanged += DisplayChanged;
@@ -183,24 +207,31 @@ namespace Sonicloud {
183
207
  }
184
208
  void DisplayChanged(object sender, EventArgs e) { if (!IsDisposed && Visible) BeginInvoke((Action)Render); }
185
209
  void Render() {
210
+ AccessibleName = VoiceLocale.Text("panel.title"); text.AccessibleName = VoiceLocale.Text("panel.result");
211
+ waveform.AccessibleName = VoiceLocale.Text("panel.processing");
212
+ copy.Text = VoiceLocale.Text(copyKey); submit.Text = VoiceLocale.Text("panel.submit"); submit.AccessibleName = submit.Text;
186
213
  var display = Screen.AllScreens.FirstOrDefault(s => screen != null && s.DeviceName == screen.DeviceName) ?? Screen.PrimaryScreen;
187
- var area = display.WorkingArea; var width = Math.Min(720, area.Width - 48); var height = 48;
214
+ var area = display.WorkingArea; var width = Math.Min(720, area.Width - 48);
215
+ int buttonWidth = Math.Max(96, Math.Max(TextRenderer.MeasureText(copy.Text, Font).Width, TextRenderer.MeasureText(submit.Text, Font).Width) + 20);
216
+ buttonWidth = Math.Min(buttonWidth, width / 3);
217
+ string status = message.Length > 0 ? VoiceLocale.Text(message) : VoiceLocale.Text(phase == "finishing" ? "panel.finishing" : phase == "translating" ? "panel.translating" : "");
218
+ string displayText = (status + " " + preview).Trim();
219
+ int textWidth = Math.Max(100, width - 116 - (pendingSubmit ? 2 * buttonWidth + 8 : !active && preview.Length > 0 ? buttonWidth : 0));
220
+ int height = Math.Min(area.Height / 2, Math.Max(48, TextRenderer.MeasureText(displayText, Font, new Size(textWidth, Int32.MaxValue), TextFormatFlags.WordBreak).Height + 24));
188
221
  Bounds = new Rectangle(area.Left + (area.Width - width) / 2, area.Bottom - height - 24, width, height);
189
- using (var outline = CapsuleShape.Create(new RectangleF(0, 0, width, height), height / 2f)) {
222
+ using (var outline = CapsuleShape.Create(new RectangleF(0, 0, width, height), 24)) {
190
223
  var previous = Region; Region = new Region(outline); if (previous != null) previous.Dispose();
191
224
  }
192
225
  waveform.SetBounds(20, (height - 26) / 2, 23, 26);
193
226
  close.SetBounds(width - 44, (height - 28) / 2, 28, 28);
194
227
  if (pendingSubmit) {
195
- submit.SetBounds(width - 148, (height - 32) / 2, 96, 32);
196
- copy.SetBounds(width - 252, (height - 32) / 2, 96, 32);
197
- } else copy.SetBounds(width - 146, (height - 32) / 2, 96, 32);
228
+ submit.SetBounds(width - 52 - buttonWidth, (height - 32) / 2, buttonWidth, 32);
229
+ copy.SetBounds(width - 60 - 2 * buttonWidth, (height - 32) / 2, buttonWidth, 32);
230
+ } else copy.SetBounds(width - 52 - buttonWidth, (height - 32) / 2, buttonWidth, 32);
198
231
  waveform.Visible = active; submit.Visible = pendingSubmit;
199
- copy.Visible = !active && preview.Length > 0; close.AccessibleName = active ? "取消" : "关闭";
232
+ copy.Visible = !active && preview.Length > 0; close.AccessibleName = VoiceLocale.Text(active ? "panel.cancel" : "panel.close");
200
233
  int left = active ? 54 : 22, right = copy.Visible ? copy.Left : close.Left;
201
- text.SetBounds(left, 0, Math.Max(0, right - left - 12), height);
202
- string status = message.Length > 0 ? message : phase == "finishing" ? "正在整理…" : phase == "translating" ? "正在翻译…" : "";
203
- string displayText = (status + " " + preview).Trim();
234
+ text.SetBounds(left, 12, Math.Max(0, right - left - 12), height - 24);
204
235
  text.Text = Regex.Replace(displayText, @"[\r\n\t\u0085\u2028\u2029]+", " ");
205
236
  pulse.Enabled = Visible && active;
206
237
  Show();
@@ -218,7 +249,7 @@ namespace Sonicloud {
218
249
  }
219
250
  void HandleTypingError(int code) {
220
251
  typingError = true; typingErrorCode = code;
221
- message = "未回填:" + TyperEngine.ErrorText(code) + ",可复制结果";
252
+ message = VoiceLocale.Encode("panel.notInserted", "reason", TyperEngine.ErrorText(code));
222
253
  Render();
223
254
  }
224
255
  // 一键提交:把保留的文本一次性逐字注入点击时聚焦的窗口(浮窗不抢焦点,焦点仍在用户摆好的目标上)。
@@ -226,8 +257,8 @@ namespace Sonicloud {
226
257
  if (!pendingSubmit) return;
227
258
  pendingSubmit = false;
228
259
  string reason = null;
229
- if (typer == null || typer.context == IntPtr.Zero) reason = "打字组件不可用";
230
- else if (FocusedElementIsPassword()) reason = "目标为密码输入框";
260
+ if (typer == null || typer.context == IntPtr.Zero) reason = "panel.typingUnavailable";
261
+ else if (FocusedElementIsPassword()) reason = "panel.password";
231
262
  else {
232
263
  int rc = typer.Begin(Typer.ModePerChar);
233
264
  if (rc != 0) reason = TyperEngine.ErrorText(rc);
@@ -239,25 +270,31 @@ namespace Sonicloud {
239
270
  }
240
271
  }
241
272
  if (reason == null) { preview = message = ""; Hide(); }
242
- else { message = "未回填:" + reason + ",可复制结果"; Render(); }
273
+ else { message = VoiceLocale.Encode("panel.notInserted", "reason", reason); Render(); }
243
274
  }
244
275
  void HandleCommand(Dictionary<string, object> item) {
245
276
  string command = Get(item, "command"), incoming = Get(item, "sessionId"); bool ok = true, inserted = false;
277
+ if (command == "locale") {
278
+ object dictionary;
279
+ if (item.TryGetValue("dictionary", out dictionary) && dictionary is Dictionary<string, object>) VoiceLocale.Dictionary = (Dictionary<string, object>)dictionary;
280
+ if (Visible) Render();
281
+ return;
282
+ }
246
283
  if (command == "begin") {
247
284
  session = incoming; preview = message = ""; phase = "connecting"; active = true;
248
285
  string action = Get(item, "action");
249
286
  typingBlocked = false; typingError = false; sessionTyping = false; typingLive = false; pendingSubmit = false;
250
287
  if (action == "voice_input" || action == "translate") {
251
288
  typingLive = action == "voice_input"; // 翻译只在最终译文出来后打字,避免先打原文再整段退格
252
- if (typer == null || typer.context == IntPtr.Zero) { typingBlocked = true; blockedReason = "打字组件不可用"; }
253
- else if (FocusedElementIsPassword()) { typingBlocked = true; blockedReason = "目标为密码输入框"; }
289
+ if (typer == null || typer.context == IntPtr.Zero) { typingBlocked = true; blockedReason = "panel.typingUnavailable"; }
290
+ else if (FocusedElementIsPassword()) { typingBlocked = true; blockedReason = "panel.password"; }
254
291
  else {
255
292
  int rc = typer.Begin(Typer.ModePerChar);
256
293
  if (rc == 0) sessionTyping = true;
257
294
  else { typingBlocked = true; blockedReason = TyperEngine.ErrorText(rc); }
258
295
  }
259
296
  }
260
- screen = Screen.FromPoint(Cursor.Position); copy.Text = "复制结果"; Render();
297
+ screen = Screen.FromPoint(Cursor.Position); copyKey = "panel.copy"; Render();
261
298
  } else if (incoming.Length > 0 && incoming != session) { ok = false; }
262
299
  else if (command == "result" && active) {
263
300
  preview = Get(item, "text");
@@ -271,7 +308,7 @@ namespace Sonicloud {
271
308
  }
272
309
  EndSession();
273
310
  if (reason == null) { inserted = true; Hide(); }
274
- else { message = "未回填:" + reason + ",可复制结果"; Render(); }
311
+ else { message = VoiceLocale.Encode("panel.notInserted", "reason", reason); Render(); }
275
312
  } else if (command == "event") {
276
313
  switch (Get(item, "type")) {
277
314
  case "preview":
@@ -290,9 +327,9 @@ namespace Sonicloud {
290
327
  EndSession();
291
328
  typingError = false; // 清闩,本次提交允许重新注入
292
329
  pendingSubmit = preview.Length > 0;
293
- message = pendingSubmit ? Get(item, "message") : "没有可输入的内容";
294
- if (message.Length == 0) message = "请打开需要输入界面";
295
- copy.Text = "复制结果"; Render();
330
+ message = pendingSubmit ? Get(item, "message") : "panel.noText";
331
+ if (message.Length == 0) message = "panel.openInput";
332
+ copyKey = "panel.copy"; Render();
296
333
  break;
297
334
  case "cancelled": case "finished":
298
335
  // 空结果收尾(无 result):实时打出的中间结果用空 partial 修正掉,再结束会话。
@@ -141,7 +141,7 @@ final class WaveformView: NSView {
141
141
  override init(frame frameRect: NSRect) {
142
142
  super.init(frame: frameRect)
143
143
  wantsLayer = true
144
- setAccessibilityElement(true); setAccessibilityLabel("语音处理中")
144
+ setAccessibilityElement(true); setAccessibilityLabel("Processing speech")
145
145
  for bar in bars { bar.backgroundColor = NSColor.systemGreen.cgColor; bar.cornerRadius = 1.5; layer?.addSublayer(bar) }
146
146
  }
147
147
  required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
@@ -176,13 +176,37 @@ final class Panel: NSPanel {
176
176
  override var canBecomeKey: Bool { false }
177
177
  override var canBecomeMain: Bool { false }
178
178
  }
179
+ // 文案由插件通过私有 IPC 下发;结果文本始终原样显示。
180
+ final class VoiceLocale {
181
+ static var dictionary: [String: String] = [:]
182
+ static func encode(_ key: String, _ params: [String: Any] = [:]) -> String {
183
+ let data = try! JSONSerialization.data(withJSONObject: ["key": key, "params": params], options: [.sortedKeys])
184
+ return "sonicloud:" + String(data: data, encoding: .utf8)!
185
+ }
186
+ static func text(_ value: String, _ depth: Int = 0) -> String {
187
+ if value.isEmpty { return "" }
188
+ if let text = dictionary[value] { return text }
189
+ if depth < 5 && value.hasPrefix("sonicloud:"), let data = String(value.dropFirst(10)).data(using: .utf8),
190
+ let object = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any], let key = object["key"] as? String {
191
+ var result = dictionary[key] ?? dictionary["error.generic"] ?? "Operation failed. Please retry."
192
+ for (name, param) in object["params"] as? [String: Any] ?? [:] {
193
+ let raw = String(describing: param)
194
+ let translated = raw.hasPrefix("sonicloud:") || dictionary[raw] != nil ? text(raw, depth + 1) : raw
195
+ result = result.replacingOccurrences(of: "{" + name + "}", with: translated)
196
+ }
197
+ return result
198
+ }
199
+ return dictionary["error.generic"] ?? "Operation failed. Please retry."
200
+ }
201
+ }
179
202
  final class VoiceUI: NSObject {
180
203
  let panel = Panel(contentRect: .zero, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
181
204
  let text = NSTextField(labelWithString: "")
182
205
  let waveform = WaveformView(frame: .zero)
183
206
  let closeButton = NSButton(title: "", target: nil, action: nil)
184
- let copyButton = NSButton(title: "复制结果", target: nil, action: nil)
207
+ let copyButton = NSButton(title: "Copy result", target: nil, action: nil)
185
208
  var session = "", preview = "", phase = "connecting", message = ""
209
+ var copyKey = "panel.copy"
186
210
  var active = false
187
211
  var insertion: ClipboardInsertion?
188
212
  var resultPending = false
@@ -200,14 +224,14 @@ final class VoiceUI: NSObject {
200
224
  let content = CapsuleView()
201
225
  panel.contentView = content
202
226
  text.font = .systemFont(ofSize: 15)
203
- text.lineBreakMode = .byTruncatingHead
204
- text.maximumNumberOfLines = 1
205
- text.cell?.usesSingleLineMode = true
206
- text.cell?.wraps = false
227
+ text.lineBreakMode = .byWordWrapping
228
+ text.maximumNumberOfLines = 0
229
+ text.cell?.usesSingleLineMode = false
230
+ text.cell?.wraps = true
207
231
  text.cell?.isScrollable = false
208
- text.setAccessibilityLabel("语音识别结果")
232
+ text.setAccessibilityLabel("Speech recognition result")
209
233
  for view in [waveform, text, closeButton, copyButton] { content.addSubview(view) }
210
- closeButton.image = NSImage(systemSymbolName: "xmark", accessibilityDescription: "取消")?.withSymbolConfiguration(NSImage.SymbolConfiguration(pointSize: 14, weight: .medium))
234
+ closeButton.image = NSImage(systemSymbolName: "xmark", accessibilityDescription: "Cancel")?.withSymbolConfiguration(NSImage.SymbolConfiguration(pointSize: 14, weight: .medium))
211
235
  closeButton.imagePosition = .imageOnly
212
236
  closeButton.isBordered = false
213
237
  closeButton.contentTintColor = .secondaryLabelColor
@@ -219,14 +243,18 @@ final class VoiceUI: NSObject {
219
243
  func position() {
220
244
  let display = NSScreen.screens.first(where: { $0 == screen }) ?? NSScreen.main ?? NSScreen.screens.first
221
245
  guard let frame = display?.visibleFrame else { return }
222
- let width = min(720, max(280, frame.width - 48)), height: CGFloat = 48
246
+ let width = min(720, max(280, frame.width - 48))
247
+ let copyWidth = min(width / 2, max(96, copyButton.intrinsicContentSize.width + 16))
248
+ let available = max(100, width - (copyButton.isHidden ? 110 : copyWidth + 116))
249
+ let bounds = (text.stringValue as NSString).boundingRect(with: NSSize(width: available, height: .greatestFiniteMagnitude), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font: text.font!])
250
+ let height: CGFloat = min(frame.height / 2, max(48, ceil(bounds.height) + 24))
223
251
  panel.setFrame(NSRect(x: frame.midX - width / 2, y: frame.minY + 24, width: width, height: height), display: true)
224
252
  waveform.frame = NSRect(x: 20, y: (height - 26) / 2, width: 23, height: 26)
225
253
  closeButton.frame = NSRect(x: width - 44, y: (height - 28) / 2, width: 28, height: 28)
226
- copyButton.frame = NSRect(x: width - 146, y: (height - 32) / 2, width: 96, height: 32)
254
+ copyButton.frame = NSRect(x: width - 50 - copyWidth, y: (height - 32) / 2, width: copyWidth, height: 32)
227
255
  let left: CGFloat = active ? 54 : 22
228
256
  let right = copyButton.isHidden ? closeButton.frame.minX : copyButton.frame.minX
229
- let textHeight = ceil(text.intrinsicContentSize.height)
257
+ let textHeight = height - 24
230
258
  text.frame = NSRect(x: left, y: (height - textHeight) / 2, width: max(0, right - left - 12), height: textHeight)
231
259
  panel.contentView?.needsDisplay = true
232
260
  panel.invalidateShadow()
@@ -234,10 +262,14 @@ final class VoiceUI: NSObject {
234
262
  func render() {
235
263
  waveform.isHidden = !active
236
264
  waveform.animate(active)
237
- closeButton.setAccessibilityLabel(active ? "取消" : "关闭")
238
- closeButton.toolTip = active ? "取消" : "关闭"
265
+ panel.setAccessibilityLabel(VoiceLocale.text("panel.title"))
266
+ text.setAccessibilityLabel(VoiceLocale.text("panel.result"))
267
+ waveform.setAccessibilityLabel(VoiceLocale.text("panel.processing"))
268
+ copyButton.title = VoiceLocale.text(copyKey)
269
+ closeButton.setAccessibilityLabel(VoiceLocale.text(active ? "panel.cancel" : "panel.close"))
270
+ closeButton.toolTip = VoiceLocale.text(active ? "panel.cancel" : "panel.close")
239
271
  copyButton.isHidden = active || preview.isEmpty
240
- let status = message.isEmpty ? (["finishing": "正在整理…", "translating": "正在翻译…"][phase] ?? "") : message
272
+ let status = message.isEmpty ? VoiceLocale.text(["finishing": "panel.finishing", "translating": "panel.translating"][phase] ?? "") : VoiceLocale.text(message)
241
273
  let fullText = [status, preview].filter { !$0.isEmpty }.joined(separator: " ")
242
274
  text.stringValue = fullText.components(separatedBy: .newlines).joined(separator: " ").replacingOccurrences(of: "\t", with: " ")
243
275
  text.toolTip = fullText
@@ -251,14 +283,14 @@ final class VoiceUI: NSObject {
251
283
  @objc func copyResult() {
252
284
  NSPasteboard.general.clearContents()
253
285
  NSPasteboard.general.setString(preview, forType: .string)
254
- copyButton.title = "已复制"
286
+ copyKey = "panel.copied"; render()
255
287
  }
256
288
  func finishInsertion(_ inserted: Bool, changed: Bool) {
257
289
  insertion = nil; active = false; resultPending = false
258
290
  if inserted { preview = ""; message = ""; hide() }
259
291
  else {
260
- message = !AXIsProcessTrusted() ? "请授权辅助功能以回填;可复制结果"
261
- : changed ? "输入目标已变化或不支持写入,可复制结果" : "此输入框不支持自动回填,可复制结果"
292
+ message = !AXIsProcessTrusted() ? "panel.permission"
293
+ : changed ? "panel.targetChanged" : "panel.targetChanged"
262
294
  render()
263
295
  }
264
296
  }
@@ -268,6 +300,38 @@ final class VoiceUI: NSObject {
268
300
  }
269
301
  func handle(_ command: [String: Any]) {
270
302
  let name = command["command"] as? String ?? ""
303
+ if name == "locale" {
304
+ if let dictionary = command["dictionary"] as? [String: String] { VoiceLocale.dictionary = dictionary }
305
+ if panel.isVisible { render() }
306
+ return
307
+ }
308
+ if name == "permissions" {
309
+ let action = command["action"] as? String ?? "check"
310
+ guard ["check", "refresh", "accessibility"].contains(action) else {
311
+ if let id = command["id"] { emit(["id": id, "ok": false, "message": VoiceLocale.encode("error.permission")]) }
312
+ return
313
+ }
314
+ if action == "accessibility" {
315
+ guard !active && !resultPending else {
316
+ if let id = command["id"] { emit(["id": id, "ok": false, "message": VoiceLocale.encode("error.busy")]) }
317
+ return
318
+ }
319
+ if !AXIsProcessTrusted() {
320
+ hide()
321
+ let options = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: true] as CFDictionary
322
+ _ = AXIsProcessTrustedWithOptions(options)
323
+ if let settings = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility") {
324
+ NSWorkspace.shared.open(settings)
325
+ }
326
+ }
327
+ }
328
+ let helperApp = Bundle.main.bundlePath.hasSuffix(".app") ? Bundle.main.bundlePath
329
+ : URL(fileURLWithPath: CommandLine.arguments[0]).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path
330
+ if let id = command["id"] {
331
+ emit(["id": id, "ok": true, "value": ["supported": true, "accessibility": AXIsProcessTrusted(), "helperApp": helperApp]])
332
+ }
333
+ return
334
+ }
271
335
  let incoming = command["sessionId"] as? String ?? ""
272
336
  var success = true
273
337
  let inserted = false
@@ -276,7 +340,7 @@ final class VoiceUI: NSObject {
276
340
  screen = NSScreen.screens.first(where: { NSMouseInRect(NSEvent.mouseLocation, $0.frame, false) })
277
341
  insertion = ["speechSearch", "ai_input"].contains(command["action"] as? String ?? "") ? nil : ClipboardInsertion()
278
342
  resultPending = false
279
- copyButton.title = "复制结果"; render()
343
+ copyKey = "panel.copy"; render()
280
344
  } else if !incoming.isEmpty && incoming != session { success = false }
281
345
  else if name == "result" && active && !resultPending {
282
346
  preview = command["text"] as? String ?? ""
@@ -295,7 +359,7 @@ final class VoiceUI: NSObject {
295
359
  switch command["type"] as? String {
296
360
  case "preview": if active { preview = command["text"] as? String ?? ""; render() }
297
361
  case "phase": if active { phase = command["phase"] as? String ?? phase; render() }
298
- case "failed": active = false; insertion = nil; message = command["message"] as? String ?? "语音处理失败"; render()
362
+ case "failed": active = false; insertion = nil; message = command["message"] as? String ?? "error.generic"; render()
299
363
  case "notice": message = command["message"] as? String ?? ""; render()
300
364
  case "finished", "cancelled": active = false; insertion = nil; preview = ""; message = ""; hide()
301
365
  default: break
@@ -0,0 +1,115 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>files</key>
6
+ <dict/>
7
+ <key>files2</key>
8
+ <dict/>
9
+ <key>rules</key>
10
+ <dict>
11
+ <key>^Resources/</key>
12
+ <true/>
13
+ <key>^Resources/.*\.lproj/</key>
14
+ <dict>
15
+ <key>optional</key>
16
+ <true/>
17
+ <key>weight</key>
18
+ <real>1000</real>
19
+ </dict>
20
+ <key>^Resources/.*\.lproj/locversion.plist$</key>
21
+ <dict>
22
+ <key>omit</key>
23
+ <true/>
24
+ <key>weight</key>
25
+ <real>1100</real>
26
+ </dict>
27
+ <key>^Resources/Base\.lproj/</key>
28
+ <dict>
29
+ <key>weight</key>
30
+ <real>1010</real>
31
+ </dict>
32
+ <key>^version.plist$</key>
33
+ <true/>
34
+ </dict>
35
+ <key>rules2</key>
36
+ <dict>
37
+ <key>.*\.dSYM($|/)</key>
38
+ <dict>
39
+ <key>weight</key>
40
+ <real>11</real>
41
+ </dict>
42
+ <key>^(.*/)?\.DS_Store$</key>
43
+ <dict>
44
+ <key>omit</key>
45
+ <true/>
46
+ <key>weight</key>
47
+ <real>2000</real>
48
+ </dict>
49
+ <key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
50
+ <dict>
51
+ <key>nested</key>
52
+ <true/>
53
+ <key>weight</key>
54
+ <real>10</real>
55
+ </dict>
56
+ <key>^.*</key>
57
+ <true/>
58
+ <key>^Info\.plist$</key>
59
+ <dict>
60
+ <key>omit</key>
61
+ <true/>
62
+ <key>weight</key>
63
+ <real>20</real>
64
+ </dict>
65
+ <key>^PkgInfo$</key>
66
+ <dict>
67
+ <key>omit</key>
68
+ <true/>
69
+ <key>weight</key>
70
+ <real>20</real>
71
+ </dict>
72
+ <key>^Resources/</key>
73
+ <dict>
74
+ <key>weight</key>
75
+ <real>20</real>
76
+ </dict>
77
+ <key>^Resources/.*\.lproj/</key>
78
+ <dict>
79
+ <key>optional</key>
80
+ <true/>
81
+ <key>weight</key>
82
+ <real>1000</real>
83
+ </dict>
84
+ <key>^Resources/.*\.lproj/locversion.plist$</key>
85
+ <dict>
86
+ <key>omit</key>
87
+ <true/>
88
+ <key>weight</key>
89
+ <real>1100</real>
90
+ </dict>
91
+ <key>^Resources/Base\.lproj/</key>
92
+ <dict>
93
+ <key>weight</key>
94
+ <real>1010</real>
95
+ </dict>
96
+ <key>^[^/]+$</key>
97
+ <dict>
98
+ <key>nested</key>
99
+ <true/>
100
+ <key>weight</key>
101
+ <real>10</real>
102
+ </dict>
103
+ <key>^embedded\.provisionprofile$</key>
104
+ <dict>
105
+ <key>weight</key>
106
+ <real>20</real>
107
+ </dict>
108
+ <key>^version\.plist$</key>
109
+ <dict>
110
+ <key>weight</key>
111
+ <real>20</real>
112
+ </dict>
113
+ </dict>
114
+ </dict>
115
+ </plist>
@@ -0,0 +1,34 @@
1
+ # 截图运行组件
2
+
3
+ 随插件提供 ScreenTool 1.2.2 的 Windows x64、macOS ARM64 客户端与独立 helper。两端 helper 均应用 [入口显隐补丁](patches/hide-cloud-actions.patch) 后重建;macOS 另叠加[权限前检补丁](patches/mac-permissions.patch)。来源与文件 SHA-256 见 [SOURCE.json](SOURCE.json)。
4
+
5
+ - Windows:使用 Qt 5.15.2 重建 helper,保留原包的 Qt、图像格式、TLS、滚动截图与 VC 运行依赖;客户端 `screentool.dll` 来自同套 Electron 示例的 `lib/`。
6
+ - macOS:使用 Qt 6.2.4 重建 ARM64 helper,复用原包客户端、框架、PixPin 和 `Info.plist`,以原 Team `F3TYM6YPF7` 的 Developer ID 签名并通过 `codesign --verify --deep --strict`。本次未执行 Apple 公证。交付包要求 macOS 26.0+,该最低版本来自保留的客户端库。
7
+ - macOS 权限检查或截图前通过系统 `ditto` 将 `screentool-macos-1.2.2.zip` 解压到按压缩包 SHA-256 区分的用户缓存,保留签名、软链接与执行权限;新包使用新的缓存目录。
8
+ - 截图在独立进程执行,插件通过隔离的 Node worker 调用客户端库。停用插件时关闭 helper 及贴图,并等待原生回调线程退出。
9
+ - 选区、标注、复制、保存、贴图及滚动截图由 helper 提供。OCR、图像翻译与 Word 云转换未接入;界面效果与完整操作由用户人工验收。
10
+
11
+ ## 两端入口隐藏机制
12
+
13
+ 截图 worker 每次连接 helper 后先通过 `sct_set_config` 下发 `ocr_visible: false`、`trans_enabled: false`,配置成功后再发起截图。两端使用相同补丁:
14
+
15
+ - `trans_enabled: false` 使 Qt 工具条隐藏图片翻译按钮。
16
+ - `ocr_visible: false` 隐藏普通 OCR,并在每次滚动截图开始前移除自定义 OCR 动作;该动作原本用于启动 Word 导出。`onConvertImage` 同时检查此开关,阻止旧动作启动转换。
17
+ - 工具条宽度随隐藏按钮收缩;滚动截图按钮、PixPin 拼接以及复制、保存、贴图操作保留。
18
+
19
+ ## macOS 权限前检
20
+
21
+ 安装后的首次启用和服务重连会查询权限,在“声云设备”中显示持久引导;检查本身不申请系统权限、不创建截图蒙层。各组件所需权限与人工操作见[用户指南](../../README.zh.md#macos-首次授权)。
22
+
23
+ - helper 宣告 `permission_preflight` 能力,通过 `sct_query_state` 返回屏幕录制、辅助功能和组件路径。只有用户点击授权按钮后,宿主才以 `sct_set_config` 的 `permission_request` 字段请求 `screen` 或 `accessibility`,由 screenhelper 调用系统接口;请求受理不等于已授权。
24
+ - 宿主在发送截图命令前检查屏幕录制权限;原生进程也在创建选区、抓屏和显示蒙层前再次检查。缺权限时回报状态并结束截图会话,不显示蒙层,也避免触发客户端会话启动看门狗。
25
+ - 普通截图和手动滚动不要求辅助功能。重新检查时,仅在无活动截图或贴图的情况下重启截图 helper,以重新读取系统权限;不打断已有截图和贴图。
26
+
27
+ ## 重建
28
+
29
+ - Windows:`node scripts/native/build-screenshot.mjs --source <ScreenTool源码目录>`。
30
+ - macOS:`node scripts/native/build-screenshot-macos.mjs --source <ScreenTool源码目录>`;需要 Qt 6.2.4、构建工具及原 Team 的有效签名身份。
31
+
32
+ 脚本在插件 `work/` 中应用补丁、编译并运行原生离屏回归。macOS 脚本依次应用入口显隐与权限前检补丁,使用 `ditto` 复用并重新归档原 bundle,严格验签后生成新 ZIP 和构建回执;正式随包文件与来源记录由交付流程核对后更新。离屏回归与签名校验不代替首次授权、弹窗层级和完整截图操作的人工验收。
33
+
34
+ 这些供应商二进制及 Qt、OpenSSL、Microsoft VC Runtime、PixPinScrollCapture 等依赖保留各自许可,不适用仓库代码的 MIT 许可。原压缩包未提供单独的组件许可文件;公开再分发所需的完整声明与授权材料待供应商补齐。