better-dsh-pet 0.1.0

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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +93 -0
  3. package/README.md +103 -0
  4. package/assets/alarm.mp3 +0 -0
  5. package/assets/thumb//344/270/234/345/274/240/350/245/277/346/234/233.webm +0 -0
  6. package/assets/thumb//344/270/255/347/247/213/350/265/217/346/234/210/345/220/203/346/234/210/351/245/274.webm +0 -0
  7. package/assets/thumb//344/274/230/351/233/205/345/245/263/344/273/206/350/210/236.webm +0 -0
  8. package/assets/thumb//345/201/267/345/220/203/351/233/266/351/243/237/350/242/253/346/212/223/344/275/217.webm +0 -0
  9. package/assets/thumb//345/206/231/344/273/243/347/240/201.webm +0 -0
  10. package/assets/thumb//345/212/250/347/211/251/347/216/257/347/273/225.webm +0 -0
  11. package/assets/thumb//345/216/237/345/234/260/344/270/223/345/277/203/347/216/251/351/255/224/346/226/271.webm +0 -0
  12. package/assets/thumb//345/216/237/345/234/260/345/260/217/346/206/251/346/262/211/347/234/240.webm +0 -0
  13. package/assets/thumb//345/216/237/345/234/260/345/267/246/350/275/254/345/245/224/350/267/221.webm +0 -0
  14. package/assets/thumb//345/216/237/345/234/260/346/225/262/345/207/273/346/241/214/351/235/242/344/272/222/345/212/250.webm +0 -0
  15. package/assets/thumb//345/216/237/345/234/260/346/274/202/346/265/256/350/270/217/346/255/245.webm +0 -0
  16. package/assets/thumb//345/216/237/345/234/260/350/267/263/350/267/203/346/212/223/347/242/216/345/244/264/351/241/266/347/211/251/345/223/201.webm +0 -0
  17. package/assets/thumb//345/216/237/345/234/260/350/271/262/344/270/213/347/216/251/347/216/251/345/205/267/346/261/275/350/275/246.webm +0 -0
  18. package/assets/thumb//345/216/237/345/234/260/351/207/215/345/212/233/344/270/213/350/271/262/345/216/213/347/274/251.webm +0 -0
  19. package/assets/thumb//345/217/257/347/210/261/345/256/205/350/210/236.webm +0 -0
  20. package/assets/thumb//345/220/203Token.webm +0 -0
  21. package/assets/thumb//345/220/203/345/206/260/346/267/207/346/267/213/350/236/215/345/214/226.webm +0 -0
  22. package/assets/thumb//345/220/203/345/215/210/351/244/220.webm +0 -0
  23. package/assets/thumb//345/220/203/346/227/251/351/244/220.webm +0 -0
  24. package/assets/thumb//345/220/203/346/231/232/351/244/220.webm +0 -0
  25. package/assets/thumb//345/220/203/347/231/275/351/245/255.webm +0 -0
  26. package/assets/thumb//345/220/271/346/260/224/347/220/203.webm +0 -0
  27. package/assets/thumb//345/223/210/346/254/240/350/277/236/345/244/251.webm +0 -0
  28. package/assets/thumb//345/240/206/351/233/252/344/272/272.webm +0 -0
  29. package/assets/thumb//345/244/247/345/217/243/345/220/203/351/233/266/351/243/237.webm +0 -0
  30. package/assets/thumb//345/245/263/344/273/206/345/261/210/350/206/235/347/244/274/344/273/252.webm +0 -0
  31. package/assets/thumb//345/260/217/345/271/205/345/272/246/345/216/237/345/234/260 360 /345/272/246/346/227/213/350/275/254/345/261/225/347/244/272.webm +0 -0
  32. package/assets/thumb//345/260/217/346/217/220/347/220/264/346/274/224/345/245/217.webm +0 -0
  33. package/assets/thumb//345/276/205/346/234/272/345/221/274/345/220/270/344/274/221/351/227/262.webm +0 -0
  34. package/assets/thumb//346/202/240/351/227/262/345/223/274/346/255/214.webm +0 -0
  35. package/assets/thumb//346/211/223/347/236/214/347/235/241/350/242/253/346/203/212/351/206/222.webm +0 -0
  36. package/assets/thumb//346/221/207/346/211/207/347/272/263/345/207/211.webm +0 -0
  37. package/assets/thumb//346/224/276/351/243/216/347/255/235.webm +0 -0
  38. package/assets/thumb//346/225/264/344/275/223/346/215/242/350/243/205/350/257/225/350/211/262.webm +0 -0
  39. package/assets/thumb//346/267/261/345/272/246/346/200/235/350/200/203/347/242/216/347/242/216/345/277/265.webm +0 -0
  40. package/assets/thumb//347/202/271/345/207/273/345/233/236/345/272/224 - /345/202/262/345/250/207/347/224/237/346/260/224/357/274/210/344/276/247/350/272/253/345/261/225/347/244/272/357/274/211.webm +0 -0
  41. package/assets/thumb//347/202/271/345/207/273/345/233/236/345/272/224 - /345/256/263/347/276/236/346/203/212/350/256/266.webm +0 -0
  42. package/assets/thumb//347/202/271/345/207/273/345/233/236/345/272/224 - /345/274/200/345/277/203/350/267/203/345/212/250.webm +0 -0
  43. package/assets/thumb//347/205/247/351/225/234/345/255/220.webm +0 -0
  44. package/assets/thumb//347/216/251/346/260/264/346/236/252.webm +0 -0
  45. package/assets/thumb//347/216/251/346/270/270/346/210/217/346/260/224/346/200/245/350/264/245/345/235/217.webm +0 -0
  46. package/assets/thumb//347/224/250/351/262/270/351/261/274/345/260/276/345/267/264/346/213/215/346/211/223/345/234/260/351/235/242.webm +0 -0
  47. package/assets/thumb//350/223/235/351/262/270/347/216/260/344/270/226.webm +0 -0
  48. package/assets/thumb//350/236/203/350/237/271/350/265/260/350/267/257.webm +0 -0
  49. package/assets/thumb//350/242/253/345/220/223/344/270/200/350/267/263/357/274/210/347/202/270/346/257/233/357/274/211.webm +0 -0
  50. package/assets/thumb//350/242/253/350/220/275/345/217/266/346/267/271/346/262/241.webm +0 -0
  51. package/assets/thumb//350/242/253/351/274/240/346/240/207/346/213/226/346/213/275/346/202/254/347/251/272/345/217/215/351/246/210.webm +0 -0
  52. package/assets/thumb//350/266/205/345/244/247/344/274/270/346/207/222/350/205/260.webm +0 -0
  53. package/assets/thumb//350/275/273/345/277/253/346/221/207/346/221/206/350/210/236.webm +0 -0
  54. package/assets/thumb//350/275/273/345/277/253/350/256/260/345/275/225.webm +0 -0
  55. package/assets/thumb//351/262/270/351/261/274/345/220/220/346/263/241/346/263/241/347/211/271/346/225/210.webm +0 -0
  56. package/cordis.patch.yml +36 -0
  57. package/lib/client.js +238 -0
  58. package/lib/index.js +589 -0
  59. package/lib/index.js.bak-20260819-104008 +483 -0
  60. package/lib/pet-helper-process.js +133 -0
  61. package/lib/pet-protocol.js +64 -0
  62. package/lib/pet-reducer.js +527 -0
  63. package/lib/pet-status-copy.js +118 -0
  64. package/lib/types/client/index.d.ts +43 -0
  65. package/lib/types/index.d.ts +65 -0
  66. package/package.json +85 -0
  67. package/runtime/electron-helper/index.html +134 -0
  68. package/runtime/electron-helper/main.js +191 -0
  69. package/runtime/electron-helper/package.json +7 -0
  70. package/runtime/electron-helper/preload.js +39 -0
  71. package/runtime/electron-helper/renderer.js +903 -0
