better-dsh-pet 0.3.1 → 0.3.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/README.md +132 -5
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/scripts/download-sensevoice.mjs +47 -16
- package/scripts/ensure-electron.mjs +48 -18
package/README.md
CHANGED
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
- [✨ 功能特性](#-功能特性)
|
|
32
32
|
- [📸 效果预览](#-效果预览)
|
|
33
33
|
- [🚀 快速开始](#-快速开始)
|
|
34
|
+
- [⬇️ 下载说明](#️-下载说明)
|
|
34
35
|
- [🖱️ 使用指南](#️-使用指南)
|
|
35
36
|
- [⚙️ 配置说明](#️-配置说明)
|
|
36
37
|
- [🎭 情绪系统](#-情绪系统)
|
|
@@ -276,7 +277,7 @@ dsh plugin --profile web add better-dsh-pet
|
|
|
276
277
|
> 如果刚发布新版本不到 24 小时,pnpm 11 的 `minimumReleaseAge` 安全策略可能不会自动选最新版,而是退回旧版。此时请指定精确版本安装:
|
|
277
278
|
>
|
|
278
279
|
> ```bash
|
|
279
|
-
> dsh plugin --profile web add better-dsh-pet@0.3.
|
|
280
|
+
> dsh plugin --profile web add better-dsh-pet@0.3.3
|
|
280
281
|
> ```
|
|
281
282
|
>
|
|
282
283
|
> pnpm 会自动把该版本加入 `minimumReleaseAgeExclude` 并完成安装;也可以等待 24 小时后直接用上面的普通命令。
|
|
@@ -299,6 +300,112 @@ dsh plugin --profile web remove better-dsh-pet
|
|
|
299
300
|
|
|
300
301
|
---
|
|
301
302
|
|
|
303
|
+
## ⬇️ 下载说明
|
|
304
|
+
|
|
305
|
+
better-dsh-pet 有两类下载:
|
|
306
|
+
|
|
307
|
+
1. **Electron**:桌宠窗口运行环境,首次启动自动下载;
|
|
308
|
+
2. **SenseVoice 语音模型**:本地离线语音识别模型,需要手动下载(可选增强)。
|
|
309
|
+
|
|
310
|
+
> 路径会自动识别 DSH 主目录:`DSH_HOME` 环境变量 → 从插件安装路径自动推断 → 默认 `~/.dsh`。所以在不同电脑、不同 DSH 安装目录下都能保持一致。
|
|
311
|
+
|
|
312
|
+
### Electron 自动下载
|
|
313
|
+
|
|
314
|
+
- 首次启动 DSH / 桌宠时,如果找不到 Electron,会自动下载到:
|
|
315
|
+
```text
|
|
316
|
+
C:\Users\Administrator\.dsh\electron\electron.exe
|
|
317
|
+
```
|
|
318
|
+
- 下载进度会显示在:
|
|
319
|
+
- 终端(如果你用 `dsh web` 启动且能看到宿主输出)
|
|
320
|
+
- 日志文件:`C:\Users\Administrator\.dsh\logs\better-dsh-pet-electron.log`
|
|
321
|
+
- 查看最新进度:
|
|
322
|
+
```powershell
|
|
323
|
+
Get-Content "C:\Users\Administrator\.dsh\logs\better-dsh-pet-electron.log" -Tail 20
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
手动触发下载(可在终端直接看进度):
|
|
327
|
+
|
|
328
|
+
```powershell
|
|
329
|
+
node "C:\Users\Administrator\.dsh\profiles\web\node_modules\better-dsh-pet\scripts\ensure-electron.mjs"
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### SenseVoice 语音模型下载
|
|
333
|
+
|
|
334
|
+
语音模型**不会自动下载**,需要手动执行一次:
|
|
335
|
+
|
|
336
|
+
```powershell
|
|
337
|
+
cd C:\Users\Administrator\.dsh\profiles\web\node_modules\better-dsh-pet
|
|
338
|
+
npm run download:sensevoice
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
脚本会自动尝试多个镜像源,哪个可用就用哪个:
|
|
342
|
+
|
|
343
|
+
```text
|
|
344
|
+
1. GitHub 官方
|
|
345
|
+
2. ghproxy.net
|
|
346
|
+
3. ghfast.top
|
|
347
|
+
4. gh-proxy.com
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
下载进度显示在终端,也会写入:
|
|
351
|
+
|
|
352
|
+
```text
|
|
353
|
+
C:\Users\Administrator\.dsh\logs\better-dsh-pet-sensevoice.log
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
查看进度:
|
|
357
|
+
|
|
358
|
+
```powershell
|
|
359
|
+
Get-Content "C:\Users\Administrator\.dsh\logs\better-dsh-pet-sensevoice.log" -Tail 20
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
模型下载完成后位于:
|
|
363
|
+
|
|
364
|
+
```text
|
|
365
|
+
C:\Users\Administrator\.dsh\voice\sensevoice\model.int8.onnx
|
|
366
|
+
C:\Users\Administrator\.dsh\voice\sensevoice\tokens.txt
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### 如何判断下载完成
|
|
370
|
+
|
|
371
|
+
| 项目 | 完成标志 |
|
|
372
|
+
|---|---|
|
|
373
|
+
| Electron | `C:\Users\Administrator\.dsh\electron\electron.exe` 存在(约 215MB) |
|
|
374
|
+
| 语音模型 | `C:\Users\Administrator\.dsh\voice\sensevoice\model.int8.onnx` 和 `tokens.txt` 存在 |
|
|
375
|
+
| 下载日志 | 日志末尾出现 `下载完成` |
|
|
376
|
+
|
|
377
|
+
### 重新下载 / 清除缓存
|
|
378
|
+
|
|
379
|
+
```powershell
|
|
380
|
+
# 删除 Electron
|
|
381
|
+
Remove-Item "C:\Users\Administrator\.dsh\electron" -Recurse -Force
|
|
382
|
+
|
|
383
|
+
# 删除语音模型
|
|
384
|
+
Remove-Item "C:\Users\Administrator\.dsh\voice" -Recurse -Force
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
然后重新启动 DSH 或重新运行上面的下载命令。
|
|
388
|
+
|
|
389
|
+
### 下载失败排查
|
|
390
|
+
|
|
391
|
+
- **Electron 解压报“文件正由另一进程使用”**:
|
|
392
|
+
- 先关闭 DSH / 桌宠,再重新下载;
|
|
393
|
+
- 或手动运行 `ensure-electron.mjs`。
|
|
394
|
+
- **语音模型一直 0% / fetch failed**:
|
|
395
|
+
- 脚本会自动切换镜像;
|
|
396
|
+
- 也可以手动指定镜像:
|
|
397
|
+
```powershell
|
|
398
|
+
$env:DSH_VOICE_MODEL_URL = "https://ghfast.top/https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-int8-2024-07-17.tar.bz2"
|
|
399
|
+
npm run download:sensevoice
|
|
400
|
+
```
|
|
401
|
+
- **升级时提示 EPERM**:
|
|
402
|
+
- 先完全退出 DSH / 桌宠,再执行:
|
|
403
|
+
```bash
|
|
404
|
+
dsh plugin --profile web add better-dsh-pet@0.3.3
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
302
409
|
## 🖱️ 使用指南
|
|
303
410
|
|
|
304
411
|
### 右键菜单
|
|
@@ -451,9 +558,9 @@ dsh plugin --profile web remove better-dsh-pet
|
|
|
451
558
|
|
|
452
559
|
### 识别引擎
|
|
453
560
|
|
|
454
|
-
-
|
|
455
|
-
-
|
|
456
|
-
-
|
|
561
|
+
- 默认使用 **Windows 系统语音识别(SAPI)**,开箱即用
|
|
562
|
+
- 可选安装 **SenseVoice** 本地模型 + `sherpa-onnx-node`,完全离线、更准、不上传音频
|
|
563
|
+
- 首次使用 SenseVoice 需要下载模型:
|
|
457
564
|
|
|
458
565
|
```bash
|
|
459
566
|
cd node_modules/better-dsh-pet
|
|
@@ -461,6 +568,7 @@ npm run download:sensevoice
|
|
|
461
568
|
```
|
|
462
569
|
|
|
463
570
|
> 模型会下载到 `~/.dsh/voice/sensevoice`。
|
|
571
|
+
> 下载脚本会自动尝试多个镜像源,详细说明见 [⬇️ 下载说明](#️-下载说明)。
|
|
464
572
|
|
|
465
573
|
### 唤醒词
|
|
466
574
|
|
|
@@ -538,7 +646,8 @@ npm run download:sensevoice
|
|
|
538
646
|
不需要手动安装。
|
|
539
647
|
|
|
540
648
|
- 本插件**不打包 Electron**(npm 包体积限制)
|
|
541
|
-
-
|
|
649
|
+
- 首次启动会自动下载到 `~/.dsh/electron/electron.exe`
|
|
650
|
+
- 下载方式 / 进度查看见 [⬇️ 下载说明](#️-下载说明)
|
|
542
651
|
- 也可以通过环境变量指定:
|
|
543
652
|
```powershell
|
|
544
653
|
$env:DSH_PET_ELECTRON_PATH = "C:\path\to\electron.exe"
|
|
@@ -552,6 +661,24 @@ npm run download:sensevoice
|
|
|
552
661
|
better-dsh-pet: cannot resolve Electron executable.
|
|
553
662
|
```
|
|
554
663
|
|
|
664
|
+
### Q:语音模型怎么下载?
|
|
665
|
+
|
|
666
|
+
语音模型是可选增强,不会自动下载。手动执行:
|
|
667
|
+
|
|
668
|
+
```powershell
|
|
669
|
+
cd C:\Users\Administrator\.dsh\profiles\web\node_modules\better-dsh-pet
|
|
670
|
+
npm run download:sensevoice
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
详细说明见 [⬇️ 下载说明](#️-下载说明)。
|
|
674
|
+
|
|
675
|
+
### Q:没有语音模型能使用语音功能吗?
|
|
676
|
+
|
|
677
|
+
能。
|
|
678
|
+
|
|
679
|
+
- 没有 SenseVoice 模型时,会自动回退到 **Windows 系统语音识别(SAPI)**
|
|
680
|
+
- 下载 SenseVoice 后,会使用更准的本地离线识别
|
|
681
|
+
|
|
555
682
|
### Q:为什么任务识别后没有自动执行?
|
|
556
683
|
|
|
557
684
|
这是故意的。识别为任务后需要你点击「执行任务」按钮确认,防止误识别白烧 Token。
|
package/lib/index.js
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
const PACKAGE_ROOT = resolve(fileURLToPath(new URL('..', import.meta.url)))
|
|
32
32
|
|
|
33
33
|
export const name = 'better-dsh-pet'
|
|
34
|
-
export const inject = ['sessions', 'subagents', 'agents'
|
|
34
|
+
export const inject = ['sessions', 'subagents', 'agents']
|
|
35
35
|
export const CONFIG_ENDPOINT = '/plugins/better-dsh-pet/config'
|
|
36
36
|
export const STATUS_ENDPOINT = '/plugins/better-dsh-pet/status'
|
|
37
37
|
export const CLOSE_ENDPOINT = '/plugins/better-dsh-pet/close'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-dsh-pet",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "A desktop-native pet bubble driven by DeepSeek Harness session events: transparent always-on-top Electron window, status-aware animations, voice chat/wake, real DSH task execution, emotion, festival, balance, pomodoro, roast, and DSH settings card.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -8,15 +8,37 @@
|
|
|
8
8
|
* 下载后放到 ~/.dsh/voice/sensevoice,供宿主端 sherpa-onnx-node 转写使用。
|
|
9
9
|
*/
|
|
10
10
|
import { appendFileSync, createWriteStream, existsSync, mkdirSync, readdirSync, rmSync, renameSync } from 'node:fs'
|
|
11
|
-
import { join, resolve } from 'node:path'
|
|
11
|
+
import { basename, dirname, join, resolve } from 'node:path'
|
|
12
12
|
import { homedir } from 'node:os'
|
|
13
13
|
import { spawnSync } from 'node:child_process'
|
|
14
|
+
import { Transform } from 'node:stream'
|
|
15
|
+
import { pipeline } from 'node:stream/promises'
|
|
14
16
|
import { fileURLToPath } from 'node:url'
|
|
15
17
|
|
|
16
18
|
const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url)))
|
|
17
|
-
|
|
19
|
+
|
|
20
|
+
function inferDshHomeFromPackage() {
|
|
21
|
+
let dir = ROOT
|
|
22
|
+
while (true) {
|
|
23
|
+
if (basename(dir) === 'profiles') return dirname(dir)
|
|
24
|
+
const parent = dirname(dir)
|
|
25
|
+
if (parent === dir) return undefined
|
|
26
|
+
dir = parent
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DSH_HOME = (process.env.DSH_HOME && process.env.DSH_HOME.trim())
|
|
31
|
+
|| inferDshHomeFromPackage()
|
|
32
|
+
|| join(homedir(), '.dsh')
|
|
18
33
|
const MODEL_DIR = process.env.DSH_VOICE_MODEL_DIR || join(DSH_HOME, 'voice', 'sensevoice')
|
|
19
|
-
const
|
|
34
|
+
const DEFAULT_MODEL_URL = 'https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-int8-2024-07-17.tar.bz2'
|
|
35
|
+
const MODEL_URLS = [
|
|
36
|
+
process.env.DSH_VOICE_MODEL_URL,
|
|
37
|
+
DEFAULT_MODEL_URL,
|
|
38
|
+
`https://ghproxy.net/${DEFAULT_MODEL_URL}`,
|
|
39
|
+
`https://ghfast.top/${DEFAULT_MODEL_URL}`,
|
|
40
|
+
`https://gh-proxy.com/${DEFAULT_MODEL_URL}`,
|
|
41
|
+
].filter((url, index, arr) => typeof url === 'string' && url.trim() !== '' && arr.indexOf(url) === index)
|
|
20
42
|
const REQUIRED = ['model.int8.onnx', 'tokens.txt']
|
|
21
43
|
const LOG_FILE = join(DSH_HOME, 'logs', 'better-dsh-pet-sensevoice.log')
|
|
22
44
|
|
|
@@ -47,17 +69,12 @@ async function download(url, dest, label = 'download') {
|
|
|
47
69
|
const response = await fetch(url, { redirect: 'follow' })
|
|
48
70
|
if (!response.ok) throw new Error(`HTTP ${response.status} ${response.statusText}`)
|
|
49
71
|
const total = Number(response.headers.get('content-length')) || 0
|
|
50
|
-
const file = createWriteStream(dest)
|
|
51
|
-
const reader = response.body.getReader()
|
|
52
72
|
let received = 0
|
|
53
73
|
let lastLoggedAt = 0
|
|
54
74
|
let lastPercent = -1
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (done) break
|
|
59
|
-
received += value.length
|
|
60
|
-
file.write(value)
|
|
75
|
+
const progress = new Transform({
|
|
76
|
+
transform(chunk, _encoding, callback) {
|
|
77
|
+
received += chunk.length
|
|
61
78
|
const percent = total ? Math.floor((received / total) * 100) : 0
|
|
62
79
|
const shouldLog = total
|
|
63
80
|
? (percent !== lastPercent && (percent % 10 === 0 || percent === 100))
|
|
@@ -69,10 +86,10 @@ async function download(url, dest, label = 'download') {
|
|
|
69
86
|
const totalMb = total ? ` / ${(total / 1024 / 1024).toFixed(1)}MB` : ''
|
|
70
87
|
log(`[${label}] ${total ? `${percent}%` : mb} (${mb}MB${totalMb})`)
|
|
71
88
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
callback(null, chunk)
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
await pipeline(response.body, progress, createWriteStream(dest))
|
|
76
93
|
log(`[${label}] 下载完成:${(received / 1024 / 1024).toFixed(1)}MB`)
|
|
77
94
|
}
|
|
78
95
|
|
|
@@ -102,9 +119,23 @@ async function main() {
|
|
|
102
119
|
mkdirSync(MODEL_DIR, { recursive: true })
|
|
103
120
|
const archive = join(MODEL_DIR, 'sensevoice.tar.bz2')
|
|
104
121
|
const extractDir = join(MODEL_DIR, '.extract')
|
|
122
|
+
try { rmSync(archive, { force: true }) } catch { /* 清理残留压缩包 */ }
|
|
105
123
|
log(`[download-sensevoice] downloading model (约 230MB) ...`)
|
|
106
124
|
try {
|
|
107
|
-
|
|
125
|
+
let lastError
|
|
126
|
+
for (const url of MODEL_URLS) {
|
|
127
|
+
log(`[download-sensevoice] trying: ${url}`)
|
|
128
|
+
try {
|
|
129
|
+
await download(url, archive, 'SenseVoice')
|
|
130
|
+
lastError = undefined
|
|
131
|
+
break
|
|
132
|
+
} catch (error) {
|
|
133
|
+
lastError = error
|
|
134
|
+
log(`[download-sensevoice] mirror failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
135
|
+
try { rmSync(archive, { force: true }) } catch { /* ignore */ }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (lastError) throw lastError
|
|
108
139
|
ok('downloaded archive')
|
|
109
140
|
rmSync(extractDir, { recursive: true, force: true })
|
|
110
141
|
extract(archive, extractDir)
|
|
@@ -16,12 +16,34 @@
|
|
|
16
16
|
|
|
17
17
|
import { appendFileSync, createWriteStream, existsSync, mkdirSync, rmSync } from 'node:fs'
|
|
18
18
|
import { tmpdir } from 'node:os'
|
|
19
|
-
import { join, resolve } from 'node:path'
|
|
19
|
+
import { basename, dirname, join, resolve } from 'node:path'
|
|
20
20
|
import { spawnSync } from 'node:child_process'
|
|
21
|
+
import { Transform } from 'node:stream'
|
|
22
|
+
import { pipeline } from 'node:stream/promises'
|
|
23
|
+
import { fileURLToPath } from 'node:url'
|
|
21
24
|
|
|
22
|
-
const
|
|
25
|
+
const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url)))
|
|
26
|
+
|
|
27
|
+
function inferDshHomeFromPackage() {
|
|
28
|
+
let dir = ROOT
|
|
29
|
+
while (true) {
|
|
30
|
+
if (basename(dir) === 'profiles') return dirname(dir)
|
|
31
|
+
const parent = dirname(dir)
|
|
32
|
+
if (parent === dir) return undefined
|
|
33
|
+
dir = parent
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const HOME = (process.env.DSH_HOME && process.env.DSH_HOME.trim())
|
|
38
|
+
|| inferDshHomeFromPackage()
|
|
39
|
+
|| join(process.env.USERPROFILE || process.env.HOME || '', '.dsh')
|
|
23
40
|
const VERSION = process.env.DSH_PET_ELECTRON_VERSION || '43.3.0'
|
|
24
|
-
const
|
|
41
|
+
const MIRROR_TEMPLATES = [
|
|
42
|
+
(version, zip) => `${(process.env.DSH_PET_ELECTRON_MIRROR || 'https://npmmirror.com/mirrors/electron/').replace(/\/$/, '')}/${version}/${zip}`,
|
|
43
|
+
(version, zip) => `https://github.com/electron/electron/releases/download/v${version}/${zip}`,
|
|
44
|
+
(version, zip) => `https://ghfast.top/https://github.com/electron/electron/releases/download/v${version}/${zip}`,
|
|
45
|
+
(version, zip) => `https://gh-proxy.com/https://github.com/electron/electron/releases/download/v${version}/${zip}`,
|
|
46
|
+
]
|
|
25
47
|
const TARGET_DIR = resolve(HOME, 'electron')
|
|
26
48
|
const EXE = join(TARGET_DIR, 'electron.exe')
|
|
27
49
|
const REQUIRED_FILES = [
|
|
@@ -50,17 +72,12 @@ async function download(url, dest, label = 'download') {
|
|
|
50
72
|
throw new Error(`download failed: ${response.status} ${response.statusText} (${url})`)
|
|
51
73
|
}
|
|
52
74
|
const total = Number(response.headers.get('content-length')) || 0
|
|
53
|
-
const file = createWriteStream(dest)
|
|
54
|
-
const reader = response.body.getReader()
|
|
55
75
|
let received = 0
|
|
56
76
|
let lastLoggedAt = 0
|
|
57
77
|
let lastPercent = -1
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (done) break
|
|
62
|
-
received += value.length
|
|
63
|
-
file.write(value)
|
|
78
|
+
const progress = new Transform({
|
|
79
|
+
transform(chunk, _encoding, callback) {
|
|
80
|
+
received += chunk.length
|
|
64
81
|
const percent = total ? Math.floor((received / total) * 100) : 0
|
|
65
82
|
const shouldLog = total
|
|
66
83
|
? (percent !== lastPercent && (percent % 10 === 0 || percent === 100))
|
|
@@ -72,10 +89,10 @@ async function download(url, dest, label = 'download') {
|
|
|
72
89
|
const totalMb = total ? ` / ${(total / 1024 / 1024).toFixed(1)}MB` : ''
|
|
73
90
|
log(`[${label}] ${total ? `${percent}%` : mb} (${mb}MB${totalMb})`)
|
|
74
91
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
92
|
+
callback(null, chunk)
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
await pipeline(response.body, progress, createWriteStream(dest))
|
|
79
96
|
log(`[${label}] 下载完成:${(received / 1024 / 1024).toFixed(1)}MB`)
|
|
80
97
|
}
|
|
81
98
|
|
|
@@ -111,12 +128,25 @@ async function main() {
|
|
|
111
128
|
mkdirSync(TARGET_DIR, { recursive: true })
|
|
112
129
|
|
|
113
130
|
const zipName = `electron-v${VERSION}-win32-x64.zip`
|
|
114
|
-
const url = `${MIRROR.replace(/\/$/, '')}/${VERSION}/${zipName}`
|
|
115
131
|
const zipPath = join(tmpdir(), zipName)
|
|
132
|
+
try { rmSync(zipPath, { force: true }) } catch { /* 清理残留 zip */ }
|
|
116
133
|
|
|
117
134
|
try {
|
|
118
|
-
|
|
119
|
-
|
|
135
|
+
let lastError
|
|
136
|
+
for (const makeUrl of MIRROR_TEMPLATES) {
|
|
137
|
+
const url = makeUrl(VERSION, zipName)
|
|
138
|
+
log(`[ensure-electron] trying: ${url}`)
|
|
139
|
+
try {
|
|
140
|
+
await download(url, zipPath, 'Electron')
|
|
141
|
+
lastError = undefined
|
|
142
|
+
break
|
|
143
|
+
} catch (error) {
|
|
144
|
+
lastError = error
|
|
145
|
+
log(`[ensure-electron] mirror failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
146
|
+
try { rmSync(zipPath, { force: true }) } catch { /* ignore */ }
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (lastError) throw lastError
|
|
120
150
|
extractZip(zipPath, TARGET_DIR)
|
|
121
151
|
if (!existsSync(EXE)) {
|
|
122
152
|
throw new Error('Electron zip extracted, but electron.exe not found')
|