@sonicloud/dsh-sonicloud-device 0.1.1 → 0.1.3
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.
- package/CHANGELOG.md +44 -0
- package/CHANGELOG.zh.md +44 -0
- package/README.md +81 -86
- package/README.zh.md +135 -0
- package/dist/build.json +1 -1
- package/dist/client.js +202 -28
- package/docs/contributing/development.md +51 -28
- package/docs/images/plugin-install.png +0 -0
- package/docs/images/sonicloud-device.png +0 -0
- package/docs/specs/ci-cd.md +24 -37
- package/docs/specs/mouse-settings.md +7 -34
- package/docs/specs/smart-mouse-plugin.md +51 -32
- package/native/README.md +4 -0
- package/native/desktop/VOICE_SOURCE.json +16 -0
- package/native/desktop/VoicePanel.cs +191 -59
- package/native/desktop/VoicePanel.swift +27 -0
- package/native/desktop/darwin-arm64/Sonicloud Voice.app/Contents/MacOS/sonicloud-voice +0 -0
- package/native/desktop/darwin-arm64/Sonicloud Voice.app/Contents/_CodeSignature/CodeResources +115 -0
- package/native/desktop/typer.dll +0 -0
- package/native/desktop/windows.ps1 +1 -1
- package/native/screenshot/README.md +34 -0
- package/native/screenshot/SOURCE.json +218 -0
- package/native/screenshot/darwin-arm64/screentool-macos-1.2.2.zip +0 -0
- package/native/screenshot/patches/hide-cloud-actions.patch +202 -0
- package/native/screenshot/patches/mac-permissions.patch +545 -0
- package/native/screenshot/patches/upstream-files.json +22 -0
- package/native/screenshot/win32-x64/PixPinScrollCapture.dll +0 -0
- package/native/screenshot/win32-x64/Qt5Core.dll +0 -0
- package/native/screenshot/win32-x64/Qt5Gui.dll +0 -0
- package/native/screenshot/win32-x64/Qt5Network.dll +0 -0
- package/native/screenshot/win32-x64/Qt5Svg.dll +0 -0
- package/native/screenshot/win32-x64/Qt5Widgets.dll +0 -0
- package/native/screenshot/win32-x64/iconengines/qsvgicon.dll +0 -0
- package/native/screenshot/win32-x64/imageformats/qjpeg.dll +0 -0
- package/native/screenshot/win32-x64/imageformats/qsvg.dll +0 -0
- package/native/screenshot/win32-x64/libcrypto-1_1-x64.dll +0 -0
- package/native/screenshot/win32-x64/libssl-1_1-x64.dll +0 -0
- package/native/screenshot/win32-x64/msvcp140.dll +0 -0
- package/native/screenshot/win32-x64/platforms/qwindows.dll +0 -0
- package/native/screenshot/win32-x64/qwindowsvistastyle.dll +0 -0
- package/native/screenshot/win32-x64/screenhelper.exe +0 -0
- package/native/screenshot/win32-x64/screentool.dll +0 -0
- package/native/screenshot/win32-x64/vcruntime140.dll +0 -0
- package/native/screenshot/win32-x64/vcruntime140_1.dll +0 -0
- package/package.json +2 -1
- package/src/desktop/presentation.mjs +18 -4
- package/src/desktop/screenshot-worker.mjs +225 -0
- package/src/desktop/screenshot.mjs +185 -0
- package/src/devices/actions.mjs +7 -1
- package/src/devices/manager.mjs +145 -81
- package/src/host/index.mjs +5 -1
- package/src/shared/remote.mjs +5 -0
- /package/{src/client/assets → docs/images}/contact-wechat.jpg +0 -0
|
@@ -2,58 +2,98 @@ using System;
|
|
|
2
2
|
using System.Collections.Generic;
|
|
3
3
|
using System.Drawing;
|
|
4
4
|
using System.Drawing.Drawing2D;
|
|
5
|
+
using System.Runtime.InteropServices;
|
|
6
|
+
using System.Text;
|
|
5
7
|
using System.Text.RegularExpressions;
|
|
6
8
|
using System.Linq;
|
|
7
9
|
using System.Threading;
|
|
8
10
|
using System.Windows.Automation;
|
|
9
|
-
using System.Windows.Automation.Text;
|
|
10
11
|
using System.Windows.Forms;
|
|
11
12
|
using System.Web.Script.Serialization;
|
|
12
13
|
|
|
13
14
|
namespace Sonicloud {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
int
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
public static Insertion Capture() {
|
|
35
|
-
try {
|
|
36
|
-
var target = AutomationElement.FocusedElement;
|
|
37
|
-
string value; int offset, count;
|
|
38
|
-
if (target == null || !Read(target, out value, out offset, out count)) return null;
|
|
39
|
-
return new Insertion { element = target, runtime = target.GetRuntimeId(), original = value, start = offset, length = count };
|
|
40
|
-
} catch { return null; }
|
|
15
|
+
// typer.dll 标准注入库(纯 C ABI):会话式逐字打字,实时退格更正,逐字模式不占用剪贴板。
|
|
16
|
+
static class Typer {
|
|
17
|
+
public const int ModePerChar = 0;
|
|
18
|
+
public const int ErrInvalidArg = -1, ErrNotSupported = -2, ErrAccessDenied = -4, ErrWrongState = -6, ErrQueueFull = -8;
|
|
19
|
+
public delegate void ErrorCallback(IntPtr user, int code);
|
|
20
|
+
// typer_config v1.1 布局(x64 自然对齐与 C 一致);drained_cb 不用,置空。
|
|
21
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
22
|
+
public struct Config {
|
|
23
|
+
public IntPtr size, drained_cb, drained_user;
|
|
24
|
+
public int xkb_bind_delay_ms, xkb_char_interval_ms, xdotool_char_delay_ms, xclip_settle_ms,
|
|
25
|
+
paste_settle_ms, ime_settle_ms, proc_timeout_ms, queue_limit;
|
|
26
|
+
public IntPtr error_cb, error_user;
|
|
27
|
+
}
|
|
28
|
+
// typer_caps 完整布局(含尾部 char ime_tool_path[260],探测要求 size 覆盖全结构)。
|
|
29
|
+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
|
30
|
+
public struct Caps {
|
|
31
|
+
public IntPtr size;
|
|
32
|
+
public int session_type, text_typing, increment_typing, whole_phrase_paste, ime_guard,
|
|
33
|
+
input_permitted, has_xdotool, has_xclip, has_fcitx_remote;
|
|
34
|
+
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string ime_tool_path;
|
|
41
35
|
}
|
|
42
|
-
|
|
36
|
+
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] static extern IntPtr LoadLibrary(string path);
|
|
37
|
+
[DllImport("typer.dll", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr typer_create(ref Config config);
|
|
38
|
+
[DllImport("typer.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void typer_destroy(IntPtr ctx);
|
|
39
|
+
[DllImport("typer.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int typer_session_begin(IntPtr ctx, int mode);
|
|
40
|
+
[DllImport("typer.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int typer_feed_partial(IntPtr ctx, byte[] utf8);
|
|
41
|
+
[DllImport("typer.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int typer_feed_final(IntPtr ctx, byte[] utf8);
|
|
42
|
+
[DllImport("typer.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int typer_session_end(IntPtr ctx);
|
|
43
|
+
[DllImport("typer.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int typer_session_abort(IntPtr ctx);
|
|
44
|
+
[DllImport("typer.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int typer_probe(ref Caps caps);
|
|
45
|
+
[DllImport("typer.dll", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr typer_version();
|
|
46
|
+
[DllImport("typer.dll", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr typer_strerror(int code);
|
|
47
|
+
public static bool loaded;
|
|
48
|
+
public static void Load(string directory) {
|
|
43
49
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
if (LoadLibrary(System.IO.Path.Combine(directory, "typer.dll")) == IntPtr.Zero) return;
|
|
51
|
+
StringAt(typer_version()); // 触发一次导出调用,确认模块与 ABI 可用
|
|
52
|
+
loaded = true;
|
|
53
|
+
} catch { loaded = false; }
|
|
54
|
+
}
|
|
55
|
+
public static string StringAt(IntPtr pointer) { return pointer == IntPtr.Zero ? "" : Marshal.PtrToStringAnsi(pointer); }
|
|
56
|
+
}
|
|
57
|
+
// 面板持有的 typer 会话封装;error 回调来自库内打字线程,只做投递,不在回调内再调 typer_*。
|
|
58
|
+
sealed class TyperEngine {
|
|
59
|
+
static Action<int> notify;
|
|
60
|
+
static readonly Typer.ErrorCallback errorCallback = OnNativeError;
|
|
61
|
+
static void OnNativeError(IntPtr user, int code) { Action<int> handler = notify; if (handler != null) handler(code); }
|
|
62
|
+
public IntPtr context;
|
|
63
|
+
public bool Open(Action<int> onError) {
|
|
64
|
+
if (!Typer.loaded) return false;
|
|
65
|
+
var config = new Typer.Config();
|
|
66
|
+
config.size = (IntPtr)Marshal.SizeOf(typeof(Typer.Config));
|
|
67
|
+
config.queue_limit = 1024; // 默认 256,长语音的中间结果可能更多
|
|
68
|
+
config.error_cb = Marshal.GetFunctionPointerForDelegate(errorCallback);
|
|
69
|
+
try { context = Typer.typer_create(ref config); } catch { context = IntPtr.Zero; }
|
|
70
|
+
if (context == IntPtr.Zero) return false;
|
|
71
|
+
notify = onError;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
public void Close() {
|
|
75
|
+
if (context != IntPtr.Zero) { Typer.typer_destroy(context); context = IntPtr.Zero; }
|
|
76
|
+
notify = null;
|
|
77
|
+
}
|
|
78
|
+
public int Begin(int mode) { return context == IntPtr.Zero ? Typer.ErrNotSupported : Typer.typer_session_begin(context, mode); }
|
|
79
|
+
public int Partial(string text) { return context == IntPtr.Zero ? Typer.ErrNotSupported : Typer.typer_feed_partial(context, Bytes(text)); }
|
|
80
|
+
public int Final(string text) { return context == IntPtr.Zero ? Typer.ErrNotSupported : Typer.typer_feed_final(context, Bytes(text)); }
|
|
81
|
+
public int End() { return context == IntPtr.Zero ? Typer.ErrNotSupported : Typer.typer_session_end(context); }
|
|
82
|
+
public int Abort() { return context == IntPtr.Zero ? Typer.ErrNotSupported : Typer.typer_session_abort(context); }
|
|
83
|
+
public static string ErrorText(int code) {
|
|
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 + ")";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
static byte[] Bytes(string text) {
|
|
93
|
+
if (string.IsNullOrEmpty(text)) return new byte[] { 0 };
|
|
94
|
+
byte[] data = Encoding.UTF8.GetBytes(text);
|
|
95
|
+
Array.Resize(ref data, data.Length + 1); // 追加 NUL 终止
|
|
96
|
+
return data;
|
|
57
97
|
}
|
|
58
98
|
}
|
|
59
99
|
static class CapsuleShape {
|
|
@@ -90,12 +130,19 @@ namespace Sonicloud {
|
|
|
90
130
|
public sealed class VoicePanel : Form {
|
|
91
131
|
readonly SingleLineText text = new SingleLineText();
|
|
92
132
|
readonly Waveform waveform = new Waveform();
|
|
93
|
-
readonly Button close = new Button(), copy = new Button();
|
|
133
|
+
readonly Button close = new Button(), copy = new Button(), submit = new Button();
|
|
94
134
|
readonly JavaScriptSerializer json = new JavaScriptSerializer { MaxJsonLength = 300000 };
|
|
95
135
|
readonly System.Windows.Forms.Timer pulse = new System.Windows.Forms.Timer { Interval = 40 };
|
|
96
136
|
string session = "", preview = "", phase = "", message = "";
|
|
97
137
|
bool active;
|
|
98
|
-
|
|
138
|
+
TyperEngine typer;
|
|
139
|
+
bool sessionTyping; // typer 会话已 begin 且未 end/abort
|
|
140
|
+
bool typingLive; // voice_input:中间结果实时逐字打进目标窗口
|
|
141
|
+
bool typingBlocked; // 密码框 / 组件不可用,本次会话拒绝打字
|
|
142
|
+
string blockedReason = "";
|
|
143
|
+
bool typingError; // 注入失败已闩(error_cb),后续 feed/end 只会返回 WRONG_STATE
|
|
144
|
+
int typingErrorCode;
|
|
145
|
+
bool pendingSubmit; // 宿主 submitOffer:文本留在浮窗,等用户放好焦点后一键提交
|
|
99
146
|
Screen screen;
|
|
100
147
|
protected override bool ShowWithoutActivation { get { return true; } }
|
|
101
148
|
protected override CreateParams CreateParams {
|
|
@@ -120,16 +167,19 @@ namespace Sonicloud {
|
|
|
120
167
|
}
|
|
121
168
|
close.Image = icon; close.AccessibleName = "取消";
|
|
122
169
|
copy.Text = "复制结果";
|
|
123
|
-
|
|
170
|
+
submit.Text = "一键提交"; submit.AccessibleName = "一键提交";
|
|
171
|
+
Controls.AddRange(new Control[] { text, waveform, close, copy, submit });
|
|
124
172
|
close.Click += delegate {
|
|
125
173
|
if (active) Emit(new Dictionary<string, object> { { "event", "cancel" }, { "sessionId", session } });
|
|
126
|
-
|
|
174
|
+
EndSession(); preview = message = ""; pendingSubmit = false; Hide();
|
|
127
175
|
};
|
|
176
|
+
submit.Click += delegate { SubmitPending(); };
|
|
128
177
|
copy.Click += delegate { try { Clipboard.SetText(preview); copy.Text = "已复制"; } catch { copy.Text = "复制失败"; } };
|
|
129
178
|
pulse.Tick += delegate { waveform.Phase += 0.25; waveform.Invalidate(); };
|
|
130
179
|
VisibleChanged += delegate { pulse.Enabled = Visible && active; };
|
|
131
180
|
Microsoft.Win32.SystemEvents.DisplaySettingsChanged += DisplayChanged;
|
|
132
181
|
FormClosed += delegate { pulse.Dispose(); close.Image.Dispose(); Microsoft.Win32.SystemEvents.DisplaySettingsChanged -= DisplayChanged; };
|
|
182
|
+
Disposed += delegate { EndSession(); if (typer != null) { typer.Close(); typer = null; } };
|
|
133
183
|
}
|
|
134
184
|
void DisplayChanged(object sender, EventArgs e) { if (!IsDisposed && Visible) BeginInvoke((Action)Render); }
|
|
135
185
|
void Render() {
|
|
@@ -140,44 +190,126 @@ namespace Sonicloud {
|
|
|
140
190
|
var previous = Region; Region = new Region(outline); if (previous != null) previous.Dispose();
|
|
141
191
|
}
|
|
142
192
|
waveform.SetBounds(20, (height - 26) / 2, 23, 26);
|
|
143
|
-
close.SetBounds(width - 44, (height - 28) / 2, 28, 28);
|
|
144
|
-
|
|
193
|
+
close.SetBounds(width - 44, (height - 28) / 2, 28, 28);
|
|
194
|
+
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);
|
|
198
|
+
waveform.Visible = active; submit.Visible = pendingSubmit;
|
|
199
|
+
copy.Visible = !active && preview.Length > 0; close.AccessibleName = active ? "取消" : "关闭";
|
|
145
200
|
int left = active ? 54 : 22, right = copy.Visible ? copy.Left : close.Left;
|
|
146
201
|
text.SetBounds(left, 0, Math.Max(0, right - left - 12), height);
|
|
147
202
|
string status = message.Length > 0 ? message : phase == "finishing" ? "正在整理…" : phase == "translating" ? "正在翻译…" : "";
|
|
148
203
|
string displayText = (status + " " + preview).Trim();
|
|
149
204
|
text.Text = Regex.Replace(displayText, @"[\r\n\t\u0085\u2028\u2029]+", " ");
|
|
150
|
-
pulse.Enabled = active;
|
|
205
|
+
pulse.Enabled = Visible && active;
|
|
151
206
|
Show();
|
|
152
207
|
}
|
|
153
208
|
static string Get(Dictionary<string, object> item, string key) { object value; return item.TryGetValue(key, out value) ? Convert.ToString(value) : ""; }
|
|
154
209
|
void Emit(Dictionary<string, object> value) { Console.WriteLine(json.Serialize(value)); Console.Out.Flush(); }
|
|
210
|
+
// UIA 不可达时放行(fail-open):最坏情况等于无密码检查的直接注入。
|
|
211
|
+
static bool FocusedElementIsPassword() {
|
|
212
|
+
try { var element = AutomationElement.FocusedElement; return element != null && element.Current.IsPassword; }
|
|
213
|
+
catch { return false; }
|
|
214
|
+
}
|
|
215
|
+
void EndSession() {
|
|
216
|
+
active = false; typingLive = false;
|
|
217
|
+
if (sessionTyping) { sessionTyping = false; if (typer != null) typer.Abort(); }
|
|
218
|
+
}
|
|
219
|
+
void HandleTypingError(int code) {
|
|
220
|
+
typingError = true; typingErrorCode = code;
|
|
221
|
+
message = "未回填:" + TyperEngine.ErrorText(code) + ",可复制结果";
|
|
222
|
+
Render();
|
|
223
|
+
}
|
|
224
|
+
// 一键提交:把保留的文本一次性逐字注入点击时聚焦的窗口(浮窗不抢焦点,焦点仍在用户摆好的目标上)。
|
|
225
|
+
void SubmitPending() {
|
|
226
|
+
if (!pendingSubmit) return;
|
|
227
|
+
pendingSubmit = false;
|
|
228
|
+
string reason = null;
|
|
229
|
+
if (typer == null || typer.context == IntPtr.Zero) reason = "打字组件不可用";
|
|
230
|
+
else if (FocusedElementIsPassword()) reason = "目标为密码输入框";
|
|
231
|
+
else {
|
|
232
|
+
int rc = typer.Begin(Typer.ModePerChar);
|
|
233
|
+
if (rc != 0) reason = TyperEngine.ErrorText(rc);
|
|
234
|
+
else {
|
|
235
|
+
sessionTyping = true;
|
|
236
|
+
rc = typer.Final(preview);
|
|
237
|
+
if (rc == 0) { typer.End(); sessionTyping = false; }
|
|
238
|
+
else { typer.Abort(); sessionTyping = false; reason = TyperEngine.ErrorText(rc); }
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (reason == null) { preview = message = ""; Hide(); }
|
|
242
|
+
else { message = "未回填:" + reason + ",可复制结果"; Render(); }
|
|
243
|
+
}
|
|
155
244
|
void HandleCommand(Dictionary<string, object> item) {
|
|
156
245
|
string command = Get(item, "command"), incoming = Get(item, "sessionId"); bool ok = true, inserted = false;
|
|
157
246
|
if (command == "begin") {
|
|
158
247
|
session = incoming; preview = message = ""; phase = "connecting"; active = true;
|
|
159
|
-
|
|
248
|
+
string action = Get(item, "action");
|
|
249
|
+
typingBlocked = false; typingError = false; sessionTyping = false; typingLive = false; pendingSubmit = false;
|
|
250
|
+
if (action == "voice_input" || action == "translate") {
|
|
251
|
+
typingLive = action == "voice_input"; // 翻译只在最终译文出来后打字,避免先打原文再整段退格
|
|
252
|
+
if (typer == null || typer.context == IntPtr.Zero) { typingBlocked = true; blockedReason = "打字组件不可用"; }
|
|
253
|
+
else if (FocusedElementIsPassword()) { typingBlocked = true; blockedReason = "目标为密码输入框"; }
|
|
254
|
+
else {
|
|
255
|
+
int rc = typer.Begin(Typer.ModePerChar);
|
|
256
|
+
if (rc == 0) sessionTyping = true;
|
|
257
|
+
else { typingBlocked = true; blockedReason = TyperEngine.ErrorText(rc); }
|
|
258
|
+
}
|
|
259
|
+
}
|
|
160
260
|
screen = Screen.FromPoint(Cursor.Position); copy.Text = "复制结果"; Render();
|
|
161
|
-
} else if (incoming.Length > 0 && incoming != session) ok = false;
|
|
261
|
+
} else if (incoming.Length > 0 && incoming != session) { ok = false; }
|
|
162
262
|
else if (command == "result" && active) {
|
|
163
|
-
preview = Get(item, "text");
|
|
164
|
-
|
|
165
|
-
if (
|
|
263
|
+
preview = Get(item, "text");
|
|
264
|
+
string reason = null;
|
|
265
|
+
if (typingBlocked) reason = blockedReason;
|
|
266
|
+
else if (typingError) reason = TyperEngine.ErrorText(typingErrorCode);
|
|
267
|
+
else if (sessionTyping) {
|
|
268
|
+
int rc = typer.Final(preview);
|
|
269
|
+
if (rc != 0) reason = TyperEngine.ErrorText(rc);
|
|
270
|
+
else { typer.End(); sessionTyping = false; }
|
|
271
|
+
}
|
|
272
|
+
EndSession();
|
|
273
|
+
if (reason == null) { inserted = true; Hide(); }
|
|
274
|
+
else { message = "未回填:" + reason + ",可复制结果"; Render(); }
|
|
166
275
|
} else if (command == "event") {
|
|
167
276
|
switch (Get(item, "type")) {
|
|
168
|
-
case "preview":
|
|
277
|
+
case "preview":
|
|
278
|
+
if (active) {
|
|
279
|
+
preview = Get(item, "text");
|
|
280
|
+
if (typingLive && sessionTyping && !typingError) typer.Partial(preview);
|
|
281
|
+
Render();
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
169
284
|
case "phase": if (active) { phase = Get(item, "phase"); Render(); } break;
|
|
170
285
|
case "notice": message = Get(item, "message"); Render(); break;
|
|
171
|
-
case "failed":
|
|
172
|
-
case "
|
|
286
|
+
case "failed": EndSession(); message = Get(item, "message"); Render(); break;
|
|
287
|
+
case "submitOffer":
|
|
288
|
+
// 宿主无法填入 Harness 对话(窗口/渲染不可达):文本留在浮窗,交给一键提交注入当前焦点窗口。
|
|
289
|
+
preview = Get(item, "text");
|
|
290
|
+
EndSession();
|
|
291
|
+
typingError = false; // 清闩,本次提交允许重新注入
|
|
292
|
+
pendingSubmit = preview.Length > 0;
|
|
293
|
+
message = pendingSubmit ? Get(item, "message") : "没有可输入的内容";
|
|
294
|
+
if (message.Length == 0) message = "请打开需要输入界面";
|
|
295
|
+
copy.Text = "复制结果"; Render();
|
|
296
|
+
break;
|
|
297
|
+
case "cancelled": case "finished":
|
|
298
|
+
// 空结果收尾(无 result):实时打出的中间结果用空 partial 修正掉,再结束会话。
|
|
299
|
+
if (sessionTyping && typingLive && !typingError) { typer.Partial(""); typer.End(); sessionTyping = false; }
|
|
300
|
+
EndSession(); preview = message = ""; Hide();
|
|
301
|
+
break;
|
|
173
302
|
}
|
|
174
303
|
} else ok = false;
|
|
175
304
|
object id; if (item.TryGetValue("id", out id)) Emit(new Dictionary<string, object> { { "id", id }, { "ok", ok }, { "value", inserted } });
|
|
176
305
|
}
|
|
177
|
-
[STAThread] public static void Run() {
|
|
306
|
+
[STAThread] public static void Run(string dllDirectory) {
|
|
307
|
+
Typer.Load(dllDirectory);
|
|
178
308
|
Application.EnableVisualStyles();
|
|
179
309
|
using (var form = new VoicePanel()) {
|
|
180
|
-
var handle = form.Handle;
|
|
310
|
+
var handle = form.Handle; // 先建句柄,后台线程的 BeginInvoke 才有目标
|
|
311
|
+
form.typer = new TyperEngine();
|
|
312
|
+
form.typer.Open(code => { if (!form.IsDisposed) form.BeginInvoke((Action)(() => form.HandleTypingError(code))); });
|
|
181
313
|
var input = new Thread(() => {
|
|
182
314
|
string line;
|
|
183
315
|
while ((line = Console.ReadLine()) != null) {
|
|
@@ -268,6 +268,33 @@ final class VoiceUI: NSObject {
|
|
|
268
268
|
}
|
|
269
269
|
func handle(_ command: [String: Any]) {
|
|
270
270
|
let name = command["command"] as? String ?? ""
|
|
271
|
+
if name == "permissions" {
|
|
272
|
+
let action = command["action"] as? String ?? "check"
|
|
273
|
+
guard ["check", "refresh", "accessibility"].contains(action) else {
|
|
274
|
+
if let id = command["id"] { emit(["id": id, "ok": false, "message": "不支持此打字权限操作"]) }
|
|
275
|
+
return
|
|
276
|
+
}
|
|
277
|
+
if action == "accessibility" {
|
|
278
|
+
guard !active && !resultPending else {
|
|
279
|
+
if let id = command["id"] { emit(["id": id, "ok": false, "message": "请先结束语音输入,再设置打字权限"]) }
|
|
280
|
+
return
|
|
281
|
+
}
|
|
282
|
+
if !AXIsProcessTrusted() {
|
|
283
|
+
hide()
|
|
284
|
+
let options = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: true] as CFDictionary
|
|
285
|
+
_ = AXIsProcessTrustedWithOptions(options)
|
|
286
|
+
if let settings = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility") {
|
|
287
|
+
NSWorkspace.shared.open(settings)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
let helperApp = Bundle.main.bundlePath.hasSuffix(".app") ? Bundle.main.bundlePath
|
|
292
|
+
: URL(fileURLWithPath: CommandLine.arguments[0]).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path
|
|
293
|
+
if let id = command["id"] {
|
|
294
|
+
emit(["id": id, "ok": true, "value": ["supported": true, "accessibility": AXIsProcessTrusted(), "helperApp": helperApp]])
|
|
295
|
+
}
|
|
296
|
+
return
|
|
297
|
+
}
|
|
271
298
|
let incoming = command["sessionId"] as? String ?? ""
|
|
272
299
|
var success = true
|
|
273
300
|
let inserted = false
|
|
Binary file
|
|
@@ -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>
|
|
Binary file
|
|
@@ -6,4 +6,4 @@ $references = @('System.Windows.Forms', 'System.Drawing', 'System.Web.Extensions
|
|
|
6
6
|
[System.Windows.Automation.AutomationElement].Assembly.Location,
|
|
7
7
|
[System.Windows.Automation.Text.TextPatternRangeEndpoint].Assembly.Location)
|
|
8
8
|
Add-Type -Path (Join-Path $PSScriptRoot 'VoicePanel.cs') -ReferencedAssemblies $references
|
|
9
|
-
[Sonicloud.VoicePanel]::Run()
|
|
9
|
+
[Sonicloud.VoicePanel]::Run($PSScriptRoot)
|
|
@@ -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 许可。原压缩包未提供单独的组件许可文件;公开再分发所需的完整声明与授权材料待供应商补齐。
|