@sonicloud/dsh-sonicloud-device 0.1.3 → 0.1.5
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 +37 -1
- package/CHANGELOG.zh.md +37 -1
- package/README.md +18 -14
- package/README.zh.md +9 -5
- package/dist/build.json +1 -1
- package/dist/client.js +2112 -120
- package/docs/contributing/development.md +7 -5
- package/docs/specs/ci-cd.md +5 -4
- package/docs/specs/mouse-settings.md +1 -1
- package/docs/specs/multilingual.md +98 -0
- package/docs/specs/smart-mouse-plugin.md +6 -3
- package/locale/de.json +7 -0
- package/locale/en.json +7 -0
- package/locale/es.json +7 -0
- package/locale/fr.json +7 -0
- package/locale/ja.json +7 -0
- package/locale/pt.json +7 -0
- package/locale/ru.json +7 -0
- package/locale/zh.json +7 -0
- package/native/desktop/VOICE_SOURCE.json +2 -2
- package/native/desktop/VoicePanel.cs +70 -33
- package/native/desktop/VoicePanel.swift +58 -21
- package/native/desktop/darwin-arm64/Sonicloud Voice.app/Contents/MacOS/sonicloud-voice +0 -0
- package/native/screenshot/README.md +9 -4
- package/native/screenshot/SOURCE.json +48 -17
- package/native/screenshot/darwin-arm64/screentool-macos-1.2.2.zip +0 -0
- package/native/screenshot/helper-i18n/de.json +85 -0
- package/native/screenshot/helper-i18n/es.json +85 -0
- package/native/screenshot/helper-i18n/fr.json +85 -0
- package/native/screenshot/patches/{hide-cloud-actions.patch → macos/hide-cloud-actions.patch} +84 -76
- package/native/screenshot/patches/macos/mac-clang-compat.patch +14 -0
- package/native/screenshot/patches/macos/mac-color-panel.patch +40 -0
- package/native/screenshot/patches/macos/mac-permissions.patch +549 -0
- package/native/screenshot/patches/macos/mac-ui-focus.patch +658 -0
- package/native/screenshot/patches/macos/upstream-files.json +77 -0
- package/native/screenshot/patches/upstream-files.json +12 -8
- package/native/screenshot/win32-x64/i18n/de.json +85 -0
- package/native/screenshot/win32-x64/i18n/es.json +85 -0
- package/native/screenshot/win32-x64/i18n/fr.json +85 -0
- package/native/screenshot/win32-x64/screenhelper.exe +0 -0
- package/package.json +5 -3
- package/src/asr/auth.mjs +9 -8
- package/src/asr/config.mjs +1 -1
- package/src/asr/stream.mjs +25 -24
- package/src/desktop/presentation.mjs +18 -12
- package/src/desktop/screenshot-shortcut-worker.mjs +188 -0
- package/src/desktop/screenshot-shortcut.mjs +266 -0
- package/src/desktop/screenshot-worker.mjs +49 -32
- package/src/desktop/screenshot.mjs +46 -26
- package/src/devices/actions.mjs +7 -6
- package/src/devices/config.mjs +2 -1
- package/src/devices/diagnostics.mjs +4 -3
- package/src/devices/manager.mjs +77 -43
- package/src/devices/native-worker.mjs +4 -3
- package/src/devices/native.mjs +9 -8
- package/src/devices/queue.mjs +4 -3
- package/src/devices/recognition.mjs +5 -4
- package/src/devices/store.mjs +3 -2
- package/src/devices/translate.mjs +11 -10
- package/src/host/ai-conversation.mjs +8 -7
- package/src/host/index.mjs +13 -3
- package/src/host/locale.mjs +44 -0
- package/src/shared/devices.mjs +13 -12
- package/src/shared/i18n.mjs +47 -0
- package/src/shared/locales/de.json +181 -0
- package/src/shared/locales/en.json +181 -0
- package/src/shared/locales/es.json +181 -0
- package/src/shared/locales/fr.json +181 -0
- package/src/shared/locales/ja.json +181 -0
- package/src/shared/locales/pt.json +181 -0
- package/src/shared/locales/ru.json +181 -0
- package/src/shared/locales/zh.json +181 -0
- package/src/shared/remote.mjs +7 -1
- package/src/shared/screenshot-shortcut.mjs +50 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { message as msg } from '../shared/i18n.mjs';
|
|
1
2
|
import koffi from 'koffi';
|
|
2
3
|
import { dirname } from 'node:path';
|
|
3
4
|
|
|
@@ -13,6 +14,7 @@ const call = (fn, ...args) => {
|
|
|
13
14
|
const callbacks = [];
|
|
14
15
|
let api, handle, closing = false, closePromise, connected = false, connection, disconnected, stateRequest;
|
|
15
16
|
let capabilities = new Set();
|
|
17
|
+
let currentLanguage; // 宿主下发的 UI 语言;helper(重)连后应用,实际生效由 language_changed 事件回报
|
|
16
18
|
let commands = Promise.resolve(), events = Promise.resolve();
|
|
17
19
|
function send(message) {
|
|
18
20
|
if (!process.connected) return;
|
|
@@ -30,18 +32,18 @@ function finishState(error, value, request = stateRequest) {
|
|
|
30
32
|
stateRequest = undefined; clearTimeout(request.timer);
|
|
31
33
|
if (error) request.reject(error); else request.resolve(value);
|
|
32
34
|
}
|
|
33
|
-
const errorMessage = rc => rc === -3 ? '
|
|
34
|
-
: rc === -2 ? '
|
|
35
|
+
const errorMessage = rc => rc === -3 ? msg('error.busy')
|
|
36
|
+
: rc === -2 ? msg('error.screenshot') : msg('error.screenshot');
|
|
35
37
|
|
|
36
38
|
// 原生线程回调只保留事件文本并排队;所有 FFI 调用离开回调后异步执行。
|
|
37
39
|
function queueEvent(json) {
|
|
38
40
|
const text = String(json || '');
|
|
39
41
|
setImmediate(() => {
|
|
40
|
-
let event; try { event = JSON.parse(text); } catch { notice('
|
|
42
|
+
let event; try { event = JSON.parse(text); } catch { notice(msg('error.screenshot')); return; }
|
|
41
43
|
if (event.type === 'disconnected') {
|
|
42
44
|
connected = false; capabilities = new Set();
|
|
43
|
-
finishState(new Error('
|
|
44
|
-
finishConnection(new Error('
|
|
45
|
+
finishState(new Error(msg('error.permission')));
|
|
46
|
+
finishConnection(new Error(msg('error.screenshot')));
|
|
45
47
|
disconnected?.();
|
|
46
48
|
}
|
|
47
49
|
if (closing) return;
|
|
@@ -52,8 +54,14 @@ function queueEvent(json) {
|
|
|
52
54
|
}
|
|
53
55
|
if (event.type === 'connected') {
|
|
54
56
|
const rc = await call(api.config, handle, JSON.stringify({ ocr_visible: false, trans_enabled: false }));
|
|
55
|
-
if (rc !== 0) { connected = false; finishConnection(new Error('
|
|
57
|
+
if (rc !== 0) { connected = false; finishConnection(new Error(msg('error.screenshot'))); return; }
|
|
56
58
|
connected = true; finishConnection();
|
|
59
|
+
// helper(含重连)每次就绪都重申当前语言:HelperConfig 不跨 helper 进程持久。
|
|
60
|
+
// 经 set_config 的 lang 键透传:随包 dylib 为原包 1.2.2(无 1.3.0 的
|
|
61
|
+
// sct_set_language 符号),厂商推荐 FFI 宿主走 set_config。宿主语言中
|
|
62
|
+
// helper 无内置 .qm 的语种(西/法/德)由交付包 helper 同目录 i18n/ 的
|
|
63
|
+
// screentool-i18n/1 JSON 补齐,helper 启动时自举装载,无需宿主下发目录。
|
|
64
|
+
if (currentLanguage) { try { await call(api.config, handle, JSON.stringify({ lang: currentLanguage })); } catch { /* 失败由 language_changed 事件如实回报 */ } }
|
|
57
65
|
} else if (event.type === 'hello_ack') {
|
|
58
66
|
capabilities = new Set(Array.isArray(event.capabilities) ? event.capabilities : []);
|
|
59
67
|
} else if (event.type === 'state_report') {
|
|
@@ -63,17 +71,17 @@ function queueEvent(json) {
|
|
|
63
71
|
} else if (event.type === 'connect_failed') {
|
|
64
72
|
connected = false;
|
|
65
73
|
const message = event.code === 'stale_helper_refused'
|
|
66
|
-
? '
|
|
74
|
+
? msg('error.screenshotBusy') : msg('error.screenshot');
|
|
67
75
|
if (connection) finishConnection(new Error(message)); else notice(message);
|
|
68
76
|
} else if (event.type === 'error' || event.type === 'word_failed') {
|
|
69
77
|
notice(event.code === 'permission_screen_required'
|
|
70
|
-
? '
|
|
71
|
-
: ['permission_busy', 'permission_request_busy'].includes(event.code) ? '
|
|
72
|
-
: '
|
|
78
|
+
? msg('error.screenPermission')
|
|
79
|
+
: ['permission_busy', 'permission_request_busy'].includes(event.code) ? msg('error.screenshotBusy')
|
|
80
|
+
: msg('error.permission'));
|
|
73
81
|
} else if (['word_started', 'word_result', 'ocr_requested'].includes(event.type)) {
|
|
74
|
-
notice('
|
|
82
|
+
notice(msg('error.screenshotExport'));
|
|
75
83
|
}
|
|
76
|
-
}).catch(() => { connected = false; finishConnection(new Error('
|
|
84
|
+
}).catch(() => { connected = false; finishConnection(new Error(msg('error.screenshot'))); notice(msg('error.screenshot')); });
|
|
77
85
|
});
|
|
78
86
|
}
|
|
79
87
|
|
|
@@ -92,51 +100,59 @@ async function initialize() {
|
|
|
92
100
|
shutdown: library.func('int sct_shutdown(void *h, const char *policy)'),
|
|
93
101
|
};
|
|
94
102
|
handle = await call(api.create);
|
|
95
|
-
if (!handle) throw new Error('
|
|
103
|
+
if (!handle) throw new Error(msg('error.screenshot'));
|
|
96
104
|
const eventProto = koffi.proto('void SonicloudScreenshotEvent(void *user, const char *json, const uint8_t *payload, int len)');
|
|
97
105
|
const logProto = koffi.proto('void SonicloudScreenshotLog(void *user, int level, const char *message)');
|
|
98
106
|
callbacks.push(koffi.register((_user, json) => queueEvent(json), koffi.pointer(eventProto)));
|
|
99
107
|
callbacks.push(koffi.register(() => {}, koffi.pointer(logProto)));
|
|
100
108
|
if (await call(api.setEvent, handle, callbacks[0], null) !== 0 ||
|
|
101
109
|
await call(api.setLog, handle, callbacks[1], null) !== 0 ||
|
|
102
|
-
await call(api.helper, handle, helperPath) !== 0) throw new Error('
|
|
110
|
+
await call(api.helper, handle, helperPath) !== 0) throw new Error(msg('error.screenshot'));
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
async function ensureConnected() {
|
|
106
|
-
if (closing) throw new Error('
|
|
114
|
+
if (closing) throw new Error(msg('error.closed'));
|
|
107
115
|
if (connected) return;
|
|
108
116
|
if (!connection) {
|
|
109
117
|
let resolve, reject;
|
|
110
118
|
const promise = new Promise((yes, no) => { resolve = yes; reject = no; });
|
|
111
|
-
connection = { promise, resolve, reject, timer: setTimeout(() => finishConnection(new Error('
|
|
119
|
+
connection = { promise, resolve, reject, timer: setTimeout(() => finishConnection(new Error(msg('error.timeout'))), 6500) };
|
|
112
120
|
call(api.connect, handle, 5000).then(rc => { if (rc !== 0) finishConnection(new Error(errorMessage(rc))); },
|
|
113
|
-
() => finishConnection(new Error('
|
|
121
|
+
() => finishConnection(new Error(msg('error.screenshot'))));
|
|
114
122
|
}
|
|
115
123
|
return connection.promise;
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
async function queryState() {
|
|
119
|
-
if (closing) throw new Error('
|
|
127
|
+
if (closing) throw new Error(msg('error.closed'));
|
|
120
128
|
if (stateRequest) return stateRequest.promise;
|
|
121
129
|
let resolve, reject;
|
|
122
130
|
const promise = new Promise((yes, no) => { resolve = yes; reject = no; });
|
|
123
131
|
const request = { promise, resolve, reject,
|
|
124
|
-
timer: setTimeout(() => finishState(new Error('
|
|
132
|
+
timer: setTimeout(() => finishState(new Error(msg('error.timeout')), undefined, request), 2500) };
|
|
125
133
|
stateRequest = request;
|
|
126
134
|
call(api.query, handle).then(rc => {
|
|
127
|
-
if (rc !== 0) finishState(new Error('
|
|
128
|
-
}, () => finishState(new Error('
|
|
135
|
+
if (rc !== 0) finishState(new Error(msg('error.permission')), undefined, request);
|
|
136
|
+
}, () => finishState(new Error(msg('error.permission')), undefined, request));
|
|
129
137
|
return promise;
|
|
130
138
|
}
|
|
131
139
|
|
|
132
140
|
function permissionView(state) {
|
|
133
141
|
if (typeof state.perm_screen !== 'boolean' || typeof state.perm_a11y !== 'boolean')
|
|
134
|
-
throw new Error('
|
|
142
|
+
throw new Error(msg('error.permission'));
|
|
135
143
|
return { supported: true, screenRecording: state.perm_screen, accessibility: state.perm_a11y,
|
|
136
144
|
helperApp: typeof state.helper_app === 'string' ? state.helper_app.slice(0, 4096) : '' };
|
|
137
145
|
}
|
|
138
146
|
const idle = state => state.capturing === false && state.pins_alive === 0 && state.pin_editing !== true;
|
|
139
147
|
|
|
148
|
+
async function applyLanguage(tag) {
|
|
149
|
+
// 尽力而为:语言标签限定字母与连字符,其余静默忽略;生效与否由 language_changed 事件回报。
|
|
150
|
+
if (typeof tag !== 'string' || !/^[a-zA-Z][a-zA-Z-]{1,15}$/.test(tag)) return;
|
|
151
|
+
currentLanguage = tag;
|
|
152
|
+
if (closing || !handle || !connected) return;
|
|
153
|
+
try { await call(api.config, handle, JSON.stringify({ lang: tag })); } catch { /* helper 解析折叠/回退自己回报 */ }
|
|
154
|
+
}
|
|
155
|
+
|
|
140
156
|
async function stopHelper() {
|
|
141
157
|
let timer;
|
|
142
158
|
const stopped = new Promise(resolve => {
|
|
@@ -145,13 +161,13 @@ async function stopHelper() {
|
|
|
145
161
|
});
|
|
146
162
|
try {
|
|
147
163
|
const rc = await call(api.shutdown, handle, 'close_now');
|
|
148
|
-
if (rc !== 0) throw new Error('
|
|
149
|
-
if (!await stopped) throw new Error('
|
|
164
|
+
if (rc !== 0) throw new Error(msg('error.permission'));
|
|
165
|
+
if (!await stopped) throw new Error(msg('error.permission'));
|
|
150
166
|
} finally { clearTimeout(timer); disconnected = undefined; }
|
|
151
167
|
}
|
|
152
168
|
|
|
153
169
|
async function permissions(action) {
|
|
154
|
-
if (!['check', 'screen', 'accessibility', 'refresh'].includes(action)) throw new Error('
|
|
170
|
+
if (!['check', 'screen', 'accessibility', 'refresh'].includes(action)) throw new Error(msg('error.permission'));
|
|
155
171
|
if (process.platform !== 'darwin') return { supported: false, screenRecording: true, accessibility: true, helperApp: '' };
|
|
156
172
|
let state = await queryState();
|
|
157
173
|
let view = permissionView(state);
|
|
@@ -160,10 +176,10 @@ async function permissions(action) {
|
|
|
160
176
|
state = await queryState(); view = permissionView(state);
|
|
161
177
|
}
|
|
162
178
|
if (action === 'screen' || action === 'accessibility') {
|
|
163
|
-
if (!idle(state)) throw new Error('
|
|
164
|
-
if (!capabilities.has('permission_preflight')) throw new Error('
|
|
179
|
+
if (!idle(state)) throw new Error(msg('error.screenshotBusy'));
|
|
180
|
+
if (!capabilities.has('permission_preflight')) throw new Error(msg('error.permission'));
|
|
165
181
|
const rc = await call(api.config, handle, JSON.stringify({ permission_request: action }));
|
|
166
|
-
if (rc !== 0) throw new Error('
|
|
182
|
+
if (rc !== 0) throw new Error(msg('error.permission'));
|
|
167
183
|
// 系统授权由用户完成;写入请求只代表已受理,不能当作已授权。
|
|
168
184
|
}
|
|
169
185
|
return view;
|
|
@@ -171,18 +187,19 @@ async function permissions(action) {
|
|
|
171
187
|
|
|
172
188
|
process.on('message', message => {
|
|
173
189
|
if (message?.command === 'close') { void close(); return; }
|
|
190
|
+
if (message?.command === 'locale') { void applyLanguage(message.language); return; }
|
|
174
191
|
if (closing || !['capture', 'permissions'].includes(message?.command)) return;
|
|
175
192
|
commands = commands.then(async () => {
|
|
176
193
|
await initialized;
|
|
177
194
|
await ensureConnected();
|
|
178
|
-
if (closing) throw new Error('
|
|
195
|
+
if (closing) throw new Error(msg('error.closed'));
|
|
179
196
|
if (message.command === 'permissions') {
|
|
180
197
|
const value = await permissions(message.action ?? 'check');
|
|
181
198
|
send({ type: 'reply', requestId: message.requestId, ok: true, value });
|
|
182
199
|
return;
|
|
183
200
|
}
|
|
184
201
|
if (process.platform === 'darwin' && !permissionView(await queryState()).screenRecording)
|
|
185
|
-
throw new Error('
|
|
202
|
+
throw new Error(msg('error.screenPermission'));
|
|
186
203
|
const trigger = typeof message.trigger === 'string' ? message.trigger.replace(/[^a-zA-Z0-9_.-]/g, '_').slice(0, 64) : 'ui';
|
|
187
204
|
const rc = await call(api.capture, handle, trigger || 'ui');
|
|
188
205
|
if (rc !== 0) throw new Error(errorMessage(rc));
|
|
@@ -198,8 +215,8 @@ initialized.then(() => { if (!closing) send({ type: 'ready' }); }).catch(() => {
|
|
|
198
215
|
function close() {
|
|
199
216
|
if (closePromise) return closePromise;
|
|
200
217
|
closing = true; connected = false;
|
|
201
|
-
finishConnection(new Error('
|
|
202
|
-
finishState(new Error('
|
|
218
|
+
finishConnection(new Error(msg('error.closed')));
|
|
219
|
+
finishState(new Error(msg('error.closed')));
|
|
203
220
|
closePromise = (async () => {
|
|
204
221
|
await initialized.catch(() => {});
|
|
205
222
|
await commands.catch(() => {}); await events.catch(() => {});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { message as msg } from '../shared/i18n.mjs';
|
|
1
2
|
import { EventEmitter } from 'node:events';
|
|
2
3
|
import { fork, execFile } from 'node:child_process';
|
|
3
4
|
import { existsSync } from 'node:fs';
|
|
@@ -37,7 +38,7 @@ export async function prepareMacScreenshot({
|
|
|
37
38
|
// ditto 最多运行 30 秒;清理崩溃后留下的过期准备锁。
|
|
38
39
|
try { if (Date.now() - (await stat(lock)).mtimeMs > 60000) { await rm(lock, { recursive: true, force: true }); continue; } }
|
|
39
40
|
catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
40
|
-
if (Date.now() > deadline) throw new Error('
|
|
41
|
+
if (Date.now() > deadline) throw new Error(msg('error.screenshot'));
|
|
41
42
|
await new Promise(resolve => setTimeout(resolve, 50));
|
|
42
43
|
}
|
|
43
44
|
}
|
|
@@ -48,7 +49,7 @@ export async function prepareMacScreenshot({
|
|
|
48
49
|
await rm(directory, { recursive: true, force: true });
|
|
49
50
|
temporary = await mkdtemp(join(cacheRoot, '.screentool-'));
|
|
50
51
|
await extract('/usr/bin/ditto', ['-x', '-k', archivePath, temporary], { timeout: 30000, maxBuffer: 8192 });
|
|
51
|
-
if (!complete(macPaths(temporary))) throw new Error('
|
|
52
|
+
if (!complete(macPaths(temporary))) throw new Error(msg('error.screenshot'));
|
|
52
53
|
// 另一进程可能已完成相同版本;只清理本次创建的临时目录。
|
|
53
54
|
if (!complete(paths)) {
|
|
54
55
|
try { await rename(temporary, directory); }
|
|
@@ -69,10 +70,21 @@ export class ScreenshotService extends EventEmitter {
|
|
|
69
70
|
Object.assign(this, { platform, arch, launch, timeoutMs, startTimeoutMs, closeTimeoutMs,
|
|
70
71
|
libraryPath, helperPath, prepareMac, exists });
|
|
71
72
|
this.pending = new Map(); this.sequence = 0;
|
|
73
|
+
this.locale = undefined; // 宿主 UI 语言:worker(重)启动时下发,运行中热切换
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 语言为尽力而为:不拉起未运行的 worker;helper 生效结果经 language_changed 事件回报。
|
|
77
|
+
setLocale(locale) {
|
|
78
|
+
if (typeof locale !== 'string' || !/^[a-zA-Z][a-zA-Z-]{1,15}$/.test(locale)) return;
|
|
79
|
+
this.locale = locale;
|
|
80
|
+
const child = this.child;
|
|
81
|
+
if (!this.closed && child?.connected) {
|
|
82
|
+
try { child.send({ command: 'locale', language: locale }, () => {}); } catch { /* worker 故障走现有监管 */ }
|
|
83
|
+
}
|
|
72
84
|
}
|
|
73
85
|
|
|
74
86
|
start() {
|
|
75
|
-
if (this.closed) return Promise.reject(new Error('
|
|
87
|
+
if (this.closed) return Promise.reject(new Error(msg('error.closed')));
|
|
76
88
|
if (this.starting) return this.starting;
|
|
77
89
|
const attempt = this.startWorker().catch(error => { if (this.starting === attempt) this.starting = undefined; throw error; });
|
|
78
90
|
this.starting = attempt;
|
|
@@ -81,7 +93,7 @@ export class ScreenshotService extends EventEmitter {
|
|
|
81
93
|
|
|
82
94
|
async startWorker() {
|
|
83
95
|
const target = `${this.platform}-${this.arch}`;
|
|
84
|
-
if (!['win32-x64', 'darwin-arm64'].includes(target)) throw new Error('
|
|
96
|
+
if (!['win32-x64', 'darwin-arm64'].includes(target)) throw new Error(msg('error.screenshot'));
|
|
85
97
|
let paths = { libraryPath: this.libraryPath, helperPath: this.helperPath };
|
|
86
98
|
if (!paths.libraryPath || !paths.helperPath) {
|
|
87
99
|
try {
|
|
@@ -90,19 +102,22 @@ export class ScreenshotService extends EventEmitter {
|
|
|
90
102
|
helperPath: join(nativeRoot, target, 'screenhelper.exe'),
|
|
91
103
|
};
|
|
92
104
|
paths = { libraryPath: paths.libraryPath ?? defaults.libraryPath, helperPath: paths.helperPath ?? defaults.helperPath };
|
|
93
|
-
} catch { throw new Error('
|
|
105
|
+
} catch { throw new Error(msg('error.permission')); }
|
|
94
106
|
}
|
|
95
|
-
if (this.closed) throw new Error('
|
|
96
|
-
if (!this.exists(paths.libraryPath) || !this.exists(paths.helperPath)) throw new Error('
|
|
107
|
+
if (this.closed) throw new Error(msg('error.closed'));
|
|
108
|
+
if (!this.exists(paths.libraryPath) || !this.exists(paths.helperPath)) throw new Error(msg('error.screenshot'));
|
|
97
109
|
let child;
|
|
98
110
|
try {
|
|
111
|
+
const forkOptions = { stdio: ['ignore', 'ignore', 'ignore', 'ipc'], execArgv: [], windowsHide: true,
|
|
112
|
+
// helper 出生语言(1.3.0 HelperConfig 读 SCREENTOOL_LANG;1.2.2 忽略,跨平台无害)
|
|
113
|
+
env: { ...process.env, ...(this.locale ? { SCREENTOOL_LANG: this.locale } : {}) } };
|
|
99
114
|
child = this.launch(fileURLToPath(new URL('./screenshot-worker.mjs', import.meta.url)),
|
|
100
|
-
[paths.libraryPath, paths.helperPath],
|
|
101
|
-
} catch { throw new Error('
|
|
115
|
+
[paths.libraryPath, paths.helperPath], forkOptions);
|
|
116
|
+
} catch { throw new Error(msg('error.screenshot')); }
|
|
102
117
|
this.child = child;
|
|
103
118
|
return new Promise((resolve, reject) => {
|
|
104
119
|
let ready = false, failed = false;
|
|
105
|
-
const timer = setTimeout(() => { fail('
|
|
120
|
+
const timer = setTimeout(() => { fail(msg('error.timeout')); child.kill(); }, this.startTimeoutMs);
|
|
106
121
|
const fail = message => {
|
|
107
122
|
if (failed) return;
|
|
108
123
|
failed = true; clearTimeout(timer);
|
|
@@ -114,8 +129,13 @@ export class ScreenshotService extends EventEmitter {
|
|
|
114
129
|
};
|
|
115
130
|
child.on('message', message => {
|
|
116
131
|
if (this.child !== child || !message || typeof message !== 'object') return;
|
|
117
|
-
if (message.type === 'ready') {
|
|
118
|
-
|
|
132
|
+
if (message.type === 'ready') {
|
|
133
|
+
clearTimeout(timer); ready = true; resolve();
|
|
134
|
+
if (this.locale && !this.closed) {
|
|
135
|
+
try { child.send({ command: 'locale', language: this.locale }, () => {}); } catch { /* worker 故障走现有监管 */ }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else if (message.type === 'fatal') { fail(msg('error.screenshot')); child.kill(); }
|
|
119
139
|
else if (message.type === 'notice') { if (!this.closed && typeof message.message === 'string') this.emit('notice', message.message); }
|
|
120
140
|
else if (message.type === 'event') { if (!this.closed && message.event && typeof message.event.type === 'string') this.emit('event', message.event); }
|
|
121
141
|
else if (message.type === 'reply') {
|
|
@@ -123,53 +143,53 @@ export class ScreenshotService extends EventEmitter {
|
|
|
123
143
|
if (!pending) return;
|
|
124
144
|
clearTimeout(pending.timer); this.pending.delete(message.requestId);
|
|
125
145
|
if (message.ok) pending.resolve(message.value ?? true);
|
|
126
|
-
else pending.reject(new Error(message.message || '
|
|
146
|
+
else pending.reject(new Error(message.message || msg('error.screenshot')));
|
|
127
147
|
}
|
|
128
148
|
});
|
|
129
|
-
child.once('exit', () => fail(this.closed ? '
|
|
130
|
-
child.once('error', () => { fail('
|
|
131
|
-
child.once('disconnect', () => { fail(this.closed ? '
|
|
132
|
-
this.rejectStarting = () => { clearTimeout(timer); reject(new Error('
|
|
149
|
+
child.once('exit', () => fail(this.closed ? msg('error.closed') : msg('error.screenshot')));
|
|
150
|
+
child.once('error', () => { fail(msg('error.screenshot')); child.kill(); });
|
|
151
|
+
child.once('disconnect', () => { fail(this.closed ? msg('error.closed') : msg('error.screenshot')); if (!this.closed) child.kill(); });
|
|
152
|
+
this.rejectStarting = () => { clearTimeout(timer); reject(new Error(msg('error.closed'))); };
|
|
133
153
|
});
|
|
134
154
|
}
|
|
135
155
|
|
|
136
156
|
capture(trigger = 'ui') { return this.command('capture', { trigger }); }
|
|
137
157
|
|
|
138
158
|
async permissions(action = 'check') {
|
|
139
|
-
if (!['check', 'screen', 'accessibility', 'refresh'].includes(action)) throw new Error('
|
|
140
|
-
if (this.closed) throw new Error('
|
|
159
|
+
if (!['check', 'screen', 'accessibility', 'refresh'].includes(action)) throw new Error(msg('error.permission'));
|
|
160
|
+
if (this.closed) throw new Error(msg('error.closed'));
|
|
141
161
|
if (this.platform !== 'darwin') return { supported: false, screenRecording: true, accessibility: true, helperApp: '' };
|
|
142
162
|
const state = await this.command('permissions', { action }, Math.max(this.timeoutMs, 20000));
|
|
143
163
|
if (!state || typeof state !== 'object' || state.supported !== true || typeof state.screenRecording !== 'boolean'
|
|
144
|
-
|| typeof state.accessibility !== 'boolean' || typeof state.helperApp !== 'string') throw new Error('
|
|
164
|
+
|| typeof state.accessibility !== 'boolean' || typeof state.helperApp !== 'string') throw new Error(msg('error.permission'));
|
|
145
165
|
return state;
|
|
146
166
|
}
|
|
147
167
|
|
|
148
168
|
async command(command, fields = {}, timeoutMs = this.timeoutMs) {
|
|
149
169
|
await this.start();
|
|
150
|
-
if (this.closed) throw new Error('
|
|
170
|
+
if (this.closed) throw new Error(msg('error.closed'));
|
|
151
171
|
const child = this.child;
|
|
152
|
-
if (!child?.connected) throw new Error('
|
|
172
|
+
if (!child?.connected) throw new Error(msg('error.screenshot'));
|
|
153
173
|
const requestId = ++this.sequence;
|
|
154
174
|
return new Promise((resolve, reject) => {
|
|
155
175
|
const timer = setTimeout(() => {
|
|
156
|
-
this.pending.delete(requestId); reject(new Error('
|
|
176
|
+
this.pending.delete(requestId); reject(new Error(msg('error.timeout'))); child.kill();
|
|
157
177
|
}, timeoutMs);
|
|
158
178
|
this.pending.set(requestId, { resolve, reject, timer });
|
|
159
179
|
try {
|
|
160
180
|
child.send({ command, ...fields, requestId }, error => {
|
|
161
181
|
if (!error) return;
|
|
162
182
|
const pending = this.pending.get(requestId);
|
|
163
|
-
if (pending) { clearTimeout(timer); this.pending.delete(requestId); reject(new Error('
|
|
183
|
+
if (pending) { clearTimeout(timer); this.pending.delete(requestId); reject(new Error(msg('error.screenshot'))); child.kill(); }
|
|
164
184
|
});
|
|
165
|
-
} catch { clearTimeout(timer); this.pending.delete(requestId); reject(new Error('
|
|
185
|
+
} catch { clearTimeout(timer); this.pending.delete(requestId); reject(new Error(msg('error.screenshot'))); child.kill(); }
|
|
166
186
|
});
|
|
167
187
|
}
|
|
168
188
|
|
|
169
189
|
close() {
|
|
170
190
|
if (this.closing) return this.closing;
|
|
171
191
|
this.closed = true; this.rejectStarting?.();
|
|
172
|
-
for (const pending of this.pending.values()) { clearTimeout(pending.timer); pending.reject(new Error('
|
|
192
|
+
for (const pending of this.pending.values()) { clearTimeout(pending.timer); pending.reject(new Error(msg('error.closed'))); }
|
|
173
193
|
this.pending.clear();
|
|
174
194
|
const child = this.child;
|
|
175
195
|
this.closing = child ? new Promise(resolve => {
|
package/src/devices/actions.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { message as msg } from '../shared/i18n.mjs';
|
|
1
2
|
import { execFile } from 'node:child_process';
|
|
2
3
|
import { promisify } from 'node:util';
|
|
3
4
|
import { webUrl } from '../shared/devices.mjs';
|
|
@@ -15,9 +16,9 @@ export async function systemAction(action, value, { platform = process.platform,
|
|
|
15
16
|
const result = await execute('/usr/bin/osascript', ['-l', 'JavaScript', '-e',
|
|
16
17
|
"ObjC.import('CoreServices'); ObjC.unwrap(ObjC.castRefToObject($.LSCopyDefaultHandlerForURLScheme($('http'))));"], commandOptions);
|
|
17
18
|
const browser = result.stdout.trim();
|
|
18
|
-
if (!/^[a-z\d][a-z\d.-]+$/i.test(browser)) throw new Error('
|
|
19
|
+
if (!/^[a-z\d][a-z\d.-]+$/i.test(browser)) throw new Error(msg('error.browser'));
|
|
19
20
|
args = ['-n', '-b', browser, '--args', url];
|
|
20
|
-
} catch { throw new Error('
|
|
21
|
+
} catch { throw new Error(msg('error.browser')); }
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
else if (platform === 'win32') { file = 'rundll32.exe'; args = ['url.dll,FileProtocolHandler', url]; }
|
|
@@ -29,7 +30,7 @@ export async function systemAction(action, value, { platform = process.platform,
|
|
|
29
30
|
backspace: 'tell application "System Events" to key code 51',
|
|
30
31
|
openAi: 'tell application "DeepSeek Harness" to activate',
|
|
31
32
|
};
|
|
32
|
-
if (!scripts[action]) throw new Error('
|
|
33
|
+
if (!scripts[action]) throw new Error(msg('error.action'));
|
|
33
34
|
args = ['-e', scripts[action]];
|
|
34
35
|
} else if (platform === 'win32') {
|
|
35
36
|
file = 'powershell.exe';
|
|
@@ -44,9 +45,9 @@ export async function systemAction(action, value, { platform = process.platform,
|
|
|
44
45
|
// without any window, so the Electron overrides must be stripped before handing off.
|
|
45
46
|
openAi: "$p=Get-Process -Name 'DeepSeek Harness' -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowHandle -ne 0 } | Select-Object -First 1; if($p){ Add-Type -Namespace Win -Name Native -MemberDefinition '[DllImport(\"user32.dll\")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);[DllImport(\"user32.dll\")] public static extern bool SetForegroundWindow(IntPtr hWnd);'; [Win.Native]::ShowWindow($p.MainWindowHandle, 9) | Out-Null; if([Win.Native]::SetForegroundWindow($p.MainWindowHandle)){ exit 0 } }; Remove-Item Env:\\ELECTRON_RUN_AS_NODE, Env:\\ELECTRON_NO_ATTACH_CONSOLE, Env:\\ELECTRON_NO_ASAR -ErrorAction SilentlyContinue; $exe=(Get-Process -Name 'DeepSeek Harness' -ErrorAction SilentlyContinue | Select-Object -First 1).Path; if($exe){ Start-Process -FilePath $exe -ArgumentList 'dsh://open'; exit 0 }; Start-Process -FilePath rundll32.exe -ArgumentList 'url.dll,FileProtocolHandler','dsh://open' -WindowStyle Hidden; exit 0",
|
|
46
47
|
};
|
|
47
|
-
if (!scripts[action]) throw new Error('
|
|
48
|
+
if (!scripts[action]) throw new Error(msg('error.action'));
|
|
48
49
|
args = ['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(scripts[action], 'utf16le').toString('base64')];
|
|
49
|
-
} else throw new Error('
|
|
50
|
+
} else throw new Error(msg('error.action'));
|
|
50
51
|
try { await execute(file, args, commandOptions); }
|
|
51
|
-
catch { throw new Error(action === 'openUrl' ? '
|
|
52
|
+
catch { throw new Error(action === 'openUrl' ? msg('error.browser') : msg('error.action')); }
|
|
52
53
|
}
|
package/src/devices/config.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { message as msg } from '../shared/i18n.mjs';
|
|
1
2
|
import { z } from 'zod';
|
|
2
|
-
const query = z.partialRecord(z.enum(['lid', 'lanid', 'role', 'language', 'accent', 'rlang']), z.union([z.string().max(128), z.number()])).refine(value => Object.keys(value).length > 0, '
|
|
3
|
+
const query = z.partialRecord(z.enum(['lid', 'lanid', 'role', 'language', 'accent', 'rlang']), z.union([z.string().max(128), z.number()])).refine(value => Object.keys(value).length > 0, msg('error.language'));
|
|
3
4
|
export const pluginConfigSchema = z.object({
|
|
4
5
|
native: z.object({ libraryPath: z.string().min(1).max(4096).optional() }).strict().optional(),
|
|
5
6
|
dpiLevels: z.partialRecord(z.enum(['800', '1200', '1600', '2400']), z.number().int().min(0).max(255)).optional(),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { message as msg } from '../shared/i18n.mjs';
|
|
1
2
|
import { execFile } from 'node:child_process';
|
|
2
3
|
import { promisify } from 'node:util';
|
|
3
4
|
|
|
@@ -44,9 +45,9 @@ export async function diagnoseUsb(workerPid, { platform = process.platform, exec
|
|
|
44
45
|
const result = parseUsbOwners(stdout, workerPid);
|
|
45
46
|
if (result.owners.length) {
|
|
46
47
|
const names = [...new Set(result.owners.map(item => item.name))].join('、');
|
|
47
|
-
return
|
|
48
|
+
return msg('status.occupied', { names });
|
|
48
49
|
}
|
|
49
50
|
return result.receiverPresent
|
|
50
|
-
? '
|
|
51
|
-
: '
|
|
51
|
+
? msg('status.receiver')
|
|
52
|
+
: msg('status.searching');
|
|
52
53
|
}
|