@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.
Files changed (52) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/CHANGELOG.zh.md +16 -1
  3. package/README.md +15 -13
  4. package/README.zh.md +2 -0
  5. package/dist/build.json +1 -1
  6. package/dist/client.js +1506 -109
  7. package/docs/contributing/development.md +4 -2
  8. package/docs/specs/ci-cd.md +5 -4
  9. package/docs/specs/multilingual.md +98 -0
  10. package/locale/de.json +7 -0
  11. package/locale/en.json +7 -0
  12. package/locale/es.json +7 -0
  13. package/locale/fr.json +7 -0
  14. package/locale/ja.json +7 -0
  15. package/locale/pt.json +7 -0
  16. package/locale/ru.json +7 -0
  17. package/locale/zh.json +7 -0
  18. package/native/desktop/VOICE_SOURCE.json +2 -2
  19. package/native/desktop/VoicePanel.cs +70 -33
  20. package/native/desktop/VoicePanel.swift +58 -21
  21. package/native/desktop/darwin-arm64/Sonicloud Voice.app/Contents/MacOS/sonicloud-voice +0 -0
  22. package/package.json +5 -3
  23. package/src/asr/auth.mjs +9 -8
  24. package/src/asr/config.mjs +1 -1
  25. package/src/asr/stream.mjs +25 -24
  26. package/src/desktop/presentation.mjs +17 -11
  27. package/src/desktop/screenshot-worker.mjs +33 -32
  28. package/src/desktop/screenshot.mjs +25 -24
  29. package/src/devices/actions.mjs +7 -6
  30. package/src/devices/config.mjs +2 -1
  31. package/src/devices/diagnostics.mjs +4 -3
  32. package/src/devices/manager.mjs +41 -40
  33. package/src/devices/native-worker.mjs +4 -3
  34. package/src/devices/native.mjs +9 -8
  35. package/src/devices/queue.mjs +4 -3
  36. package/src/devices/recognition.mjs +5 -4
  37. package/src/devices/store.mjs +3 -2
  38. package/src/devices/translate.mjs +11 -10
  39. package/src/host/ai-conversation.mjs +8 -7
  40. package/src/host/index.mjs +7 -2
  41. package/src/host/locale.mjs +42 -0
  42. package/src/shared/devices.mjs +13 -12
  43. package/src/shared/i18n.mjs +47 -0
  44. package/src/shared/locales/de.json +155 -0
  45. package/src/shared/locales/en.json +155 -0
  46. package/src/shared/locales/es.json +155 -0
  47. package/src/shared/locales/fr.json +155 -0
  48. package/src/shared/locales/ja.json +155 -0
  49. package/src/shared/locales/pt.json +155 -0
  50. package/src/shared/locales/ru.json +155 -0
  51. package/src/shared/locales/zh.json +155 -0
  52. 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('截图组件返回无效事件,请重试'); return; }
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('截图配置失败,请重试')); return; }
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
- ? '请先在“声云设备”中为 screenhelper 授权屏幕录制,再重新检查权限'
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('当前插件尚未接入截图文字识别和 Word 导出,请使用复制、保存或贴图');
75
+ notice(msg('error.screenshotExport'));
75
76
  }
76
- }).catch(() => { connected = false; finishConnection(new Error('截图组件通信失败,请重试')); notice('截图组件通信失败,请重试'); });
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('截图进程连接超时,请重试')), 6500) };
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('截图权限检查超时,请先完成系统授权窗口后重试'), undefined, request), 2500) };
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('截图权限检查失败,请重试'), undefined, request);
128
- }, () => finishState(new Error('截图权限检查失败,请重试'), undefined, request));
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('截图组件未返回 macOS 权限状态,请更新插件');
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('请先在“声云设备”中为 screenhelper 授权屏幕录制,再重新检查权限');
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('当前平台不支持截图,请使用 Windows x64 或 Apple 芯片 Mac');
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('截图服务启动超时,请重试'); child.kill(); }, this.startTimeoutMs);
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('截图组件加载失败,请检查系统架构、运行依赖并重新安装插件'); child.kill(); }
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('截图服务启动失败,请检查插件安装并重试'); child.kill(); });
131
- child.once('disconnect', () => { fail(this.closed ? '截图服务已关闭' : '截图服务连接已断开,请重试'); if (!this.closed) child.kill(); });
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('截图服务响应超时,请重试')); child.kill();
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('截图指令发送失败,请重试')); child.kill(); }
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('截图指令发送失败,请重试')); child.kill(); }
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 => {
@@ -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
  }
@@ -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 `鼠标 USB 数据接口被 ${names} 占用,请退出该应用;释放后会自动重试连接。`;
48
+ return msg('status.occupied', { names });
48
49
  }
49
50
  return result.receiverPresent
50
- ? '已检测到 2.4G 接收器,正在等待鼠标响应。请确认鼠标已开机并切到 2.4G 模式。'
51
- : '正在查找智能鼠标,请插入 2.4G 接收器或连接蓝牙。';
51
+ ? msg('status.receiver')
52
+ : msg('status.searching');
52
53
  }