better-dsh-pet 0.3.4 → 0.3.6
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 +15 -2
- package/cordis.patch.yml +1 -0
- package/lib/index.js +3 -0
- package/lib/pet-helper-process.js +8 -1
- package/lib/types/client/index.d.ts +3 -2
- package/lib/types/index.d.ts +6 -4
- package/package.json +6 -5
- package/runtime/electron-helper/index.html +12 -10
- package/runtime/electron-helper/main.js +240 -50
- package/runtime/electron-helper/preload.js +11 -0
- package/runtime/electron-helper/renderer.js +69 -7
- package/scripts/download-sensevoice.mjs +7 -7
package/README.md
CHANGED
|
@@ -277,7 +277,7 @@ dsh plugin --profile web add better-dsh-pet
|
|
|
277
277
|
> 如果刚发布新版本不到 24 小时,pnpm 11 的 `minimumReleaseAge` 安全策略可能不会自动选最新版,而是退回旧版。此时请指定精确版本安装:
|
|
278
278
|
>
|
|
279
279
|
> ```bash
|
|
280
|
-
> dsh plugin --profile web add better-dsh-pet@0.3.
|
|
280
|
+
> dsh plugin --profile web add better-dsh-pet@0.3.6
|
|
281
281
|
> ```
|
|
282
282
|
>
|
|
283
283
|
> pnpm 会自动把该版本加入 `minimumReleaseAgeExclude` 并完成安装;也可以等待 24 小时后直接用上面的普通命令。
|
|
@@ -402,7 +402,7 @@ Remove-Item "C:\Users\Administrator\.dsh\voice" -Recurse -Force
|
|
|
402
402
|
- **升级时提示 EPERM**:
|
|
403
403
|
- 先完全退出 DSH / 桌宠,再执行:
|
|
404
404
|
```bash
|
|
405
|
-
dsh plugin --profile web add better-dsh-pet@0.3.
|
|
405
|
+
dsh plugin --profile web add better-dsh-pet@0.3.6
|
|
406
406
|
```
|
|
407
407
|
|
|
408
408
|
---
|
|
@@ -604,6 +604,19 @@ npm run download:sensevoice
|
|
|
604
604
|
4. 首次启动需要自动下载 Electron,请稍等片刻
|
|
605
605
|
5. 如果下载失败,可手动设置 `DSH_PET_ELECTRON_PATH` 指向 `electron.exe`
|
|
606
606
|
|
|
607
|
+
### Q:DSH 升到 0.2.x 之后大肥鱼不见了?
|
|
608
|
+
|
|
609
|
+
0.3.5 及更早版本会有两处不兼容,**升级到 0.3.6** 即可:
|
|
610
|
+
|
|
611
|
+
1. peer 范围写在 `^0.1.0-rc.6`(只覆盖 0.1.x)。DSH 装配 profile 时会校验 `@deepseek-ai/dsh-*` 的 peer 范围与运行时版本,不匹配就**整个 bundle 被跳过**——插件不加载、设置页也没有卡片。0.3.6 起放宽为 `>=0.1.0-rc.6 <0.3.0`。
|
|
612
|
+
2. DSH 0.2.0 桌面端把宿主跑在 `ELECTRON_RUN_AS_NODE=1` 下,该环境变量会继承给桌宠 Helper,使 `electron.exe` 退化为纯 Node 进程(`require('electron')` 报 `MODULE_NOT_FOUND`),窗口起不来、进程被反复重拉。0.3.6 起在 spawn Helper 前摘掉这个开关。
|
|
613
|
+
|
|
614
|
+
升级命令:
|
|
615
|
+
|
|
616
|
+
```bash
|
|
617
|
+
dsh plugin --profile web add better-dsh-pet@0.3.6
|
|
618
|
+
```
|
|
619
|
+
|
|
607
620
|
### Q:为什么没有余额显示?
|
|
608
621
|
|
|
609
622
|
- 需要 DSH 中配置了 `DEEPSEEK_API_KEY`
|
package/cordis.patch.yml
CHANGED
package/lib/index.js
CHANGED
|
@@ -77,6 +77,7 @@ export const Config = Schema.object({
|
|
|
77
77
|
holidayEnabled: Schema.boolean().default(false).description('启用节日祝福识别(阳历与农历)'),
|
|
78
78
|
wakeWord: Schema.string().default('大肥鱼').description('语音唤醒词(例如:大肥鱼)'),
|
|
79
79
|
taskCwd: Schema.string().default('').description('复杂任务工作目录(留空=用户主目录)'),
|
|
80
|
+
weatherCity: Schema.string().default('').description('查天气默认城市(留空=自动定位)'),
|
|
80
81
|
}).description('由 DeepSeek Harness 状态驱动的桌面大肥鱼')
|
|
81
82
|
|
|
82
83
|
const defaults = Object.freeze({
|
|
@@ -106,6 +107,7 @@ const defaults = Object.freeze({
|
|
|
106
107
|
holidayEnabled: false,
|
|
107
108
|
wakeWord: '大肥鱼',
|
|
108
109
|
taskCwd: '',
|
|
110
|
+
weatherCity: '',
|
|
109
111
|
})
|
|
110
112
|
|
|
111
113
|
function publicConfig(config = {}) {
|
|
@@ -136,6 +138,7 @@ function publicConfig(config = {}) {
|
|
|
136
138
|
holidayEnabled: config.holidayEnabled ?? defaults.holidayEnabled,
|
|
137
139
|
wakeWord: config.wakeWord || defaults.wakeWord,
|
|
138
140
|
taskCwd: config.taskCwd || defaults.taskCwd,
|
|
141
|
+
weatherCity: config.weatherCity || defaults.weatherCity,
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
|
|
@@ -98,9 +98,16 @@ export class HelperProcess {
|
|
|
98
98
|
const command = launch.command
|
|
99
99
|
const args = this.options.args || launch.args
|
|
100
100
|
|
|
101
|
+
const childEnv = { ...process.env, ...this.options.env }
|
|
102
|
+
// DSH 0.2.0 桌面端把宿主跑在 ELECTRON_RUN_AS_NODE=1 下(用自带 Electron 二进制充当
|
|
103
|
+
// Node),该变量会随 process.env 继承给桌宠 Helper,使它退化为纯 Node 进程:
|
|
104
|
+
// require('electron') 直接 MODULE_NOT_FOUND → 窗口起不来,Helper 秒退后被看门狗
|
|
105
|
+
// 每 750ms 重拉(表现为大肥鱼一直不出现)。独立 Electron 窗口必须摘掉这个开关。
|
|
106
|
+
delete childEnv.ELECTRON_RUN_AS_NODE
|
|
107
|
+
delete childEnv.ELECTRON_NO_ATTACH_CONSOLE
|
|
101
108
|
const child = spawn(command, args, {
|
|
102
109
|
cwd: this.options.cwd || packageRoot,
|
|
103
|
-
env:
|
|
110
|
+
env: childEnv,
|
|
104
111
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
105
112
|
windowsHide: true,
|
|
106
113
|
})
|
package/lib/types/index.d.ts
CHANGED
|
@@ -74,10 +74,12 @@ export interface Config {
|
|
|
74
74
|
voiceAutoRecord?: boolean;
|
|
75
75
|
/** 启用节日祝福识别(阳历与农历)。默认 false。 */
|
|
76
76
|
holidayEnabled?: boolean;
|
|
77
|
-
/** 语音唤醒词。默认“大肥鱼”。 */
|
|
78
|
-
wakeWord?: string;
|
|
79
|
-
/** 复杂任务工作目录(留空=用户主目录)。 */
|
|
80
|
-
taskCwd?: string;
|
|
77
|
+
/** 语音唤醒词。默认“大肥鱼”。 */
|
|
78
|
+
wakeWord?: string;
|
|
79
|
+
/** 复杂任务工作目录(留空=用户主目录)。 */
|
|
80
|
+
taskCwd?: string;
|
|
81
|
+
/** 查天气默认城市(留空=自动定位)。 */
|
|
82
|
+
weatherCity?: string;
|
|
81
83
|
/** 旧版 /pet 路由的 full 资源根目录。 */
|
|
82
84
|
fullRoot?: string;
|
|
83
85
|
/** Helper 进程选项。 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-dsh-pet",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
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",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"scripts.encode:thumbs —— 转码管线(step03 母版 → assets/thumb 360×360)",
|
|
38
38
|
"scripts.prepack —— 发布前自动健康检查",
|
|
39
39
|
"peerDependencies —— 运行时由宿主(DSH)提供的模块,本包不打包它们",
|
|
40
|
+
"peerDependencies 范围(0.3.6 起):DSH 在装配 profile 时会用 semver 校验 @deepseek-ai/dsh-* 的 peer 范围与运行时版本,范围不含运行时版本会导致整个 bundle 被跳过(插件完全不加载、设置页也没有卡片)。原 ^0.1.0-rc.6 只覆盖 0.1.x,在 0.2.x 上必被跳过,故放宽为 >=0.1.0-rc.6 <0.3.0。",
|
|
40
41
|
"================================================"
|
|
41
42
|
],
|
|
42
43
|
"type": "module",
|
|
@@ -86,10 +87,10 @@
|
|
|
86
87
|
},
|
|
87
88
|
"peerDependencies": {
|
|
88
89
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
89
|
-
"@deepseek-ai/dsh-home-paths": "
|
|
90
|
-
"@deepseek-ai/dsh-host-webserver": "
|
|
91
|
-
"@deepseek-ai/dsh-client-runtime": "
|
|
92
|
-
"@deepseek-ai/dsh-client-ui-slots": "
|
|
90
|
+
"@deepseek-ai/dsh-home-paths": ">=0.1.0-rc.6 <0.3.0",
|
|
91
|
+
"@deepseek-ai/dsh-host-webserver": ">=0.1.0-rc.6 <0.3.0",
|
|
92
|
+
"@deepseek-ai/dsh-client-runtime": ">=0.1.0-rc.6 <0.3.0",
|
|
93
|
+
"@deepseek-ai/dsh-client-ui-slots": ">=0.1.0-rc.6 <0.3.0",
|
|
93
94
|
"react": "^18.2.0"
|
|
94
95
|
}
|
|
95
96
|
}
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
top: 0;
|
|
57
57
|
left: 50%;
|
|
58
58
|
transform: translateX(-50%);
|
|
59
|
-
width:
|
|
59
|
+
width: min(420px, 80vw);
|
|
60
60
|
background: rgba(252, 252, 253, 0.97);
|
|
61
61
|
border: 1px solid rgba(218, 221, 226, 0.9);
|
|
62
62
|
border-radius: 16px;
|
|
63
63
|
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
|
|
64
|
-
padding:
|
|
64
|
+
padding: 14px 16px;
|
|
65
65
|
display: none;
|
|
66
66
|
pointer-events: none;
|
|
67
67
|
color: #25282d;
|
|
@@ -69,19 +69,21 @@
|
|
|
69
69
|
#bubble.visible { display: block; }
|
|
70
70
|
#bubble-title {
|
|
71
71
|
font-weight: 600;
|
|
72
|
-
font-size:
|
|
72
|
+
font-size: 15px;
|
|
73
73
|
margin: 0 0 4px;
|
|
74
|
-
white-space:
|
|
75
|
-
overflow:
|
|
76
|
-
text-overflow:
|
|
74
|
+
white-space: normal;
|
|
75
|
+
overflow: visible;
|
|
76
|
+
text-overflow: clip;
|
|
77
|
+
word-break: break-word;
|
|
77
78
|
}
|
|
78
79
|
#bubble-detail {
|
|
79
|
-
font-size:
|
|
80
|
+
font-size: 13px;
|
|
80
81
|
color: #747981;
|
|
81
82
|
margin: 0;
|
|
82
|
-
white-space:
|
|
83
|
-
overflow:
|
|
84
|
-
text-overflow:
|
|
83
|
+
white-space: normal;
|
|
84
|
+
overflow: visible;
|
|
85
|
+
text-overflow: clip;
|
|
86
|
+
word-break: break-word;
|
|
85
87
|
}
|
|
86
88
|
#menu {
|
|
87
89
|
position: absolute;
|
|
@@ -24,8 +24,10 @@ let tray = null
|
|
|
24
24
|
let userHidden = false
|
|
25
25
|
let fullscreenHidden = false
|
|
26
26
|
let fullscreenCheckTimer = null
|
|
27
|
-
let wakeWordProcess = null
|
|
27
|
+
let wakeWordProcess = null
|
|
28
28
|
let currentWakeWord = process.env.DSH_PET_WAKE_WORD || '大肥鱼'
|
|
29
|
+
let forceClickThrough = false
|
|
30
|
+
let trayToggleVisible = null
|
|
29
31
|
|
|
30
32
|
function setClickThrough(ignore) {
|
|
31
33
|
if (mainWindow && !mainWindow.isDestroyed()) {
|
|
@@ -75,7 +77,7 @@ function createTray() {
|
|
|
75
77
|
}
|
|
76
78
|
tray = new Tray(icon)
|
|
77
79
|
tray.setToolTip('Better DSH Pet')
|
|
78
|
-
|
|
80
|
+
trayToggleVisible = () => {
|
|
79
81
|
if (!mainWindow || mainWindow.isDestroyed()) return
|
|
80
82
|
if (mainWindow.isVisible()) {
|
|
81
83
|
mainWindow.hide()
|
|
@@ -85,8 +87,24 @@ function createTray() {
|
|
|
85
87
|
userHidden = false
|
|
86
88
|
}
|
|
87
89
|
}
|
|
90
|
+
updateTrayMenu()
|
|
91
|
+
tray.on('click', trayToggleVisible)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function updateTrayMenu() {
|
|
95
|
+
if (!tray) return
|
|
96
|
+
const toggleForceClickThrough = () => {
|
|
97
|
+
forceClickThrough = !forceClickThrough
|
|
98
|
+
if (mainWindow && !mainWindow.isDestroyed()) {
|
|
99
|
+
mainWindow.webContents.send('pet:force-click-through', forceClickThrough)
|
|
100
|
+
mainWindow.setIgnoreMouseEvents(forceClickThrough, { forward: true })
|
|
101
|
+
}
|
|
102
|
+
updateTrayMenu()
|
|
103
|
+
}
|
|
88
104
|
tray.setContextMenu(Menu.buildFromTemplate([
|
|
89
|
-
{ label: '显示 / 隐藏桌宠', click:
|
|
105
|
+
{ label: '显示 / 隐藏桌宠', click: trayToggleVisible },
|
|
106
|
+
{ type: 'separator' },
|
|
107
|
+
{ label: forceClickThrough ? '关闭鼠标穿透' : '开启鼠标穿透', click: toggleForceClickThrough },
|
|
90
108
|
{ type: 'separator' },
|
|
91
109
|
{
|
|
92
110
|
label: '退出',
|
|
@@ -95,7 +113,6 @@ function createTray() {
|
|
|
95
113
|
},
|
|
96
114
|
},
|
|
97
115
|
]))
|
|
98
|
-
tray.on('click', toggleVisible)
|
|
99
116
|
}
|
|
100
117
|
|
|
101
118
|
// Windows 上资源管理器重启、分辨率/DPI 变化、休眠唤醒等可能让置顶丢失,
|
|
@@ -360,6 +377,148 @@ try {
|
|
|
360
377
|
})
|
|
361
378
|
}
|
|
362
379
|
|
|
380
|
+
function weatherCodeText(code) {
|
|
381
|
+
const map = {
|
|
382
|
+
0: '晴朗', 1: '大致晴朗', 2: '多云', 3: '阴天',
|
|
383
|
+
45: '雾', 48: '雾凇',
|
|
384
|
+
51: '小毛毛雨', 53: '毛毛雨', 55: '大毛毛雨',
|
|
385
|
+
56: '冻毛毛雨', 57: '强冻毛毛雨',
|
|
386
|
+
61: '小雨', 63: '中雨', 65: '大雨',
|
|
387
|
+
66: '冻雨', 67: '强冻雨',
|
|
388
|
+
71: '小雪', 73: '中雪', 75: '大雪',
|
|
389
|
+
77: '雪粒',
|
|
390
|
+
80: '小阵雨', 81: '中阵雨', 82: '强阵雨',
|
|
391
|
+
85: '小阵雪', 86: '大阵雪',
|
|
392
|
+
95: '雷雨', 96: '雷雨伴冰雹', 99: '强雷雨伴冰雹',
|
|
393
|
+
}
|
|
394
|
+
return map[Number(code)] || '未知天气'
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function translateWeatherDesc(desc) {
|
|
398
|
+
const text = String(desc || '').toLowerCase()
|
|
399
|
+
const map = {
|
|
400
|
+
'clear': '晴朗', 'sunny': '晴朗', 'partly cloudy': '多云', 'cloudy': '阴天', 'overcast': '阴天',
|
|
401
|
+
'mist': '薄雾', 'fog': '雾', 'freezing fog': '冻雾',
|
|
402
|
+
'light rain': '小雨', 'moderate rain': '中雨', 'heavy rain': '大雨', 'rain': '雨',
|
|
403
|
+
'light snow': '小雪', 'moderate snow': '中雪', 'heavy snow': '大雪', 'snow': '雪',
|
|
404
|
+
'thundery outbreaks possible': '雷阵雨', 'thunderstorm': '雷雨', 'patchy rain possible': '局部小雨',
|
|
405
|
+
'patchy snow possible': '局部小雪', 'smoky haze': '烟霾', 'haze': '霾',
|
|
406
|
+
'light drizzle': '小毛毛雨', 'drizzle': '毛毛雨', 'freezing drizzle': '冻毛毛雨',
|
|
407
|
+
}
|
|
408
|
+
for (const [key, zh] of Object.entries(map)) {
|
|
409
|
+
if (text.includes(key)) return zh
|
|
410
|
+
}
|
|
411
|
+
return desc || '未知天气'
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
async function fetchWeather(city) {
|
|
415
|
+
const rawName = String(city || '').trim()
|
|
416
|
+
const useLocal = !rawName || rawName === '本地' || rawName === 'default' || rawName === '当前位置'
|
|
417
|
+
let name = rawName
|
|
418
|
+
if (useLocal) {
|
|
419
|
+
try {
|
|
420
|
+
const ipRes = await fetch('https://ipwho.is/', { signal: AbortSignal.timeout(8000) })
|
|
421
|
+
if (ipRes.ok) {
|
|
422
|
+
const ip = await ipRes.json()
|
|
423
|
+
name = ip.city || '北京'
|
|
424
|
+
const lat = ip.latitude
|
|
425
|
+
const lon = ip.longitude
|
|
426
|
+
if (lat && lon) {
|
|
427
|
+
const wRes = await fetch(`https://wttr.in/${lat},${lon}?format=j1`, { signal: AbortSignal.timeout(8000) })
|
|
428
|
+
if (wRes.ok) {
|
|
429
|
+
const data = await wRes.json()
|
|
430
|
+
const cur = data?.current_condition?.[0]
|
|
431
|
+
if (cur) {
|
|
432
|
+
const temp = Math.round(Number(cur.temp_C) || 0)
|
|
433
|
+
const desc = translateWeatherDesc(cur.lang_zh?.[0]?.value || cur.weatherDesc?.[0]?.value || '')
|
|
434
|
+
const hum = cur.humidity
|
|
435
|
+
return { ok: true, text: `${name} 当前 ${temp}°C,${desc},湿度 ${hum}%` }
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
} else {
|
|
440
|
+
name = '北京'
|
|
441
|
+
}
|
|
442
|
+
} catch {
|
|
443
|
+
name = '北京'
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (!name) name = '北京'
|
|
447
|
+
// 1. Nominatim 中文地理编码 + wttr.in 坐标查询(国内可用性较好)
|
|
448
|
+
try {
|
|
449
|
+
const geoRes = await fetch(`https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(name)}&format=json&limit=1`, {
|
|
450
|
+
headers: { 'User-Agent': 'better-dsh-pet' },
|
|
451
|
+
signal: AbortSignal.timeout(8000),
|
|
452
|
+
})
|
|
453
|
+
if (geoRes.ok) {
|
|
454
|
+
const geo = await geoRes.json()
|
|
455
|
+
const loc = geo?.[0]
|
|
456
|
+
if (loc) {
|
|
457
|
+
const lat = loc.lat
|
|
458
|
+
const lon = loc.lon
|
|
459
|
+
const place = String(loc.display_name || name).split(',')[0] || name
|
|
460
|
+
const wRes = await fetch(`https://wttr.in/${lat},${lon}?format=j1`, { signal: AbortSignal.timeout(8000) })
|
|
461
|
+
if (wRes.ok) {
|
|
462
|
+
const data = await wRes.json()
|
|
463
|
+
const cur = data?.current_condition?.[0]
|
|
464
|
+
if (cur) {
|
|
465
|
+
const temp = Math.round(Number(cur.temp_C) || 0)
|
|
466
|
+
const desc = translateWeatherDesc(cur.lang_zh?.[0]?.value || cur.weatherDesc?.[0]?.value || '')
|
|
467
|
+
const hum = cur.humidity
|
|
468
|
+
return { ok: true, text: `${place} 当前 ${temp}°C,${desc},湿度 ${hum}%` }
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
} catch {
|
|
474
|
+
// 继续 fallback
|
|
475
|
+
}
|
|
476
|
+
// 2. Open-Meteo 地理编码 + 预报
|
|
477
|
+
try {
|
|
478
|
+
const geoRes = await fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(name)}&count=1&language=zh&format=json`, { signal: AbortSignal.timeout(8000) })
|
|
479
|
+
if (geoRes.ok) {
|
|
480
|
+
const geo = await geoRes.json()
|
|
481
|
+
const loc = geo?.results?.[0]
|
|
482
|
+
if (loc) {
|
|
483
|
+
const lat = loc.latitude
|
|
484
|
+
const lon = loc.longitude
|
|
485
|
+
const place = loc.name || name
|
|
486
|
+
const region = [loc.admin1, loc.country].filter(Boolean).join(' ')
|
|
487
|
+
const wxRes = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}¤t_weather=true&timezone=auto`, { signal: AbortSignal.timeout(8000) })
|
|
488
|
+
if (wxRes.ok) {
|
|
489
|
+
const wx = await wxRes.json()
|
|
490
|
+
const cur = wx?.current_weather
|
|
491
|
+
if (cur) {
|
|
492
|
+
const temp = Math.round(cur.temperature)
|
|
493
|
+
const desc = weatherCodeText(cur.weathercode)
|
|
494
|
+
const wind = Math.round(cur.windspeed)
|
|
495
|
+
return { ok: true, text: `${place}${region ? ' ' + region : ''} 当前 ${temp}°C,${desc},风速 ${wind}km/h` }
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
} catch {
|
|
501
|
+
// 继续 fallback
|
|
502
|
+
}
|
|
503
|
+
// 3. wttr.in 按城市名兜底
|
|
504
|
+
try {
|
|
505
|
+
const wRes = await fetch(`https://wttr.in/${encodeURIComponent(name)}?format=j1`, { signal: AbortSignal.timeout(8000) })
|
|
506
|
+
if (wRes.ok) {
|
|
507
|
+
const data = await wRes.json()
|
|
508
|
+
const cur = data?.current_condition?.[0]
|
|
509
|
+
if (cur) {
|
|
510
|
+
const temp = Math.round(Number(cur.temp_C) || 0)
|
|
511
|
+
const desc = translateWeatherDesc(cur.lang_zh?.[0]?.value || cur.weatherDesc?.[0]?.value || '')
|
|
512
|
+
const hum = cur.humidity
|
|
513
|
+
return { ok: true, text: `${name} 当前 ${temp}°C,${desc},湿度 ${hum}%` }
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
} catch {
|
|
517
|
+
// ignore
|
|
518
|
+
}
|
|
519
|
+
return { ok: false, error: '天气查询失败,请稍后再试~' }
|
|
520
|
+
}
|
|
521
|
+
|
|
363
522
|
function speakText(text) {
|
|
364
523
|
const safeText = String(text || '').slice(0, 200)
|
|
365
524
|
if (!safeText) return
|
|
@@ -392,8 +551,8 @@ try {
|
|
|
392
551
|
$culture = [System.Globalization.CultureInfo]::GetCultureInfo('zh-CN')
|
|
393
552
|
$recognizer = New-Object System.Speech.Recognition.SpeechRecognitionEngine($culture)
|
|
394
553
|
$recognizer.SetInputToDefaultAudioDevice()
|
|
395
|
-
$wake = $env:DSH_PET_WAKE_WORD
|
|
396
|
-
if (-not $wake) { $wake = '大肥鱼' }
|
|
554
|
+
$wake = $env:DSH_PET_WAKE_WORD
|
|
555
|
+
if (-not $wake) { $wake = '大肥鱼' }
|
|
397
556
|
$choices = New-Object System.Speech.Recognition.Choices
|
|
398
557
|
$choices.Add("\${wake}开始番茄钟")
|
|
399
558
|
$choices.Add("嗨\${wake}开始番茄钟")
|
|
@@ -406,6 +565,17 @@ try {
|
|
|
406
565
|
$choices.Add("\${wake}余额")
|
|
407
566
|
$choices.Add("\${wake}吐槽")
|
|
408
567
|
$choices.Add("\${wake}设置")
|
|
568
|
+
$choices.Add("\${wake}查天气")
|
|
569
|
+
$choices.Add("嗨\${wake}查天气")
|
|
570
|
+
$choices.Add("\${wake}天气")
|
|
571
|
+
$choices.Add("嗨\${wake}天气")
|
|
572
|
+
$choices.Add("\${wake}气温")
|
|
573
|
+
$choices.Add("\${wake}温度")
|
|
574
|
+
$choices.Add("\${wake}几度")
|
|
575
|
+
$choices.Add("\${wake}下雨吗")
|
|
576
|
+
$choices.Add("\${wake}下雪吗")
|
|
577
|
+
$choices.Add("\${wake}冷不冷")
|
|
578
|
+
$choices.Add("\${wake}热不热")
|
|
409
579
|
$choices.Add("\${wake}你在吗")
|
|
410
580
|
$choices.Add("\${wake}在吗")
|
|
411
581
|
$choices.Add("嗨\${wake}你在吗")
|
|
@@ -414,10 +584,21 @@ try {
|
|
|
414
584
|
$choices.Add("嗨\${wake}")
|
|
415
585
|
$grammar = New-Object System.Speech.Recognition.Grammar($choices)
|
|
416
586
|
$recognizer.LoadGrammar($grammar)
|
|
587
|
+
$recognizer.BabbleTimeout = [TimeSpan]::FromSeconds(5)
|
|
588
|
+
$recognizer.InitialSilenceTimeout = [TimeSpan]::FromSeconds(5)
|
|
589
|
+
$recognizer.EndSilenceTimeout = [TimeSpan]::FromSeconds(2)
|
|
417
590
|
while ($true) {
|
|
418
591
|
$result = $recognizer.Recognize()
|
|
419
592
|
if ($result -ne $null) {
|
|
420
|
-
|
|
593
|
+
$text = $result.Text
|
|
594
|
+
if ($text -eq $wake -or $text -eq "嗨$wake") {
|
|
595
|
+
$dictation = New-Object System.Speech.Recognition.DictationGrammar
|
|
596
|
+
$recognizer.LoadGrammar($dictation)
|
|
597
|
+
$follow = $recognizer.Recognize()
|
|
598
|
+
$recognizer.UnloadGrammar($dictation)
|
|
599
|
+
if ($follow -ne $null -and $follow.Text) { $text = $text + $follow.Text }
|
|
600
|
+
}
|
|
601
|
+
'CMD:' + $text
|
|
421
602
|
}
|
|
422
603
|
}
|
|
423
604
|
} catch {
|
|
@@ -426,7 +607,7 @@ try {
|
|
|
426
607
|
`
|
|
427
608
|
const child = spawn('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', script], {
|
|
428
609
|
windowsHide: true,
|
|
429
|
-
env: { ...process.env, DSH_PET_WAKE_WORD: currentWakeWord },
|
|
610
|
+
env: { ...process.env, DSH_PET_WAKE_WORD: currentWakeWord },
|
|
430
611
|
})
|
|
431
612
|
let buffer = ''
|
|
432
613
|
child.stdout.on('data', (chunk) => {
|
|
@@ -511,8 +692,8 @@ function createWindow() {
|
|
|
511
692
|
voiceSilenceMs: process.env.DSH_PET_VOICE_SILENCE_MS || '1200',
|
|
512
693
|
voiceAutoSend: process.env.DSH_PET_VOICE_AUTO_SEND === '0' ? '0' : '1',
|
|
513
694
|
voiceAutoRecord: process.env.DSH_PET_VOICE_AUTO_RECORD === '0' ? '0' : '1',
|
|
514
|
-
holidayEnabled: process.env.DSH_PET_HOLIDAY_ENABLED === '1' ? '1' : '0',
|
|
515
|
-
wakeWord: process.env.DSH_PET_WAKE_WORD || '大肥鱼',
|
|
695
|
+
holidayEnabled: process.env.DSH_PET_HOLIDAY_ENABLED === '1' ? '1' : '0',
|
|
696
|
+
wakeWord: process.env.DSH_PET_WAKE_WORD || '大肥鱼',
|
|
516
697
|
taskCwd: process.env.DSH_PET_TASK_CWD || '',
|
|
517
698
|
},
|
|
518
699
|
}).then(() => {
|
|
@@ -590,6 +771,14 @@ app.whenReady().then(() => {
|
|
|
590
771
|
ipcMain.on('pet:set-ignore-mouse', (_event, { ignore }) => {
|
|
591
772
|
setClickThrough(ignore === true)
|
|
592
773
|
})
|
|
774
|
+
ipcMain.on('pet:set-force-click-through', (_event, enabled) => {
|
|
775
|
+
forceClickThrough = !!enabled
|
|
776
|
+
if (mainWindow && !mainWindow.isDestroyed()) {
|
|
777
|
+
mainWindow.webContents.send('pet:force-click-through', forceClickThrough)
|
|
778
|
+
mainWindow.setIgnoreMouseEvents(forceClickThrough, { forward: true })
|
|
779
|
+
}
|
|
780
|
+
updateTrayMenu()
|
|
781
|
+
})
|
|
593
782
|
ipcMain.on('pet:beep', () => {
|
|
594
783
|
try { shell.beep() } catch { /* 系统不支持时忽略 */ }
|
|
595
784
|
})
|
|
@@ -626,14 +815,14 @@ app.whenReady().then(() => {
|
|
|
626
815
|
event.sender.send('pet:wake-state', true)
|
|
627
816
|
}
|
|
628
817
|
})
|
|
629
|
-
ipcMain.on('pet:set-wake-word', (event, word) => {
|
|
630
|
-
currentWakeWord = String(word || '大肥鱼').trim() || '大肥鱼'
|
|
631
|
-
if (wakeWordProcess) {
|
|
632
|
-
stopWakeWordListener()
|
|
633
|
-
startWakeWordListener()
|
|
634
|
-
}
|
|
635
|
-
event.sender.send('pet:wake-state', Boolean(wakeWordProcess))
|
|
636
|
-
})
|
|
818
|
+
ipcMain.on('pet:set-wake-word', (event, word) => {
|
|
819
|
+
currentWakeWord = String(word || '大肥鱼').trim() || '大肥鱼'
|
|
820
|
+
if (wakeWordProcess) {
|
|
821
|
+
stopWakeWordListener()
|
|
822
|
+
startWakeWordListener()
|
|
823
|
+
}
|
|
824
|
+
event.sender.send('pet:wake-state', Boolean(wakeWordProcess))
|
|
825
|
+
})
|
|
637
826
|
ipcMain.handle('pet:chat', async (_event, message) => {
|
|
638
827
|
const statusUrl = process.env.DSH_PET_STATUS_URL
|
|
639
828
|
if (!statusUrl || !message) return { ok: false, reply: '消息不能为空~' }
|
|
@@ -650,38 +839,39 @@ app.whenReady().then(() => {
|
|
|
650
839
|
return { ok: false, reply: '网络开小差了,等会儿再聊吧~' }
|
|
651
840
|
}
|
|
652
841
|
})
|
|
653
|
-
ipcMain.handle('pet:intent', async (_event, text) => {
|
|
654
|
-
const statusUrl = process.env.DSH_PET_STATUS_URL
|
|
655
|
-
if (!statusUrl || !text) return { ok: false, type: 'chat' }
|
|
656
|
-
try {
|
|
657
|
-
const intentUrl = statusUrl.replace(/\/plugins\/better-dsh-pet\/status$/, '/plugins/better-dsh-pet/intent')
|
|
658
|
-
const response = await fetch(intentUrl, {
|
|
659
|
-
method: 'POST',
|
|
660
|
-
headers: { 'content-type': 'application/json' },
|
|
661
|
-
body: JSON.stringify({ text }),
|
|
662
|
-
})
|
|
663
|
-
const data = await response.json()
|
|
664
|
-
return data
|
|
665
|
-
} catch {
|
|
666
|
-
return { ok: false, type: 'chat' }
|
|
667
|
-
}
|
|
668
|
-
})
|
|
669
|
-
ipcMain.handle('pet:task', async (_event, task) => {
|
|
670
|
-
const statusUrl = process.env.DSH_PET_STATUS_URL
|
|
671
|
-
if (!statusUrl || !task) return { ok: false, result: '任务内容为空~' }
|
|
672
|
-
try {
|
|
673
|
-
const taskUrl = statusUrl.replace(/\/plugins\/better-dsh-pet\/status$/, '/plugins/better-dsh-pet/task')
|
|
674
|
-
const response = await fetch(taskUrl, {
|
|
675
|
-
method: 'POST',
|
|
676
|
-
headers: { 'content-type': 'application/json' },
|
|
677
|
-
body: JSON.stringify({ task }),
|
|
678
|
-
})
|
|
679
|
-
const data = await response.json()
|
|
680
|
-
return data
|
|
681
|
-
} catch {
|
|
682
|
-
return { ok: false, result: '任务执行时网络开小差了~' }
|
|
683
|
-
}
|
|
684
|
-
})
|
|
842
|
+
ipcMain.handle('pet:intent', async (_event, text) => {
|
|
843
|
+
const statusUrl = process.env.DSH_PET_STATUS_URL
|
|
844
|
+
if (!statusUrl || !text) return { ok: false, type: 'chat' }
|
|
845
|
+
try {
|
|
846
|
+
const intentUrl = statusUrl.replace(/\/plugins\/better-dsh-pet\/status$/, '/plugins/better-dsh-pet/intent')
|
|
847
|
+
const response = await fetch(intentUrl, {
|
|
848
|
+
method: 'POST',
|
|
849
|
+
headers: { 'content-type': 'application/json' },
|
|
850
|
+
body: JSON.stringify({ text }),
|
|
851
|
+
})
|
|
852
|
+
const data = await response.json()
|
|
853
|
+
return data
|
|
854
|
+
} catch {
|
|
855
|
+
return { ok: false, type: 'chat' }
|
|
856
|
+
}
|
|
857
|
+
})
|
|
858
|
+
ipcMain.handle('pet:task', async (_event, task) => {
|
|
859
|
+
const statusUrl = process.env.DSH_PET_STATUS_URL
|
|
860
|
+
if (!statusUrl || !task) return { ok: false, result: '任务内容为空~' }
|
|
861
|
+
try {
|
|
862
|
+
const taskUrl = statusUrl.replace(/\/plugins\/better-dsh-pet\/status$/, '/plugins/better-dsh-pet/task')
|
|
863
|
+
const response = await fetch(taskUrl, {
|
|
864
|
+
method: 'POST',
|
|
865
|
+
headers: { 'content-type': 'application/json' },
|
|
866
|
+
body: JSON.stringify({ task }),
|
|
867
|
+
})
|
|
868
|
+
const data = await response.json()
|
|
869
|
+
return data
|
|
870
|
+
} catch {
|
|
871
|
+
return { ok: false, result: '任务执行时网络开小差了~' }
|
|
872
|
+
}
|
|
873
|
+
})
|
|
874
|
+
ipcMain.handle('pet:weather', async (_event, city) => fetchWeather(city))
|
|
685
875
|
ipcMain.handle('pet:transcribe', async (_event, wavBuffer) => {
|
|
686
876
|
const statusUrl = process.env.DSH_PET_STATUS_URL
|
|
687
877
|
if (!statusUrl || !wavBuffer) return { ok: false, text: '' }
|
|
@@ -27,6 +27,14 @@ contextBridge.exposeInMainWorld('petBridge', {
|
|
|
27
27
|
setIgnoreMouse(ignore) {
|
|
28
28
|
ipcRenderer.send('pet:set-ignore-mouse', { ignore })
|
|
29
29
|
},
|
|
30
|
+
setForceClickThrough(enabled) {
|
|
31
|
+
ipcRenderer.send('pet:set-force-click-through', enabled)
|
|
32
|
+
},
|
|
33
|
+
onForceClickThrough(callback) {
|
|
34
|
+
const listener = (_event, enabled) => callback(enabled)
|
|
35
|
+
ipcRenderer.on('pet:force-click-through', listener)
|
|
36
|
+
return () => ipcRenderer.removeListener('pet:force-click-through', listener)
|
|
37
|
+
},
|
|
30
38
|
beep() {
|
|
31
39
|
ipcRenderer.send('pet:beep')
|
|
32
40
|
},
|
|
@@ -67,6 +75,9 @@ contextBridge.exposeInMainWorld('petBridge', {
|
|
|
67
75
|
executeTask(task) {
|
|
68
76
|
return ipcRenderer.invoke('pet:task', task)
|
|
69
77
|
},
|
|
78
|
+
getWeather(city) {
|
|
79
|
+
return ipcRenderer.invoke('pet:weather', city)
|
|
80
|
+
},
|
|
70
81
|
startDictation() {
|
|
71
82
|
ipcRenderer.send('pet:dictation-start')
|
|
72
83
|
},
|
|
@@ -390,6 +390,7 @@ let idleDelayTimer = null
|
|
|
390
390
|
// 情绪:mood -100~100(负=低落,正=开心),energy 0~100,anxiety 0~100,boredom 0~100
|
|
391
391
|
const EMOTION_STORAGE_KEY = 'better-dsh-pet:emotion'
|
|
392
392
|
let emotion = { mood: 0, energy: 100, anxiety: 0, boredom: 0 }
|
|
393
|
+
let forceClickThrough = false
|
|
393
394
|
let wakeWordEnabled = false
|
|
394
395
|
let festivalPlayToken = 0
|
|
395
396
|
let festivalActive = false
|
|
@@ -976,9 +977,12 @@ function applyTasksMessage(message) {
|
|
|
976
977
|
}
|
|
977
978
|
|
|
978
979
|
// ---------- 喂食/互动反馈 ----------
|
|
979
|
-
function showManualBubble(message, detail, ttl = 2200) {
|
|
980
|
+
function showManualBubble(message, detail, ttl = 2200, priority = false) {
|
|
981
|
+
const now = Date.now()
|
|
982
|
+
// 高优先级气泡(如天气)显示期间,普通动作/状态气泡不能覆盖它。
|
|
983
|
+
if (manualBubble?.priority && manualBubble.expiresAt > now && !priority) return
|
|
980
984
|
if (manualBubbleTimer) clearTimeout(manualBubbleTimer)
|
|
981
|
-
manualBubble = { message, detail, expiresAt:
|
|
985
|
+
manualBubble = { message, detail, expiresAt: now + ttl, priority }
|
|
982
986
|
manualBubbleTimer = setTimeout(() => {
|
|
983
987
|
manualBubble = null
|
|
984
988
|
manualBubbleTimer = null
|
|
@@ -1149,10 +1153,17 @@ function updateClickThrough() {
|
|
|
1149
1153
|
const overlayVisible = menuEl.classList.contains('visible')
|
|
1150
1154
|
|| settingsPanel.classList.contains('visible')
|
|
1151
1155
|
|| chatPanel.classList.contains('visible')
|
|
1152
|
-
const ignore = !inside && !dragging && !dragState.active && !overlayVisible
|
|
1156
|
+
const ignore = forceClickThrough || (!inside && !dragging && !dragState.active && !overlayVisible)
|
|
1153
1157
|
window.petBridge.setIgnoreMouse(ignore)
|
|
1154
1158
|
}
|
|
1155
1159
|
|
|
1160
|
+
function setForceClickThrough(enabled) {
|
|
1161
|
+
forceClickThrough = !!enabled
|
|
1162
|
+
updateClickThrough()
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
window.petBridge.onForceClickThrough?.(setForceClickThrough)
|
|
1166
|
+
|
|
1156
1167
|
document.addEventListener('mousemove', (e) => {
|
|
1157
1168
|
lastMouse = { x: e.clientX, y: e.clientY }
|
|
1158
1169
|
updateClickThrough()
|
|
@@ -1357,6 +1368,7 @@ function renderSettingsPanelContent() {
|
|
|
1357
1368
|
<h3>功能</h3>
|
|
1358
1369
|
<div class="field"><label>自动吐槽</label><span class="checkbox-field"><input type="checkbox" id="set-roastEnabled" ${CONFIG.roastEnabled ? 'checked' : ''}> 开启</span></div>
|
|
1359
1370
|
<div class="field"><label>节日祝福</label><span class="checkbox-field"><input type="checkbox" id="set-holidayEnabled" ${CONFIG.holidayEnabled ? 'checked' : ''}> 开启</span></div>
|
|
1371
|
+
<div class="field"><label>默认天气城市</label><input type="text" id="set-weatherCity" placeholder="如:北京(留空=自动定位)" value="${CONFIG.weatherCity || ''}"></div>
|
|
1360
1372
|
<div class="field"><label>气泡模式</label><select id="set-bubbleMode">
|
|
1361
1373
|
<option value="always" ${CONFIG.bubbleMode === 'always' ? 'selected' : ''}>常驻显示</option>
|
|
1362
1374
|
<option value="hidden" ${CONFIG.bubbleMode === 'hidden' ? 'selected' : ''}>完全隐藏</option>
|
|
@@ -1424,6 +1436,7 @@ function saveSettingsPanel() {
|
|
|
1424
1436
|
const breakMinutes = number('#set-breakMinutes', CONFIG.breakMinutes, 1, 60)
|
|
1425
1437
|
const roastEnabled = val('#set-roastEnabled').checked
|
|
1426
1438
|
const holidayEnabled = val('#set-holidayEnabled').checked
|
|
1439
|
+
const weatherCity = val('#set-weatherCity').value.trim()
|
|
1427
1440
|
const bubbleMode = val('#set-bubbleMode').value
|
|
1428
1441
|
const bubbleStates = parseList(val('#set-bubbleStates').value)
|
|
1429
1442
|
const enabledActions = parseList(val('#set-enabledActions').value)
|
|
@@ -1432,7 +1445,7 @@ function saveSettingsPanel() {
|
|
|
1432
1445
|
Object.assign(CONFIG, {
|
|
1433
1446
|
petSize, moveChance, actionDelayMs, playbackRate, activityLevel,
|
|
1434
1447
|
reducedMotion, walkEnabled, workMinutes, breakMinutes, roastEnabled,
|
|
1435
|
-
holidayEnabled,
|
|
1448
|
+
holidayEnabled, weatherCity,
|
|
1436
1449
|
bubbleMode, bubbleStates, enabledActions, actionOrder,
|
|
1437
1450
|
})
|
|
1438
1451
|
for (const video of [videoA, videoB]) {
|
|
@@ -1442,7 +1455,7 @@ function saveSettingsPanel() {
|
|
|
1442
1455
|
window.petBridge.saveConfig({
|
|
1443
1456
|
petSize, moveChance, actionDelayMs, playbackRate, activityLevel,
|
|
1444
1457
|
reducedMotion, walkEnabled, workMinutes, breakMinutes, roastEnabled,
|
|
1445
|
-
holidayEnabled,
|
|
1458
|
+
holidayEnabled, weatherCity,
|
|
1446
1459
|
bubbleMode, bubbleStates, enabledActions, actionOrder,
|
|
1447
1460
|
})
|
|
1448
1461
|
if (holidayEnabled) maybeAutoPlayFestival()
|
|
@@ -1619,8 +1632,19 @@ async function sendChatText(content) {
|
|
|
1619
1632
|
}
|
|
1620
1633
|
}
|
|
1621
1634
|
|
|
1635
|
+
function extractWeatherCity(text) {
|
|
1636
|
+
const wake = CONFIG.wakeWord || '大肥鱼'
|
|
1637
|
+
let t = String(text || '').replace(/[\s\u3000,。!?、,.!?;;::]+/g, '')
|
|
1638
|
+
t = t.replace(new RegExp(`^(嗨?${wake})`), '')
|
|
1639
|
+
t = t.replace(/^(查一下|查查|帮我|看看|今天|现在|请问|给我|查|本地)/g, '')
|
|
1640
|
+
const m = t.match(/([\u4e00-\u9fa5]{2,6}?)(?:天气|气温|温度|几度|下雨|下雪|天起|天汽|冷不冷|热不热|晴不晴)/)
|
|
1641
|
+
let city = m?.[1] || ''
|
|
1642
|
+
city = city.replace(/^(今天|现在|查一下|查查|帮我|看看|本地|请问|给我|查)$/g, '').trim()
|
|
1643
|
+
return city
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1622
1646
|
function matchRuleCommand(text) {
|
|
1623
|
-
const t = String(text || '')
|
|
1647
|
+
const t = String(text || '').replace(/[\s\u3000,。!?、,.!?;;::]+/g, '')
|
|
1624
1648
|
if (t.includes('停止番茄钟')) return { action: 'pomodoro_stop' }
|
|
1625
1649
|
if (t.includes('开始番茄钟') || t.includes('番茄钟')) return { action: 'pomodoro_start' }
|
|
1626
1650
|
if (t.includes('喂食') || t.includes('吃饭')) return { action: 'feed' }
|
|
@@ -1636,9 +1660,24 @@ function matchRuleCommand(text) {
|
|
|
1636
1660
|
if (t.includes('中间') || t.includes('居中')) return { action: 'move_pet', args: { position: 'center' } }
|
|
1637
1661
|
if (t.includes('上面') || t.includes('顶部') || t.includes('上方')) return { action: 'move_pet', args: { position: 'top' } }
|
|
1638
1662
|
if (t.includes('下面') || t.includes('底部') || t.includes('下方')) return { action: 'move_pet', args: { position: 'bottom' } }
|
|
1663
|
+
if (['天气', '气温', '温度', '几度', '下雨', '下雪', '天起', '天汽', '冷不冷', '热不热', '晴不晴'].some((k) => t.includes(k))) {
|
|
1664
|
+
return { action: 'weather', args: { city: extractWeatherCity(t) } }
|
|
1665
|
+
}
|
|
1639
1666
|
return null
|
|
1640
1667
|
}
|
|
1641
1668
|
|
|
1669
|
+
async function queryWeather(city) {
|
|
1670
|
+
const defaultCity = String(CONFIG.weatherCity || '').trim()
|
|
1671
|
+
const target = String(city || '').trim() || defaultCity || '本地'
|
|
1672
|
+
showManualBubble('正在查询天气~', target && target !== '本地' ? `城市:${target}` : '正在定位本地天气', 2000)
|
|
1673
|
+
const result = await window.petBridge.getWeather(target)
|
|
1674
|
+
if (result?.ok) {
|
|
1675
|
+
showManualBubble(`🌤 ${result.text}`, '天气', 5000, true)
|
|
1676
|
+
} else {
|
|
1677
|
+
showManualBubble('天气查询失败', result?.error || '请稍后再试~', 3000, true)
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1642
1681
|
function executeAction(action, args = {}) {
|
|
1643
1682
|
switch (action) {
|
|
1644
1683
|
case 'pomodoro_start':
|
|
@@ -1693,6 +1732,9 @@ function executeAction(action, args = {}) {
|
|
|
1693
1732
|
showManualBubble(`好的,${minutes}分钟后提醒你`, text, 3000)
|
|
1694
1733
|
return true
|
|
1695
1734
|
}
|
|
1735
|
+
case 'weather':
|
|
1736
|
+
void queryWeather(args.city)
|
|
1737
|
+
return true
|
|
1696
1738
|
default:
|
|
1697
1739
|
return false
|
|
1698
1740
|
}
|
|
@@ -1933,6 +1975,7 @@ function renderSettingsPage() {
|
|
|
1933
1975
|
<label class="ms-check"><input type="checkbox" id="ms-voiceAutoRecord" ${CONFIG.voiceAutoRecord !== false ? 'checked' : ''}> 闲聊时说“大肥鱼”自动录音</label>
|
|
1934
1976
|
<div class="ms-field"><span>唤醒词</span><input type="text" id="ms-wakeWord" value="${CONFIG.wakeWord}" placeholder="例如:大肥鱼"></div>
|
|
1935
1977
|
<div class="ms-field"><span>任务目录</span><input type="text" id="ms-taskCwd" value="${CONFIG.taskCwd || ''}" placeholder="留空=用户主目录"></div>
|
|
1978
|
+
<div class="ms-field"><span>天气城市</span><input type="text" id="ms-weatherCity" value="${CONFIG.weatherCity || ''}" placeholder="留空=自动定位"></div>
|
|
1936
1979
|
<div class="ms-field"><span>气泡模式</span><span id="ms-bubbleMode" class="ms-seg"></span></div>
|
|
1937
1980
|
<div class="ms-field"><span>气泡状态</span><textarea id="ms-bubbleStates" placeholder="SUCCESS,ERROR,WAITING">${bubbleStatesText}</textarea></div>
|
|
1938
1981
|
<div id="ms-festival-area" style="margin-top:8px;padding-top:8px;border-top:1px solid #eee">
|
|
@@ -2118,6 +2161,7 @@ function renderSettingsPage() {
|
|
|
2118
2161
|
const holidayEnabled = val('#ms-holidayEnabled').checked
|
|
2119
2162
|
const wakeWord = val('#ms-wakeWord').value.trim() || '大肥鱼'
|
|
2120
2163
|
const taskCwd = val('#ms-taskCwd').value.trim()
|
|
2164
|
+
const weatherCity = val('#ms-weatherCity').value.trim()
|
|
2121
2165
|
const voiceEnabled = val('#ms-voiceEnabled').checked
|
|
2122
2166
|
const voiceWakeAutoStart = val('#ms-voiceWakeAutoStart').checked
|
|
2123
2167
|
const voiceSilenceMs = number('#ms-voiceSilenceMs', CONFIG.voiceSilenceMs, 300, 5000)
|
|
@@ -2132,6 +2176,7 @@ function renderSettingsPage() {
|
|
|
2132
2176
|
holidayEnabled,
|
|
2133
2177
|
wakeWord,
|
|
2134
2178
|
taskCwd,
|
|
2179
|
+
weatherCity,
|
|
2135
2180
|
voiceEnabled,
|
|
2136
2181
|
voiceWakeAutoStart,
|
|
2137
2182
|
voiceSilenceMs,
|
|
@@ -2153,6 +2198,7 @@ function renderSettingsPage() {
|
|
|
2153
2198
|
holidayEnabled,
|
|
2154
2199
|
wakeWord,
|
|
2155
2200
|
taskCwd,
|
|
2201
|
+
weatherCity,
|
|
2156
2202
|
voiceEnabled,
|
|
2157
2203
|
voiceWakeAutoStart,
|
|
2158
2204
|
voiceSilenceMs,
|
|
@@ -2259,6 +2305,18 @@ function renderMainMenu() {
|
|
|
2259
2305
|
updateClickThrough()
|
|
2260
2306
|
openChat()
|
|
2261
2307
|
})
|
|
2308
|
+
addMenuButton(forceClickThrough ? '关闭鼠标穿透' : '开启鼠标穿透', () => {
|
|
2309
|
+
const next = !forceClickThrough
|
|
2310
|
+
setForceClickThrough(next)
|
|
2311
|
+
window.petBridge.setForceClickThrough(next)
|
|
2312
|
+
menuEl.classList.remove('visible')
|
|
2313
|
+
updateClickThrough()
|
|
2314
|
+
showManualBubble(
|
|
2315
|
+
next ? '鼠标穿透已开启' : '鼠标穿透已关闭',
|
|
2316
|
+
next ? '现在可以直接点击穿透大肥鱼' : '',
|
|
2317
|
+
2500,
|
|
2318
|
+
)
|
|
2319
|
+
})
|
|
2262
2320
|
addMenuButton('检查更新', () => {
|
|
2263
2321
|
menuEl.classList.remove('visible')
|
|
2264
2322
|
updateClickThrough()
|
|
@@ -2665,7 +2723,9 @@ function applyStatus(incoming) {
|
|
|
2665
2723
|
}
|
|
2666
2724
|
|
|
2667
2725
|
async function handleVoiceCommand(text) {
|
|
2668
|
-
const
|
|
2726
|
+
const raw = String(text || '').trim()
|
|
2727
|
+
// 去掉语音识别常见的空格/标点,避免“开始 番茄 钟”匹配不到“番茄钟”
|
|
2728
|
+
const command = raw.replace(/[\s\u3000,。!?、,.!?;;::]+/g, '')
|
|
2669
2729
|
if (!command) {
|
|
2670
2730
|
showManualBubble('没听清,再说一次吧~', '', 2500)
|
|
2671
2731
|
return
|
|
@@ -2721,6 +2781,8 @@ async function handleVoiceCommand(text) {
|
|
|
2721
2781
|
} else if (command.includes('设置')) {
|
|
2722
2782
|
menuPage = 'settings'
|
|
2723
2783
|
showMenu(lastMenuPos.x, lastMenuPos.y)
|
|
2784
|
+
} else if (['天气', '气温', '温度', '几度', '下雨', '下雪', '天起', '天汽', '冷不冷', '热不热', '晴不晴'].some((k) => command.includes(k))) {
|
|
2785
|
+
void queryWeather(extractWeatherCity(command))
|
|
2724
2786
|
} else {
|
|
2725
2787
|
showManualBubble(`你说的是“${command}”?我还没学会~`, '', 3000)
|
|
2726
2788
|
}
|
|
@@ -35,9 +35,9 @@ const DEFAULT_MODEL_URL = 'https://github.com/k2-fsa/sherpa-onnx/releases/downlo
|
|
|
35
35
|
const MODEL_URLS = [
|
|
36
36
|
process.env.DSH_VOICE_MODEL_URL,
|
|
37
37
|
DEFAULT_MODEL_URL,
|
|
38
|
-
`https://ghproxy.net/${DEFAULT_MODEL_URL}`,
|
|
39
|
-
`https://ghfast.top/${DEFAULT_MODEL_URL}`,
|
|
40
38
|
`https://gh-proxy.com/${DEFAULT_MODEL_URL}`,
|
|
39
|
+
`https://ghfast.top/${DEFAULT_MODEL_URL}`,
|
|
40
|
+
`https://gh.llkk.cc/${DEFAULT_MODEL_URL}`,
|
|
41
41
|
].filter((url, index, arr) => typeof url === 'string' && url.trim() !== '' && arr.indexOf(url) === index)
|
|
42
42
|
const REQUIRED = ['model.int8.onnx', 'tokens.txt']
|
|
43
43
|
const LOG_FILE = join(DSH_HOME, 'logs', 'better-dsh-pet-sensevoice.log')
|
|
@@ -70,8 +70,8 @@ async function download(url, dest, label = 'download') {
|
|
|
70
70
|
let connected = false
|
|
71
71
|
let lastChunkAt = Date.now()
|
|
72
72
|
const connectTimer = setTimeout(() => {
|
|
73
|
-
if (!connected) controller.abort(new Error('连接超时(
|
|
74
|
-
},
|
|
73
|
+
if (!connected) controller.abort(new Error('连接超时(15秒未响应)'))
|
|
74
|
+
}, 15000)
|
|
75
75
|
let stallTimer
|
|
76
76
|
try {
|
|
77
77
|
log(`[${label}] 等待响应...`)
|
|
@@ -85,10 +85,10 @@ async function download(url, dest, label = 'download') {
|
|
|
85
85
|
let lastPercent = -1
|
|
86
86
|
lastChunkAt = Date.now()
|
|
87
87
|
stallTimer = setInterval(() => {
|
|
88
|
-
if (Date.now() - lastChunkAt >
|
|
89
|
-
controller.abort(new Error('下载停滞(
|
|
88
|
+
if (Date.now() - lastChunkAt > 10000) {
|
|
89
|
+
controller.abort(new Error('下载停滞(10秒无数据)'))
|
|
90
90
|
}
|
|
91
|
-
},
|
|
91
|
+
}, 3000)
|
|
92
92
|
const progress = new Transform({
|
|
93
93
|
transform(chunk, _encoding, callback) {
|
|
94
94
|
received += chunk.length
|