better-dsh-pet 0.2.1 → 0.2.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 CHANGED
@@ -21,11 +21,9 @@
21
21
 
22
22
  ## 🎬 视频推广
23
23
 
24
- > 📹 演示视频占位:拍好视频后把链接放到这里。
24
+ > 📹 点击观看 better-dsh-pet 演示视频:
25
25
  >
26
- > ```md
27
- > [▶️ 点击观看 better-dsh-pet 演示视频](https://www.bilibili.com/video/你的视频ID)
28
- > ```
26
+ > [▶️ B站:一行命令,把大肥鱼放到桌面](https://www.bilibili.com/video/BV1YH8h6WEvi)
29
27
 
30
28
  ---
31
29
 
@@ -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.1",
3
+ "version": "0.2.3",
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"
@@ -64,6 +64,7 @@ function createWindow() {
64
64
  height,
65
65
  x: area.x,
66
66
  y: area.y,
67
+ show: false,
67
68
  useContentSize: true,
68
69
  transparent: true,
69
70
  frame: false,
@@ -76,9 +77,14 @@ function createWindow() {
76
77
  contextIsolation: true,
77
78
  nodeIntegration: false,
78
79
  sandbox: false,
80
+ paintWhenInitiallyHidden: false,
79
81
  },
80
82
  })
81
83
 
84
+ mainWindow.once('ready-to-show', () => {
85
+ mainWindow.show()
86
+ })
87
+
82
88
  mainWindow.setAlwaysOnTop(true, 'screen-saver')
83
89
  mainWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })
84
90
  setClickThrough(true)
@@ -0,0 +1,97 @@
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
+ const REQUIRED_FILES = [
30
+ 'electron.exe',
31
+ 'icudtl.dat',
32
+ 'resources.pak',
33
+ 'snapshot_blob.bin',
34
+ 'chrome_100_percent.pak',
35
+ 'v8_context_snapshot.bin',
36
+ ]
37
+
38
+ async function download(url, dest) {
39
+ const response = await fetch(url, { redirect: 'follow' })
40
+ if (!response.ok) {
41
+ throw new Error(`download failed: ${response.status} ${response.statusText} (${url})`)
42
+ }
43
+ await pipeline(response.body, createWriteStream(dest))
44
+ }
45
+
46
+ function extractZip(zipPath, targetDir) {
47
+ mkdirSync(targetDir, { recursive: true })
48
+ // Windows 自带 tar(bsdtar)可以直接解压 zip;失败时退回 PowerShell Expand-Archive。
49
+ const tar = spawnSync('tar', ['-xf', zipPath, '-C', targetDir], { stdio: 'inherit' })
50
+ if (tar.status !== 0) {
51
+ const ps = spawnSync('powershell', [
52
+ '-NoProfile',
53
+ '-Command',
54
+ `Expand-Archive -LiteralPath '${zipPath}' -DestinationPath '${targetDir}' -Force`,
55
+ ], { stdio: 'inherit' })
56
+ if (ps.status !== 0) {
57
+ throw new Error('failed to extract Electron zip')
58
+ }
59
+ }
60
+ // 校验关键文件是否完整;不完整说明下载/解压失败,清理后重试。
61
+ const missing = REQUIRED_FILES.filter((name) => !existsSync(join(targetDir, name)))
62
+ if (missing.length > 0) {
63
+ rmSync(targetDir, { recursive: true, force: true })
64
+ throw new Error(`Electron zip incomplete, missing: ${missing.join(', ')}`)
65
+ }
66
+ }
67
+
68
+ async function main() {
69
+ if (existsSync(EXE)) {
70
+ console.log(EXE)
71
+ return
72
+ }
73
+
74
+ console.log(`[ensure-electron] Electron not found, downloading v${VERSION} ...`)
75
+ mkdirSync(TARGET_DIR, { recursive: true })
76
+
77
+ const zipName = `electron-v${VERSION}-win32-x64.zip`
78
+ const url = `${MIRROR.replace(/\/$/, '')}/${VERSION}/${zipName}`
79
+ const zipPath = join(tmpdir(), zipName)
80
+
81
+ try {
82
+ console.log(`[ensure-electron] ${url}`)
83
+ await download(url, zipPath)
84
+ extractZip(zipPath, TARGET_DIR)
85
+ if (!existsSync(EXE)) {
86
+ throw new Error('Electron zip extracted, but electron.exe not found')
87
+ }
88
+ console.log(EXE)
89
+ } finally {
90
+ try { rmSync(zipPath, { force: true }) } catch { /* ignore */ }
91
+ }
92
+ }
93
+
94
+ main().catch((error) => {
95
+ console.error(`[ensure-electron] ${error instanceof Error ? error.message : String(error)}`)
96
+ process.exit(1)
97
+ })