better-dsh-pet 0.2.1 → 0.2.2
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.
|
@@ -32,10 +32,8 @@ function resolveElectronPath(candidates = []) {
|
|
|
32
32
|
} catch {
|
|
33
33
|
/* electron 未安装时跳过 */
|
|
34
34
|
}
|
|
35
|
-
// 常见 Electron
|
|
35
|
+
// 常见 Electron 安装位置(便于其他电脑直接跑通;不再依赖本机开发目录)。
|
|
36
36
|
const localCandidates = [
|
|
37
|
-
'D:/deepseek harness/tools/desktop-eval/dsh-desktop-electron/node_modules/electron/dist/electron.exe',
|
|
38
|
-
'D:/deepseek harness/tools/desktop-eval/dsh-desktop-electron/node_modules/electron/dist/electron',
|
|
39
37
|
join(process.env.USERPROFILE || '', '.dsh', 'electron', 'electron.exe'),
|
|
40
38
|
join(process.env.APPDATA || '', 'npm', 'node_modules', 'electron', 'dist', 'electron.exe'),
|
|
41
39
|
join(process.env.USERPROFILE || '', 'AppData', 'Roaming', 'npm', 'node_modules', 'electron', 'dist', 'electron.exe'),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-dsh-pet",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A desktop-native pet bubble driven by DeepSeek Harness session events: transparent always-on-top Electron window, status-aware animations, balance, pomodoro, roast, and DSH settings card.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
"runtime/electron-helper",
|
|
54
54
|
"assets/thumb",
|
|
55
55
|
"assets/alarm.mp3",
|
|
56
|
-
"cordis.patch.yml"
|
|
56
|
+
"cordis.patch.yml",
|
|
57
|
+
"scripts/ensure-electron.mjs"
|
|
57
58
|
],
|
|
58
59
|
"scripts": {
|
|
59
60
|
"prepack": "node scripts/prepack-check.js"
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ensure-electron.mjs
|
|
4
|
+
*
|
|
5
|
+
* 自动下载 Electron 到 $DSH_HOME/electron(默认 ~/.dsh/electron),
|
|
6
|
+
* 供 better-dsh-pet 桌面 Helper 使用。
|
|
7
|
+
*
|
|
8
|
+
* 用法:
|
|
9
|
+
* node scripts/ensure-electron.mjs
|
|
10
|
+
*
|
|
11
|
+
* 环境变量:
|
|
12
|
+
* DSH_HOME DSH 主目录(默认 ~/.dsh)
|
|
13
|
+
* DSH_PET_ELECTRON_VERSION Electron 版本(默认 43.3.0)
|
|
14
|
+
* DSH_PET_ELECTRON_MIRROR 镜像地址(默认 npmmirror)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { existsSync, mkdirSync, rmSync } from 'node:fs'
|
|
18
|
+
import { tmpdir } from 'node:os'
|
|
19
|
+
import { join, resolve } from 'node:path'
|
|
20
|
+
import { spawnSync } from 'node:child_process'
|
|
21
|
+
import { pipeline } from 'node:stream/promises'
|
|
22
|
+
import { createWriteStream } from 'node:fs'
|
|
23
|
+
|
|
24
|
+
const HOME = process.env.DSH_HOME || join(process.env.USERPROFILE || process.env.HOME || '', '.dsh')
|
|
25
|
+
const VERSION = process.env.DSH_PET_ELECTRON_VERSION || '43.3.0'
|
|
26
|
+
const MIRROR = process.env.DSH_PET_ELECTRON_MIRROR || 'https://npmmirror.com/mirrors/electron/'
|
|
27
|
+
const TARGET_DIR = resolve(HOME, 'electron')
|
|
28
|
+
const EXE = join(TARGET_DIR, 'electron.exe')
|
|
29
|
+
|
|
30
|
+
async function download(url, dest) {
|
|
31
|
+
const response = await fetch(url, { redirect: 'follow' })
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new Error(`download failed: ${response.status} ${response.statusText} (${url})`)
|
|
34
|
+
}
|
|
35
|
+
await pipeline(response.body, createWriteStream(dest))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function extractZip(zipPath, targetDir) {
|
|
39
|
+
mkdirSync(targetDir, { recursive: true })
|
|
40
|
+
// Windows 自带 tar(bsdtar)可以直接解压 zip;失败时退回 PowerShell Expand-Archive。
|
|
41
|
+
const tar = spawnSync('tar', ['-xf', zipPath, '-C', targetDir], { stdio: 'inherit' })
|
|
42
|
+
if (tar.status === 0) return
|
|
43
|
+
const ps = spawnSync('powershell', [
|
|
44
|
+
'-NoProfile',
|
|
45
|
+
'-Command',
|
|
46
|
+
`Expand-Archive -LiteralPath '${zipPath}' -DestinationPath '${targetDir}' -Force`,
|
|
47
|
+
], { stdio: 'inherit' })
|
|
48
|
+
if (ps.status !== 0) {
|
|
49
|
+
throw new Error('failed to extract Electron zip')
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function main() {
|
|
54
|
+
if (existsSync(EXE)) {
|
|
55
|
+
console.log(EXE)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
console.log(`[ensure-electron] Electron not found, downloading v${VERSION} ...`)
|
|
60
|
+
mkdirSync(TARGET_DIR, { recursive: true })
|
|
61
|
+
|
|
62
|
+
const zipName = `electron-v${VERSION}-win32-x64.zip`
|
|
63
|
+
const url = `${MIRROR.replace(/\/$/, '')}/${VERSION}/${zipName}`
|
|
64
|
+
const zipPath = join(tmpdir(), zipName)
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
console.log(`[ensure-electron] ${url}`)
|
|
68
|
+
await download(url, zipPath)
|
|
69
|
+
extractZip(zipPath, TARGET_DIR)
|
|
70
|
+
if (!existsSync(EXE)) {
|
|
71
|
+
throw new Error('Electron zip extracted, but electron.exe not found')
|
|
72
|
+
}
|
|
73
|
+
console.log(EXE)
|
|
74
|
+
} finally {
|
|
75
|
+
try { rmSync(zipPath, { force: true }) } catch { /* ignore */ }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
main().catch((error) => {
|
|
80
|
+
console.error(`[ensure-electron] ${error instanceof Error ? error.message : String(error)}`)
|
|
81
|
+
process.exit(1)
|
|
82
|
+
})
|