@@ -0,0 +1,65 @@
1
+ /**
2
+ * ============================================================================
3
+ * better-dsh-pet 宿主半侧的类型声明(TypeScript)
4
+ * ============================================================================
5
+ *
6
+ * 【用途】
7
+ * 给 lib/index.js(宿主半侧)提供类型信息,让 TypeScript 用户/编辑器
8
+ * 在 import 本包时获得智能提示和类型检查。纯类型文件,不影响运行时。
9
+ *
10
+ * 【对应实现】
11
+ * lib/index.js —— 监听 DSH session 事件,驱动 Electron 桌面 Helper,
12
+ * 并注册 /plugins/better-dsh-pet/config 设置端点与 /pet 静态资源路由。
13
+ *
14
+ * ============================================================================
15
+ * @module better-dsh-pet
16
+ */
17
+ import type { Context } from '@deepseek-ai/cordis';
18
+ import type { WebRoute } from '@deepseek-ai/dsh-host-webserver';
19
+
20
+ /** Cordis 插件名(loader 诊断用),与 lib/index.js 的 name 一致 */
21
+ export declare const name = 'pet';
22
+ /** 需要注入的服务列表(sessions),与 lib/index.js 的 inject 一致 */
23
+ export declare const inject: string[];
24
+
25
+ /** 插件配置:桌面气泡与状态联动 */
26
+ export interface Config {
27
+ /** 是否启用桌面小宠物。默认 true。 */
28
+ enabled?: boolean;
29
+ /** 角色大小(0.7~1.4)。默认 1。 */
30
+ scale?: number;
31
+ /** 气泡大小(0.8~1.2)。默认 1。 */
32
+ bubbleScale?: number;
33
+ /** 空闲微动作频率:quiet / normal / lively。默认 normal。 */
34
+ activityLevel?: 'quiet' | 'normal' | 'lively';
35
+ /** 减少动态效果。默认 false。 */
36
+ reducedMotion?: boolean;
37
+ /** 气泡显示模式:always / hidden / custom。默认 always。 */
38
+ bubbleMode?: 'always' | 'hidden' | 'custom';
39
+ /** 自定义模式下显示气泡的状态。 */
40
+ bubbleStates?: string[];
41
+ /** 是否允许子 Agent 抢占宠物状态。默认 false。 */
42
+ includeSubagents?: boolean;
43
+ /** 番茄钟工作时长(分钟)。默认 25。 */
44
+ workMinutes?: number;
45
+ /** 番茄钟休息时长(分钟)。默认 5。 */
46
+ breakMinutes?: number;
47
+ /** 是否根据本次对话自动吐槽(会消耗 Token)。默认 false。 */
48
+ roastEnabled?: boolean;
49
+ /** 旧版 /pet 路由的 full 资源根目录。 */
50
+ fullRoot?: string;
51
+ /** Helper 进程选项。 */
52
+ helper?: {
53
+ /** Electron 可执行文件路径;缺省时尝试 DSH_PET_ELECTRON_PATH / require('electron')。 */
54
+ electronPath?: string;
55
+ };
56
+ }
57
+
58
+ /**
59
+ * 宿主插件主体:监听 DSH 状态并驱动桌面 Helper。
60
+ * @param ctx - 插件上下文;ctx.sessions 提供会话事件
61
+ * @param config - 本行配置(来自 patch 树)
62
+ */
63
+ export declare function apply(ctx: Context, config: Config): void;
64
+
65
+ export type { WebRoute };
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "better-dsh-pet",
3
+ "version": "0.1.0",
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
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "deepseek-harness",
9
+ "desktop-pet",
10
+ "pet",
11
+ "floating-widget",
12
+ "web-ui",
13
+ "cordis",
14
+ "react"
15
+ ],
16
+ "homepage": "https://github.com/ysppwn721/better-dsh-pet#readme",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/ysppwn721/better-dsh-pet.git"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/ysppwn721/better-dsh-pet/issues"
23
+ },
24
+ "_comment": [
25
+ "=============== better-dsh-pet 包清单说明 ===============",
26
+ "type: module —— 本包是 ESM",
27
+ "main: lib/index.js —— 宿主半侧入口(Cordis 插件:name/inject/apply)",
28
+ "exports['./client'] —— 浏览器半侧入口,DSH 模块系统按它提供 /plugins/better-dsh-pet/client.js",
29
+ "dsh.bundle.patch —— 声明本包是 bundle,patch 文件是 cordis.patch.yml(安装后自动进层栈)",
30
+ "dsh.client —— 声明浏览器半侧的注入依赖和平台(web)",
31
+ "files —— npm publish 只发这些目录/文件(assets/thumb 播放资源;assets/preview 的 GIF 仅 README 展示、不入包)",
32
+ "scripts.encode:thumbs —— 转码管线(step03 母版 → assets/thumb 360×360)",
33
+ "scripts.prepack —— 发布前自动健康检查",
34
+ "peerDependencies —— 运行时由宿主(DSH)提供的模块,本包不打包它们",
35
+ "================================================"
36
+ ],
37
+ "type": "module",
38
+ "main": "lib/index.js",
39
+ "exports": {
40
+ ".": {
41
+ "types": "./lib/types/index.d.ts",
42
+ "default": "./lib/index.js"
43
+ },
44
+ "./client": {
45
+ "types": "./lib/types/client/index.d.ts",
46
+ "default": "./lib/client.js"
47
+ },
48
+ "./cordis.patch.yml": "./cordis.patch.yml",
49
+ "./package.json": "./package.json"
50
+ },
51
+ "files": [
52
+ "lib",
53
+ "runtime/electron-helper",
54
+ "assets/thumb",
55
+ "assets/alarm.mp3",
56
+ "cordis.patch.yml"
57
+ ],
58
+ "scripts": {
59
+ "prepack": "node scripts/prepack-check.js"
60
+ },
61
+ "license": "MIT",
62
+ "dependencies": {
63
+ "@deepseek-ai/schemastery": "^3.18.1"
64
+ },
65
+ "dsh": {
66
+ "bundle": {
67
+ "patch": "./cordis.patch.yml"
68
+ },
69
+ "client": {
70
+ "inject": [
71
+ "@deepseek-ai/dsh-client-runtime",
72
+ "@deepseek-ai/dsh-client-ui-settings-plugins"
73
+ ],
74
+ "platform": "web"
75
+ }
76
+ },
77
+ "peerDependencies": {
78
+ "@deepseek-ai/cordis": "^4.0.1",
79
+ "@deepseek-ai/dsh-home-paths": "^0.1.0-rc.6",
80
+ "@deepseek-ai/dsh-host-webserver": "^0.1.0-rc.6",
81
+ "@deepseek-ai/dsh-client-runtime": "^0.1.0-rc.6",
82
+ "@deepseek-ai/dsh-client-ui-slots": "^0.1.0-rc.6",
83
+ "react": "^18.2.0"
84
+ }
85
+ }
@@ -0,0 +1,134 @@
1
+ <!doctype html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>dsh-pet</title>
6
+ <style>
7
+ * { box-sizing: border-box; }
8
+ html, body {
9
+ margin: 0;
10
+ padding: 0;
11
+ width: 100%;
12
+ height: 100%;
13
+ background: transparent;
14
+ overflow: hidden;
15
+ font-family: "Microsoft YaHei UI", "Segoe UI", sans-serif;
16
+ user-select: none;
17
+ }
18
+ #root {
19
+ position: relative;
20
+ width: 100%;
21
+ height: 100%;
22
+ }
23
+ #pet-root {
24
+ position: absolute;
25
+ left: 50%;
26
+ bottom: 0;
27
+ transform: translateX(-50%);
28
+ pointer-events: none;
29
+ }
30
+ #pet-stage {
31
+ position: relative;
32
+ width: 462px;
33
+ height: calc(462px * 9 / 16);
34
+ pointer-events: none;
35
+ }
36
+ video.pet-video {
37
+ position: absolute;
38
+ inset: 0;
39
+ width: 100%;
40
+ height: 100%;
41
+ object-fit: contain;
42
+ pointer-events: none;
43
+ opacity: 0;
44
+ transition: opacity .18s ease;
45
+ }
46
+ video.pet-video.is-front { opacity: 1; }
47
+ #pet-hit {
48
+ position: absolute;
49
+ pointer-events: auto;
50
+ cursor: grab;
51
+ z-index: 1;
52
+ }
53
+ #pet-hit.dragging { cursor: grabbing; }
54
+ #bubble {
55
+ position: absolute;
56
+ top: 0;
57
+ left: 50%;
58
+ transform: translateX(-50%);
59
+ width: 340px;
60
+ background: rgba(252, 252, 253, 0.97);
61
+ border: 1px solid rgba(218, 221, 226, 0.9);
62
+ border-radius: 16px;
63
+ box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
64
+ padding: 12px 14px;
65
+ display: none;
66
+ pointer-events: none;
67
+ color: #25282d;
68
+ }
69
+ #bubble.visible { display: block; }
70
+ #bubble-title {
71
+ font-weight: 600;
72
+ font-size: 14px;
73
+ margin: 0 0 4px;
74
+ white-space: nowrap;
75
+ overflow: hidden;
76
+ text-overflow: ellipsis;
77
+ }
78
+ #bubble-detail {
79
+ font-size: 12px;
80
+ color: #747981;
81
+ margin: 0;
82
+ white-space: nowrap;
83
+ overflow: hidden;
84
+ text-overflow: ellipsis;
85
+ }
86
+ #menu {
87
+ position: absolute;
88
+ z-index: 10;
89
+ min-width: 140px;
90
+ background: #fff;
91
+ border: 1px solid #e3e5e8;
92
+ border-radius: 10px;
93
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
94
+ padding: 6px;
95
+ display: none;
96
+ pointer-events: auto;
97
+ }
98
+ #menu.visible { display: block; }
99
+ #menu button {
100
+ display: block;
101
+ width: 100%;
102
+ text-align: left;
103
+ border: 0;
104
+ background: transparent;
105
+ padding: 8px 10px;
106
+ border-radius: 6px;
107
+ font-size: 13px;
108
+ cursor: pointer;
109
+ color: #25282d;
110
+ }
111
+ #menu button:hover { background: #f2f3f5; }
112
+ @media (prefers-reduced-motion: reduce) {
113
+ video.pet-video { transition: none; }
114
+ }
115
+ </style>
116
+ </head>
117
+ <body>
118
+ <div id="root">
119
+ <div id="pet-root">
120
+ <div id="bubble">
121
+ <p id="bubble-title"></p>
122
+ <p id="bubble-detail"></p>
123
+ </div>
124
+ <div id="pet-stage">
125
+ <video class="pet-video is-front" muted playsinline autoplay></video>
126
+ <video class="pet-video" muted playsinline autoplay></video>
127
+ <div id="pet-hit"></div>
128
+ </div>
129
+ </div>
130
+ <div id="menu"></div>
131
+ </div>
132
+ <script src="./renderer.js"></script>
133
+ </body>
134
+ </html>
@@ -0,0 +1,191 @@
1
+ /**
2
+ * better-dsh-pet desktop helper —— Electron 主进程
3
+ *
4
+ * 不再依赖 stdin 协议(Windows 下 Electron GUI 进程的 stdin 不可靠),
5
+ * 改为轮询 DSH 宿主暴露的 /plugins/better-dsh-pet/status HTTP 端点,
6
+ * 把最新状态转发给透明置顶窗口内的 renderer。
7
+ */
8
+ const { app, BrowserWindow, ipcMain, screen, shell } = require('electron')
9
+ const path = require('node:path')
10
+ const { spawn } = require('node:child_process')
11
+ const { existsSync } = require('node:fs')
12
+
13
+ // 允许无用户手势直接播放 MP3 闹钟
14
+ app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required')
15
+
16
+ let mainWindow = null
17
+ let pollTimer = null
18
+
19
+ function setClickThrough(ignore) {
20
+ if (mainWindow && !mainWindow.isDestroyed()) {
21
+ mainWindow.setIgnoreMouseEvents(ignore === true, { forward: true })
22
+ }
23
+ }
24
+
25
+ function resolveDesktopPath() {
26
+ const candidates = [
27
+ process.env.DSH_PET_DESKTOP_PATH,
28
+ process.env.DSH_DESKTOP_PATH,
29
+ 'D:\\deepseek harness\\DSH Desktop\\DSH Desktop.exe',
30
+ 'D:/deepseek harness/DSH Desktop/DSH Desktop.exe',
31
+ ].filter(Boolean)
32
+ return candidates.find((candidate) => existsSync(candidate))
33
+ }
34
+
35
+ function openDesktop() {
36
+ const desktopPath = resolveDesktopPath()
37
+ if (!desktopPath) {
38
+ console.error('[better-dsh-pet-helper] DSH Desktop executable not found')
39
+ return
40
+ }
41
+ try {
42
+ const child = spawn(desktopPath, [], {
43
+ detached: true,
44
+ stdio: 'ignore',
45
+ windowsHide: false,
46
+ })
47
+ child.unref()
48
+ } catch (error) {
49
+ console.error('[better-dsh-pet-helper] failed to launch DSH Desktop:', error)
50
+ }
51
+ }
52
+
53
+ function createWindow() {
54
+ const scale = Number(process.env.DSH_PET_SCALE || '1')
55
+ const bubbleScale = Number(process.env.DSH_PET_BUBBLE_SCALE || '1')
56
+ // 使用主屏工作区作为透明画布,宠物在画布内自由移动,不移动窗口本身。
57
+ const display = screen.getPrimaryDisplay()
58
+ const area = display.workArea
59
+ const width = area.width
60
+ const height = area.height
61
+
62
+ mainWindow = new BrowserWindow({
63
+ width,
64
+ height,
65
+ x: area.x,
66
+ y: area.y,
67
+ useContentSize: true,
68
+ transparent: true,
69
+ frame: false,
70
+ alwaysOnTop: true,
71
+ skipTaskbar: true,
72
+ resizable: false,
73
+ hasShadow: false,
74
+ webPreferences: {
75
+ preload: path.join(__dirname, 'preload.js'),
76
+ contextIsolation: true,
77
+ nodeIntegration: false,
78
+ sandbox: false,
79
+ },
80
+ })
81
+
82
+ mainWindow.setAlwaysOnTop(true, 'screen-saver')
83
+ mainWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })
84
+ setClickThrough(true)
85
+
86
+ mainWindow.loadFile('index.html', {
87
+ query: {
88
+ scale: String(scale),
89
+ bubbleScale: String(bubbleScale),
90
+ activityLevel: process.env.DSH_PET_ACTIVITY_LEVEL || 'normal',
91
+ reducedMotion: process.env.DSH_PET_REDUCED_MOTION === '1' ? '1' : '0',
92
+ bubbleMode: process.env.DSH_PET_BUBBLE_MODE || 'always',
93
+ bubbleStates: process.env.DSH_PET_BUBBLE_STATES || 'SUCCESS,ERROR,WAITING',
94
+ webuiUrl: process.env.DSH_PET_WEBUI_URL || 'http://127.0.0.1:3080/',
95
+ },
96
+ }).then(() => {
97
+ startPolling()
98
+ }).catch((error) => {
99
+ console.error('[better-dsh-pet-helper] page load failed:', error)
100
+ app.quit()
101
+ })
102
+
103
+ mainWindow.on('closed', () => {
104
+ mainWindow = null
105
+ if (pollTimer) clearInterval(pollTimer)
106
+ pollTimer = null
107
+ })
108
+ }
109
+
110
+ function startPolling() {
111
+ const statusUrl = process.env.DSH_PET_STATUS_URL
112
+ if (!statusUrl) {
113
+ console.error('[better-dsh-pet-helper] DSH_PET_STATUS_URL is not set')
114
+ return
115
+ }
116
+ const poll = async () => {
117
+ if (!mainWindow || mainWindow.isDestroyed()) return
118
+ try {
119
+ const response = await fetch(statusUrl, { cache: 'no-store' })
120
+ if (!response.ok) return
121
+ const status = await response.json()
122
+ if (mainWindow && !mainWindow.isDestroyed()) {
123
+ mainWindow.webContents.send('pet:status', status)
124
+ }
125
+ } catch (error) {
126
+ // DSH 尚未就绪或临时不可达时静默跳过,下个周期再试。
127
+ }
128
+ }
129
+ poll()
130
+ pollTimer = setInterval(poll, 1000)
131
+ if (pollTimer.unref) pollTimer.unref()
132
+ }
133
+
134
+ app.whenReady().then(() => {
135
+ createWindow()
136
+ ipcMain.on('pet:closed', (_event, reason) => {
137
+ app.quit()
138
+ })
139
+ ipcMain.on('pet:hide', () => {
140
+ if (mainWindow) mainWindow.hide()
141
+ })
142
+ ipcMain.on('pet:open-webui', (_event, url) => {
143
+ if (url) shell.openExternal(String(url)).catch(() => {})
144
+ })
145
+ ipcMain.on('pet:open-desktop', () => {
146
+ openDesktop()
147
+ })
148
+ ipcMain.on('pet:set-ignore-mouse', (_event, { ignore }) => {
149
+ setClickThrough(ignore === true)
150
+ })
151
+ ipcMain.on('pet:beep', () => {
152
+ try { shell.beep() } catch { /* 系统不支持时忽略 */ }
153
+ })
154
+ ipcMain.on('pet:save-config', async (_event, patch) => {
155
+ const statusUrl = process.env.DSH_PET_STATUS_URL
156
+ if (!statusUrl || !patch || typeof patch !== 'object') return
157
+ try {
158
+ const configUrl = statusUrl.replace(/\/plugins\/better-dsh-pet\/status$/, '/plugins/better-dsh-pet/config')
159
+ const response = await fetch(configUrl, {
160
+ method: 'PATCH',
161
+ headers: { 'content-type': 'application/json' },
162
+ body: JSON.stringify(patch),
163
+ })
164
+ if (!response.ok) {
165
+ console.error('[better-dsh-pet-helper] save config failed:', response.status)
166
+ }
167
+ } catch (error) {
168
+ console.error('[better-dsh-pet-helper] save config error:', error)
169
+ }
170
+ })
171
+ ipcMain.on('pet:request-roast', async () => {
172
+ const statusUrl = process.env.DSH_PET_STATUS_URL
173
+ if (!statusUrl) return
174
+ try {
175
+ const roastUrl = statusUrl.replace(/\/plugins\/better-dsh-pet\/status$/, '/plugins/better-dsh-pet/roast')
176
+ await fetch(roastUrl, { method: 'POST', cache: 'no-store' })
177
+ } catch (error) {
178
+ console.error('[better-dsh-pet-helper] request roast error:', error)
179
+ }
180
+ })
181
+ ipcMain.on('pet:move-by', () => {
182
+ // 已改为全屏画布内移动宠物 DOM,不再移动窗口。
183
+ })
184
+ ipcMain.on('pet:drag-end', () => {
185
+ // 保留此通道,后续可用来做拖拽结束后的持久化。
186
+ })
187
+ })
188
+
189
+ app.on('window-all-closed', () => {
190
+ app.quit()
191
+ })
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "better-dsh-pet-desktop-helper",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "description": "Transparent desktop helper window for better-dsh-pet",
6
+ "main": "main.js"
7
+ }
@@ -0,0 +1,39 @@
1
+ const { contextBridge, ipcRenderer } = require('electron')
2
+
3
+ contextBridge.exposeInMainWorld('petBridge', {
4
+ onStatus(callback) {
5
+ const listener = (_event, status) => callback(status)
6
+ ipcRenderer.on('pet:status', listener)
7
+ return () => ipcRenderer.removeListener('pet:status', listener)
8
+ },
9
+ close(reason) {
10
+ ipcRenderer.send('pet:closed', reason || 'user')
11
+ },
12
+ hide() {
13
+ ipcRenderer.send('pet:hide')
14
+ },
15
+ openWebUi(url) {
16
+ ipcRenderer.send('pet:open-webui', url)
17
+ },
18
+ openDesktop() {
19
+ ipcRenderer.send('pet:open-desktop')
20
+ },
21
+ moveBy(dx, dy) {
22
+ ipcRenderer.send('pet:move-by', { dx, dy })
23
+ },
24
+ endDrag() {
25
+ ipcRenderer.send('pet:drag-end')
26
+ },
27
+ setIgnoreMouse(ignore) {
28
+ ipcRenderer.send('pet:set-ignore-mouse', { ignore })
29
+ },
30
+ beep() {
31
+ ipcRenderer.send('pet:beep')
32
+ },
33
+ saveConfig(patch) {
34
+ ipcRenderer.send('pet:save-config', patch)
35
+ },
36
+ requestRoast() {
37
+ ipcRenderer.send('pet:request-roast')
38
+ },
39
+ })