better-dsh-pet 0.2.3 → 0.2.5

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/lib/client.js CHANGED
@@ -276,10 +276,25 @@ window.__ModuleLoader__.load({
276
276
  }
277
277
 
278
278
  function apply(ctx) {
279
- ctx.slots.inject('settings.plugin.item', () => ctx.slots.register({
280
- name: 'settings.plugin.item', id: 'better-dsh-pet', order: 30,
281
- inject: () => ({}),
282
- }, PetSettingsCard))
279
+ ctx.slots.inject('settings.plugin.item', () => {
280
+ const kind = typeof ctx.slots.spec === 'function'
281
+ ? ctx.slots.spec('settings.plugin.item')?.kind
282
+ : undefined
283
+ // 不同 DSH 客户端版本对 settings.plugin.item 的槽位类型不同:
284
+ // 旧版是 list(用 id 标识卡片),新版可能是 keyed(用 key 标识)。
285
+ // 这里同时带上 id 和 key,两种声明都能兼容。
286
+ const options = {
287
+ name: 'settings.plugin.item',
288
+ id: 'better-dsh-pet',
289
+ key: 'better-dsh-pet',
290
+ order: 30,
291
+ inject: () => ({}),
292
+ }
293
+ // 若运行时的槽位规格明确是 keyed,则只保留 key(避免多余字段带来歧义);
294
+ // 其余情况(list / 未知)保留 id,保证旧版 DSH 也能正常加载。
295
+ if (kind === 'keyed') delete options.id
296
+ return ctx.slots.register(options, PetSettingsCard)
297
+ })
283
298
  }
284
299
 
285
300
  exports.name = 'better-dsh-pet-client'
package/lib/index.js CHANGED
@@ -30,6 +30,7 @@ export const name = 'better-dsh-pet'
30
30
  export const inject = ['sessions']
31
31
  export const CONFIG_ENDPOINT = '/plugins/better-dsh-pet/config'
32
32
  export const STATUS_ENDPOINT = '/plugins/better-dsh-pet/status'
33
+ export const CLOSE_ENDPOINT = '/plugins/better-dsh-pet/close'
33
34
  export const ROUTE_PREFIX = '/pet'
34
35
 
35
36
  export const Config = Schema.object({
@@ -582,6 +583,19 @@ function mount(ctx, config = {}, eventCtx = ctx) {
582
583
  }),
583
584
  'better-dsh-pet: local refresh-balance endpoint',
584
585
  )
586
+ httpCtx.effect(
587
+ () => httpCtx.webServer.register({
588
+ kind: 'exact',
589
+ path: CLOSE_ENDPOINT,
590
+ handler: async (_req, res) => {
591
+ // 用户从右键菜单选择“本次关闭”时,先通知宿主停止守护,
592
+ // 避免 Helper 进程退出后被 HelperProcess 自动拉起。
593
+ stopRuntime('user-close')
594
+ jsonResponse(res, 200, { ok: true })
595
+ },
596
+ }),
597
+ 'better-dsh-pet: local close endpoint',
598
+ )
585
599
  httpCtx.effect(
586
600
  () => httpCtx.webServer.register({ kind: 'prefix', path: ROUTE_PREFIX, handler: createAssetHandler(config) }),
587
601
  'better-dsh-pet: /pet asset route',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-dsh-pet",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
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",
@@ -69,8 +69,7 @@
69
69
  },
70
70
  "client": {
71
71
  "inject": [
72
- "@deepseek-ai/dsh-client-runtime",
73
- "@deepseek-ai/dsh-client-ui-settings-plugins"
72
+ "@deepseek-ai/dsh-client-runtime"
74
73
  ],
75
74
  "platform": "web"
76
75
  }
@@ -113,6 +113,17 @@ function createWindow() {
113
113
  })
114
114
  }
115
115
 
116
+ async function notifyHostClosed() {
117
+ const statusUrl = process.env.DSH_PET_STATUS_URL
118
+ if (!statusUrl) return
119
+ try {
120
+ const closeUrl = statusUrl.replace(/\/plugins\/better-dsh-pet\/status$/, '/plugins/better-dsh-pet/close')
121
+ await fetch(closeUrl, { method: 'POST', cache: 'no-store' })
122
+ } catch {
123
+ // 宿主不可达时无法通知,仍继续退出;宿主侧可能按崩溃重启处理。
124
+ }
125
+ }
126
+
116
127
  function startPolling() {
117
128
  const statusUrl = process.env.DSH_PET_STATUS_URL
118
129
  if (!statusUrl) {
@@ -140,7 +151,7 @@ function startPolling() {
140
151
  app.whenReady().then(() => {
141
152
  createWindow()
142
153
  ipcMain.on('pet:closed', (_event, reason) => {
143
- app.quit()
154
+ void notifyHostClosed().finally(() => app.quit())
144
155
  })
145
156
  ipcMain.on('pet:hide', () => {
146
157
  if (mainWindow) mainWindow.hide()