@sonicloud/dsh-sonicloud-device 0.1.3 → 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.
- package/CHANGELOG.md +16 -1
- package/CHANGELOG.zh.md +16 -1
- package/README.md +15 -13
- package/README.zh.md +2 -0
- package/dist/build.json +1 -1
- package/dist/client.js +1506 -109
- package/docs/contributing/development.md +4 -2
- package/docs/specs/ci-cd.md +5 -4
- package/docs/specs/multilingual.md +98 -0
- 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/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 +17 -11
- package/src/desktop/screenshot-worker.mjs +33 -32
- package/src/desktop/screenshot.mjs +25 -24
- 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 +41 -40
- 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 +7 -2
- package/src/host/locale.mjs +42 -0
- package/src/shared/devices.mjs +13 -12
- package/src/shared/i18n.mjs +47 -0
- package/src/shared/locales/de.json +155 -0
- package/src/shared/locales/en.json +155 -0
- package/src/shared/locales/es.json +155 -0
- package/src/shared/locales/fr.json +155 -0
- package/src/shared/locales/ja.json +155 -0
- package/src/shared/locales/pt.json +155 -0
- package/src/shared/locales/ru.json +155 -0
- package/src/shared/locales/zh.json +155 -0
- package/src/shared/remote.mjs +2 -1
|
@@ -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
|
|
|
@@ -30,18 +31,18 @@ function finishState(error, value, request = stateRequest) {
|
|
|
30
31
|
stateRequest = undefined; clearTimeout(request.timer);
|
|
31
32
|
if (error) request.reject(error); else request.resolve(value);
|
|
32
33
|
}
|
|
33
|
-
const errorMessage = rc => rc === -3 ? '
|
|
34
|
-
: rc === -2 ? '
|
|
34
|
+
const errorMessage = rc => rc === -3 ? msg('error.busy')
|
|
35
|
+
: rc === -2 ? msg('error.screenshot') : msg('error.screenshot');
|
|
35
36
|
|
|
36
37
|
// 原生线程回调只保留事件文本并排队;所有 FFI 调用离开回调后异步执行。
|
|
37
38
|
function queueEvent(json) {
|
|
38
39
|
const text = String(json || '');
|
|
39
40
|
setImmediate(() => {
|
|
40
|
-
let event; try { event = JSON.parse(text); } catch { notice('
|
|
41
|
+
let event; try { event = JSON.parse(text); } catch { notice(msg('error.screenshot')); return; }
|
|
41
42
|
if (event.type === 'disconnected') {
|
|
42
43
|
connected = false; capabilities = new Set();
|
|
43
|
-
finishState(new Error('
|
|
44
|
-
finishConnection(new Error('
|
|
44
|
+
finishState(new Error(msg('error.permission')));
|
|
45
|
+
finishConnection(new Error(msg('error.screenshot')));
|
|
45
46
|
disconnected?.();
|
|
46
47
|
}
|
|
47
48
|
if (closing) return;
|
|
@@ -52,7 +53,7 @@ function queueEvent(json) {
|
|
|
52
53
|
}
|
|
53
54
|
if (event.type === 'connected') {
|
|
54
55
|
const rc = await call(api.config, handle, JSON.stringify({ ocr_visible: false, trans_enabled: false }));
|
|
55
|
-
if (rc !== 0) { connected = false; finishConnection(new Error('
|
|
56
|
+
if (rc !== 0) { connected = false; finishConnection(new Error(msg('error.screenshot'))); return; }
|
|
56
57
|
connected = true; finishConnection();
|
|
57
58
|
} else if (event.type === 'hello_ack') {
|
|
58
59
|
capabilities = new Set(Array.isArray(event.capabilities) ? event.capabilities : []);
|
|
@@ -63,17 +64,17 @@ function queueEvent(json) {
|
|
|
63
64
|
} else if (event.type === 'connect_failed') {
|
|
64
65
|
connected = false;
|
|
65
66
|
const message = event.code === 'stale_helper_refused'
|
|
66
|
-
? '
|
|
67
|
+
? msg('error.screenshotBusy') : msg('error.screenshot');
|
|
67
68
|
if (connection) finishConnection(new Error(message)); else notice(message);
|
|
68
69
|
} else if (event.type === 'error' || event.type === 'word_failed') {
|
|
69
70
|
notice(event.code === 'permission_screen_required'
|
|
70
|
-
? '
|
|
71
|
-
: ['permission_busy', 'permission_request_busy'].includes(event.code) ? '
|
|
72
|
-
: '
|
|
71
|
+
? msg('error.screenPermission')
|
|
72
|
+
: ['permission_busy', 'permission_request_busy'].includes(event.code) ? msg('error.screenshotBusy')
|
|
73
|
+
: msg('error.permission'));
|
|
73
74
|
} else if (['word_started', 'word_result', 'ocr_requested'].includes(event.type)) {
|
|
74
|
-
notice('
|
|
75
|
+
notice(msg('error.screenshotExport'));
|
|
75
76
|
}
|
|
76
|
-
}).catch(() => { connected = false; finishConnection(new Error('
|
|
77
|
+
}).catch(() => { connected = false; finishConnection(new Error(msg('error.screenshot'))); notice(msg('error.screenshot')); });
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -92,46 +93,46 @@ async function initialize() {
|
|
|
92
93
|
shutdown: library.func('int sct_shutdown(void *h, const char *policy)'),
|
|
93
94
|
};
|
|
94
95
|
handle = await call(api.create);
|
|
95
|
-
if (!handle) throw new Error('
|
|
96
|
+
if (!handle) throw new Error(msg('error.screenshot'));
|
|
96
97
|
const eventProto = koffi.proto('void SonicloudScreenshotEvent(void *user, const char *json, const uint8_t *payload, int len)');
|
|
97
98
|
const logProto = koffi.proto('void SonicloudScreenshotLog(void *user, int level, const char *message)');
|
|
98
99
|
callbacks.push(koffi.register((_user, json) => queueEvent(json), koffi.pointer(eventProto)));
|
|
99
100
|
callbacks.push(koffi.register(() => {}, koffi.pointer(logProto)));
|
|
100
101
|
if (await call(api.setEvent, handle, callbacks[0], null) !== 0 ||
|
|
101
102
|
await call(api.setLog, handle, callbacks[1], null) !== 0 ||
|
|
102
|
-
await call(api.helper, handle, helperPath) !== 0) throw new Error('
|
|
103
|
+
await call(api.helper, handle, helperPath) !== 0) throw new Error(msg('error.screenshot'));
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
async function ensureConnected() {
|
|
106
|
-
if (closing) throw new Error('
|
|
107
|
+
if (closing) throw new Error(msg('error.closed'));
|
|
107
108
|
if (connected) return;
|
|
108
109
|
if (!connection) {
|
|
109
110
|
let resolve, reject;
|
|
110
111
|
const promise = new Promise((yes, no) => { resolve = yes; reject = no; });
|
|
111
|
-
connection = { promise, resolve, reject, timer: setTimeout(() => finishConnection(new Error('
|
|
112
|
+
connection = { promise, resolve, reject, timer: setTimeout(() => finishConnection(new Error(msg('error.timeout'))), 6500) };
|
|
112
113
|
call(api.connect, handle, 5000).then(rc => { if (rc !== 0) finishConnection(new Error(errorMessage(rc))); },
|
|
113
|
-
() => finishConnection(new Error('
|
|
114
|
+
() => finishConnection(new Error(msg('error.screenshot'))));
|
|
114
115
|
}
|
|
115
116
|
return connection.promise;
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
async function queryState() {
|
|
119
|
-
if (closing) throw new Error('
|
|
120
|
+
if (closing) throw new Error(msg('error.closed'));
|
|
120
121
|
if (stateRequest) return stateRequest.promise;
|
|
121
122
|
let resolve, reject;
|
|
122
123
|
const promise = new Promise((yes, no) => { resolve = yes; reject = no; });
|
|
123
124
|
const request = { promise, resolve, reject,
|
|
124
|
-
timer: setTimeout(() => finishState(new Error('
|
|
125
|
+
timer: setTimeout(() => finishState(new Error(msg('error.timeout')), undefined, request), 2500) };
|
|
125
126
|
stateRequest = request;
|
|
126
127
|
call(api.query, handle).then(rc => {
|
|
127
|
-
if (rc !== 0) finishState(new Error('
|
|
128
|
-
}, () => finishState(new Error('
|
|
128
|
+
if (rc !== 0) finishState(new Error(msg('error.permission')), undefined, request);
|
|
129
|
+
}, () => finishState(new Error(msg('error.permission')), undefined, request));
|
|
129
130
|
return promise;
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
function permissionView(state) {
|
|
133
134
|
if (typeof state.perm_screen !== 'boolean' || typeof state.perm_a11y !== 'boolean')
|
|
134
|
-
throw new Error('
|
|
135
|
+
throw new Error(msg('error.permission'));
|
|
135
136
|
return { supported: true, screenRecording: state.perm_screen, accessibility: state.perm_a11y,
|
|
136
137
|
helperApp: typeof state.helper_app === 'string' ? state.helper_app.slice(0, 4096) : '' };
|
|
137
138
|
}
|
|
@@ -145,13 +146,13 @@ async function stopHelper() {
|
|
|
145
146
|
});
|
|
146
147
|
try {
|
|
147
148
|
const rc = await call(api.shutdown, handle, 'close_now');
|
|
148
|
-
if (rc !== 0) throw new Error('
|
|
149
|
-
if (!await stopped) throw new Error('
|
|
149
|
+
if (rc !== 0) throw new Error(msg('error.permission'));
|
|
150
|
+
if (!await stopped) throw new Error(msg('error.permission'));
|
|
150
151
|
} finally { clearTimeout(timer); disconnected = undefined; }
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
async function permissions(action) {
|
|
154
|
-
if (!['check', 'screen', 'accessibility', 'refresh'].includes(action)) throw new Error('
|
|
155
|
+
if (!['check', 'screen', 'accessibility', 'refresh'].includes(action)) throw new Error(msg('error.permission'));
|
|
155
156
|
if (process.platform !== 'darwin') return { supported: false, screenRecording: true, accessibility: true, helperApp: '' };
|
|
156
157
|
let state = await queryState();
|
|
157
158
|
let view = permissionView(state);
|
|
@@ -160,10 +161,10 @@ async function permissions(action) {
|
|
|
160
161
|
state = await queryState(); view = permissionView(state);
|
|
161
162
|
}
|
|
162
163
|
if (action === 'screen' || action === 'accessibility') {
|
|
163
|
-
if (!idle(state)) throw new Error('
|
|
164
|
-
if (!capabilities.has('permission_preflight')) throw new Error('
|
|
164
|
+
if (!idle(state)) throw new Error(msg('error.screenshotBusy'));
|
|
165
|
+
if (!capabilities.has('permission_preflight')) throw new Error(msg('error.permission'));
|
|
165
166
|
const rc = await call(api.config, handle, JSON.stringify({ permission_request: action }));
|
|
166
|
-
if (rc !== 0) throw new Error('
|
|
167
|
+
if (rc !== 0) throw new Error(msg('error.permission'));
|
|
167
168
|
// 系统授权由用户完成;写入请求只代表已受理,不能当作已授权。
|
|
168
169
|
}
|
|
169
170
|
return view;
|
|
@@ -175,14 +176,14 @@ process.on('message', message => {
|
|
|
175
176
|
commands = commands.then(async () => {
|
|
176
177
|
await initialized;
|
|
177
178
|
await ensureConnected();
|
|
178
|
-
if (closing) throw new Error('
|
|
179
|
+
if (closing) throw new Error(msg('error.closed'));
|
|
179
180
|
if (message.command === 'permissions') {
|
|
180
181
|
const value = await permissions(message.action ?? 'check');
|
|
181
182
|
send({ type: 'reply', requestId: message.requestId, ok: true, value });
|
|
182
183
|
return;
|
|
183
184
|
}
|
|
184
185
|
if (process.platform === 'darwin' && !permissionView(await queryState()).screenRecording)
|
|
185
|
-
throw new Error('
|
|
186
|
+
throw new Error(msg('error.screenPermission'));
|
|
186
187
|
const trigger = typeof message.trigger === 'string' ? message.trigger.replace(/[^a-zA-Z0-9_.-]/g, '_').slice(0, 64) : 'ui';
|
|
187
188
|
const rc = await call(api.capture, handle, trigger || 'ui');
|
|
188
189
|
if (rc !== 0) throw new Error(errorMessage(rc));
|
|
@@ -198,8 +199,8 @@ initialized.then(() => { if (!closing) send({ type: 'ready' }); }).catch(() => {
|
|
|
198
199
|
function close() {
|
|
199
200
|
if (closePromise) return closePromise;
|
|
200
201
|
closing = true; connected = false;
|
|
201
|
-
finishConnection(new Error('
|
|
202
|
-
finishState(new Error('
|
|
202
|
+
finishConnection(new Error(msg('error.closed')));
|
|
203
|
+
finishState(new Error(msg('error.closed')));
|
|
203
204
|
closePromise = (async () => {
|
|
204
205
|
await initialized.catch(() => {});
|
|
205
206
|
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); }
|
|
@@ -72,7 +73,7 @@ export class ScreenshotService extends EventEmitter {
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
start() {
|
|
75
|
-
if (this.closed) return Promise.reject(new Error('
|
|
76
|
+
if (this.closed) return Promise.reject(new Error(msg('error.closed')));
|
|
76
77
|
if (this.starting) return this.starting;
|
|
77
78
|
const attempt = this.startWorker().catch(error => { if (this.starting === attempt) this.starting = undefined; throw error; });
|
|
78
79
|
this.starting = attempt;
|
|
@@ -81,7 +82,7 @@ export class ScreenshotService extends EventEmitter {
|
|
|
81
82
|
|
|
82
83
|
async startWorker() {
|
|
83
84
|
const target = `${this.platform}-${this.arch}`;
|
|
84
|
-
if (!['win32-x64', 'darwin-arm64'].includes(target)) throw new Error('
|
|
85
|
+
if (!['win32-x64', 'darwin-arm64'].includes(target)) throw new Error(msg('error.screenshot'));
|
|
85
86
|
let paths = { libraryPath: this.libraryPath, helperPath: this.helperPath };
|
|
86
87
|
if (!paths.libraryPath || !paths.helperPath) {
|
|
87
88
|
try {
|
|
@@ -90,19 +91,19 @@ export class ScreenshotService extends EventEmitter {
|
|
|
90
91
|
helperPath: join(nativeRoot, target, 'screenhelper.exe'),
|
|
91
92
|
};
|
|
92
93
|
paths = { libraryPath: paths.libraryPath ?? defaults.libraryPath, helperPath: paths.helperPath ?? defaults.helperPath };
|
|
93
|
-
} catch { throw new Error('
|
|
94
|
+
} catch { throw new Error(msg('error.permission')); }
|
|
94
95
|
}
|
|
95
|
-
if (this.closed) throw new Error('
|
|
96
|
-
if (!this.exists(paths.libraryPath) || !this.exists(paths.helperPath)) throw new Error('
|
|
96
|
+
if (this.closed) throw new Error(msg('error.closed'));
|
|
97
|
+
if (!this.exists(paths.libraryPath) || !this.exists(paths.helperPath)) throw new Error(msg('error.screenshot'));
|
|
97
98
|
let child;
|
|
98
99
|
try {
|
|
99
100
|
child = this.launch(fileURLToPath(new URL('./screenshot-worker.mjs', import.meta.url)),
|
|
100
101
|
[paths.libraryPath, paths.helperPath], { stdio: ['ignore', 'ignore', 'ignore', 'ipc'], execArgv: [], windowsHide: true });
|
|
101
|
-
} catch { throw new Error('
|
|
102
|
+
} catch { throw new Error(msg('error.screenshot')); }
|
|
102
103
|
this.child = child;
|
|
103
104
|
return new Promise((resolve, reject) => {
|
|
104
105
|
let ready = false, failed = false;
|
|
105
|
-
const timer = setTimeout(() => { fail('
|
|
106
|
+
const timer = setTimeout(() => { fail(msg('error.timeout')); child.kill(); }, this.startTimeoutMs);
|
|
106
107
|
const fail = message => {
|
|
107
108
|
if (failed) return;
|
|
108
109
|
failed = true; clearTimeout(timer);
|
|
@@ -115,7 +116,7 @@ export class ScreenshotService extends EventEmitter {
|
|
|
115
116
|
child.on('message', message => {
|
|
116
117
|
if (this.child !== child || !message || typeof message !== 'object') return;
|
|
117
118
|
if (message.type === 'ready') { clearTimeout(timer); ready = true; resolve(); }
|
|
118
|
-
else if (message.type === 'fatal') { fail('
|
|
119
|
+
else if (message.type === 'fatal') { fail(msg('error.screenshot')); child.kill(); }
|
|
119
120
|
else if (message.type === 'notice') { if (!this.closed && typeof message.message === 'string') this.emit('notice', message.message); }
|
|
120
121
|
else if (message.type === 'event') { if (!this.closed && message.event && typeof message.event.type === 'string') this.emit('event', message.event); }
|
|
121
122
|
else if (message.type === 'reply') {
|
|
@@ -123,53 +124,53 @@ export class ScreenshotService extends EventEmitter {
|
|
|
123
124
|
if (!pending) return;
|
|
124
125
|
clearTimeout(pending.timer); this.pending.delete(message.requestId);
|
|
125
126
|
if (message.ok) pending.resolve(message.value ?? true);
|
|
126
|
-
else pending.reject(new Error(message.message || '
|
|
127
|
+
else pending.reject(new Error(message.message || msg('error.screenshot')));
|
|
127
128
|
}
|
|
128
129
|
});
|
|
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('
|
|
130
|
+
child.once('exit', () => fail(this.closed ? msg('error.closed') : msg('error.screenshot')));
|
|
131
|
+
child.once('error', () => { fail(msg('error.screenshot')); child.kill(); });
|
|
132
|
+
child.once('disconnect', () => { fail(this.closed ? msg('error.closed') : msg('error.screenshot')); if (!this.closed) child.kill(); });
|
|
133
|
+
this.rejectStarting = () => { clearTimeout(timer); reject(new Error(msg('error.closed'))); };
|
|
133
134
|
});
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
capture(trigger = 'ui') { return this.command('capture', { trigger }); }
|
|
137
138
|
|
|
138
139
|
async permissions(action = 'check') {
|
|
139
|
-
if (!['check', 'screen', 'accessibility', 'refresh'].includes(action)) throw new Error('
|
|
140
|
-
if (this.closed) throw new Error('
|
|
140
|
+
if (!['check', 'screen', 'accessibility', 'refresh'].includes(action)) throw new Error(msg('error.permission'));
|
|
141
|
+
if (this.closed) throw new Error(msg('error.closed'));
|
|
141
142
|
if (this.platform !== 'darwin') return { supported: false, screenRecording: true, accessibility: true, helperApp: '' };
|
|
142
143
|
const state = await this.command('permissions', { action }, Math.max(this.timeoutMs, 20000));
|
|
143
144
|
if (!state || typeof state !== 'object' || state.supported !== true || typeof state.screenRecording !== 'boolean'
|
|
144
|
-
|| typeof state.accessibility !== 'boolean' || typeof state.helperApp !== 'string') throw new Error('
|
|
145
|
+
|| typeof state.accessibility !== 'boolean' || typeof state.helperApp !== 'string') throw new Error(msg('error.permission'));
|
|
145
146
|
return state;
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
async command(command, fields = {}, timeoutMs = this.timeoutMs) {
|
|
149
150
|
await this.start();
|
|
150
|
-
if (this.closed) throw new Error('
|
|
151
|
+
if (this.closed) throw new Error(msg('error.closed'));
|
|
151
152
|
const child = this.child;
|
|
152
|
-
if (!child?.connected) throw new Error('
|
|
153
|
+
if (!child?.connected) throw new Error(msg('error.screenshot'));
|
|
153
154
|
const requestId = ++this.sequence;
|
|
154
155
|
return new Promise((resolve, reject) => {
|
|
155
156
|
const timer = setTimeout(() => {
|
|
156
|
-
this.pending.delete(requestId); reject(new Error('
|
|
157
|
+
this.pending.delete(requestId); reject(new Error(msg('error.timeout'))); child.kill();
|
|
157
158
|
}, timeoutMs);
|
|
158
159
|
this.pending.set(requestId, { resolve, reject, timer });
|
|
159
160
|
try {
|
|
160
161
|
child.send({ command, ...fields, requestId }, error => {
|
|
161
162
|
if (!error) return;
|
|
162
163
|
const pending = this.pending.get(requestId);
|
|
163
|
-
if (pending) { clearTimeout(timer); this.pending.delete(requestId); reject(new Error('
|
|
164
|
+
if (pending) { clearTimeout(timer); this.pending.delete(requestId); reject(new Error(msg('error.screenshot'))); child.kill(); }
|
|
164
165
|
});
|
|
165
|
-
} catch { clearTimeout(timer); this.pending.delete(requestId); reject(new Error('
|
|
166
|
+
} catch { clearTimeout(timer); this.pending.delete(requestId); reject(new Error(msg('error.screenshot'))); child.kill(); }
|
|
166
167
|
});
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
close() {
|
|
170
171
|
if (this.closing) return this.closing;
|
|
171
172
|
this.closed = true; this.rejectStarting?.();
|
|
172
|
-
for (const pending of this.pending.values()) { clearTimeout(pending.timer); pending.reject(new Error('
|
|
173
|
+
for (const pending of this.pending.values()) { clearTimeout(pending.timer); pending.reject(new Error(msg('error.closed'))); }
|
|
173
174
|
this.pending.clear();
|
|
174
175
|
const child = this.child;
|
|
175
176
|
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
|
}
|