dsh-plugin-greeting-bubble 1.4.2 → 1.5.0-beta.1

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
@@ -28,17 +28,21 @@
28
28
 
29
29
  ## 效果
30
30
 
31
- - 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入气泡:👋 早上好/中午好/下午好/晚上好,腾盛 ×(按当前时间变化)
32
- - **第二行显示账号余额**:`余额 ¥12.34`,来自当前登录的 DeepSeek 账号;每 60 秒刷新一次。
33
- - **余额低于 3 元**时,这一行变橙并显示「余额不足」提醒。
34
- - **点余额这一行展开详情**:账户名/联系方式、**连接状态(断开时可一键重连)**、**今日消费金额估算**、充值余额、最近更新时间,以及「用量」「充值」快捷入口;再点一次收起。
31
+ - 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入**小机器人 + 气泡卡片**:`🤖 早上好,腾盛 · ¥12.34`(问候语按时间变化)。
32
+ - **折叠态**只显示机器人 + 「问候语 · 金额」胶囊;**点击机器人或胶囊**展开详情,再点一次收起。
33
+ - 机器人的状态会在视觉上体现:
34
+ - 正常:主题蓝,偶尔眨眼;
35
+ - 刷新中:天线闪烁;
36
+ - 余额 <¥3:变成橙色;
37
+ - 连接断开:变成灰色并“闭眼”。
38
+ - 展开后显示:账户名/联系方式、**连接状态(断开时可一键重连)**、**今日消费金额估算**、充值余额、最近更新时间,以及「用量」「充值」快捷入口。
35
39
  - 今日消费金额只显示金额(`≈ ¥x.xx`);口径是基准余额 − 当前余额,优先用**昨天最后一次读到的余额**(≈ 0 点余额),没有昨天数据则用**今天第一次读到的余额**;充值会使基准同步抬高,不计入消费。
36
40
  - **安装插件之前、或 DSH 未运行期间**的消费无法统计,所以这是“自基准时间起”的估算,不是平台账单。
37
41
  - 详情里可以**隐藏金额(隐私模式)**:金额变为 `••••` 并记住,适合截图/录屏。
38
- - 未登录、账号服务不可用或请求失败时显示 `余额 --`,不影响气泡的其他功能。
39
- - 点气泡右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
40
- - **按住气泡可以拖动**:光标变成抓手,拖到任意位置松手即可;位置会记在浏览器里,下次打开(包括刷新)仍在原处。
41
- - 默认位置刻意抬到输入框上方,不会盖住发送按钮;拖动后由你决定位置。气泡本体需要接收拖动事件,所以它所在的小块区域会接住点击,其余区域不受影响。
42
+ - 未登录、账号服务不可用或请求失败时显示 `--`,不影响其他功能。
43
+ - 展开后用右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
44
+ - **按住机器人或卡片可以拖动**:光标变成抓手,拖到任意位置松手即可;位置会记在浏览器里,下次打开(包括刷新)仍在原处。
45
+ - 默认位置刻意抬到输入框上方,不会盖住发送按钮;拖动后由你决定位置。控件需要接收拖动事件,所以它所在的小块区域会接住点击,其余区域不受影响。
42
46
  - 在「插件」「设置」等页面同样显示(浮层属于整个应用框架)。
43
47
  - 进入动画在系统开启“减少动态效果”时自动关闭;窄窗口下气泡最大宽度自动收缩,不会被拖出屏幕(拖动时自动限制在可视区内)。
44
48
 
@@ -92,16 +96,17 @@ git clone https://github.com/liwei169/dsh-plugin-greeting-bubble.git
92
96
 
93
97
  | 操作 | 结果 |
94
98
  | --- | --- |
95
- | 页面加载 | 气泡出现(每个页面视图一次),并读取一次余额 |
96
- | **按住气泡拖动** | 气泡跟着指针移动,松手后记住位置 |
97
- | **点余额那一行** | 展开/收起详情(账户、会话、连接、今日估算、钱包明细、更新时间、版本、快捷入口) |
99
+ | 页面加载 | 机器人 + 折叠胶囊出现(每个页面视图一次),并读取一次余额 |
100
+ | **按住机器人或卡片拖动** | 整体跟着指针移动,松手后记住位置 |
101
+ | **点机器人或胶囊** | 展开/收起详情卡 |
102
+ | 展开后的 × | 本次页面隐藏整个挂件 |
98
103
  | 详情里的「重连」 | 连接断开时出现,点击立即重连 Host |
99
104
  | 详情里的「刷新」 | 立即刷新余额(不用等 60 秒) |
100
105
  | 详情里的「隐藏金额 / 显示金额」 | 切换隐私模式并记住 |
101
- | 余额低于 ¥3 | 余额行变橙并显示「余额不足」 |
102
- | 点 ×(或聚焦后按 Enter / Space) | 本次页面隐藏气泡 |
103
- | 刷新页面 | 气泡再次出现,位置保持上次拖到的位置 |
104
- | 插件页关闭该包的开关 | 气泡立即消失(HMR 生效时无需刷新) |
106
+ | 余额低于 ¥3 | 机器人变橙,胶囊显示橙色圆点 |
107
+ | 连接断开 | 机器人变灰、闭眼 |
108
+ | 刷新页面 | 挂件再次出现,位置保持上次拖到的位置 |
109
+ | 插件页关闭该包的开关 | 挂件立即消失(HMR 生效时无需刷新) |
105
110
  | 插件页卸载该包 | 彻底移除,不再出现 |
106
111
 
107
112
  ## 自定义
package/client.js CHANGED
@@ -4,22 +4,19 @@
4
4
  * Loaded lazily by the DSH client module table: this file only registers a
5
5
  * factory. The factory returns a Cordis plugin whose `apply` owns every live
6
6
  * resource through `ctx.effect` / `ctx.slots.inject`, so disabling or removing
7
- * the bundle removes the bubble again without a reload.
7
+ * the bundle removes the widget again without a reload.
8
8
  *
9
9
  * Rendering surface: the `shell.overlay` list slot declared by
10
10
  * `@deepseek-ai/dsh-client-ui-layout`. It is a frame-wide layer above every
11
- * column, so the bubble floats over the whole app without moving any host
12
- * control. Registering a fresh `id` adds an entry beside the shipped ones
13
- * instead of replacing them.
11
+ * column, so the widget floats over the whole app without moving any host
12
+ * control.
14
13
  *
15
- * Features:
16
- * - draggable, viewport-clamped, position remembered in localStorage;
17
- * - account balance from the Host `account` Remote (never the token itself),
18
- * refreshed every 60s while visible, with backoff and a manual refresh;
19
- * - privacy mode hides amounts (remembered);
20
- * - a low-balance warning below 3 CNY;
21
- * - an expandable details panel with wallets, account, update time, version,
22
- * and links to the Platform usage/top-up pages.
14
+ * v1.5 visual language:
15
+ * - a small robot avatar beside one speech card, dragged as a single unit;
16
+ * - collapsed: robot + `greeting · amount` pill; expanded: greeting, details,
17
+ * and actions;
18
+ * - the robot reflects state: accent while connected, warning colour on a low
19
+ * balance, muted and "eyes closed" while disconnected, and a blinking idle.
23
20
  */
24
21
  window.__ModuleLoader__.load({
25
22
  id: 'dsh-plugin-greeting-bubble',
@@ -30,7 +27,7 @@ window.__ModuleLoader__.load({
30
27
  /** Locale namespace owned by this plugin (registered in `apply`). */
31
28
  const NS = 'greetingBubble';
32
29
 
33
- /** Where the reader last dropped the bubble, as viewport px. */
30
+ /** Where the reader last dropped the widget, as viewport px. */
34
31
  const POSITION_KEY = 'dsh-greeting-bubble:position:v1';
35
32
 
36
33
  /** Whether amounts are hidden. */
@@ -40,7 +37,7 @@ window.__ModuleLoader__.load({
40
37
  const BALANCE_REFRESH_MS = 60_000;
41
38
  const BALANCE_MAX_BACKOFF_MS = 300_000;
42
39
 
43
- /** Below this CNY amount the bubble warns. */
40
+ /** Below this CNY amount the widget warns. */
44
41
  const LOW_BALANCE_CNY = 3;
45
42
 
46
43
  /** Local-day consumption baseline; reset when the date changes. */
@@ -50,6 +47,9 @@ window.__ModuleLoader__.load({
50
47
  const USAGE_URL = 'https://platform.deepseek.com/usage';
51
48
  const TOP_UP_URL = 'https://platform.deepseek.com/top_up';
52
49
 
50
+ /** Movement in px beyond which a pointer gesture counts as a drag, not a click. */
51
+ const DRAG_THRESHOLD = 4;
52
+
53
53
  /** Read the remembered spot; a corrupt or absent value means "default". */
54
54
  function readPosition() {
55
55
  try {
@@ -65,7 +65,7 @@ window.__ModuleLoader__.load({
65
65
  return null;
66
66
  }
67
67
 
68
- /** Persist the dropped spot; failures must never break the bubble. */
68
+ /** Persist the dropped spot; failures must never break the widget. */
69
69
  function writePosition(position) {
70
70
  try {
71
71
  window.localStorage.setItem(POSITION_KEY, JSON.stringify(position));
@@ -159,8 +159,6 @@ window.__ModuleLoader__.load({
159
159
  * balance: yesterday's last reading across midnight when available,
160
160
  * otherwise today's first reading. A top-up raises the baseline so it does
161
161
  * not count as negative spending.
162
- * @param normal - current normal wallets.
163
- * @returns `{ spent, startAt }`, or null when no CNY wallet is present.
164
162
  */
165
163
  function trackConsumption(normal) {
166
164
  const cny = (normal ?? []).find((wallet) => wallet.currency === 'CNY' && typeof wallet.balance === 'string');
@@ -181,17 +179,13 @@ window.__ModuleLoader__.load({
181
179
  baseline = state.baseline;
182
180
  startAt = typeof state.startAt === 'number' ? state.startAt : now;
183
181
  if (typeof state.lastAmount === 'number' && amount > state.lastAmount) {
184
- // A top-up mid-day: keep the spend counter continuous.
185
182
  baseline += amount - state.lastAmount;
186
183
  }
187
184
  } else if (state && typeof state.lastAmount === 'number' && typeof state.lastAt === 'number'
188
185
  && localDateKey(new Date(state.lastAt)) !== today) {
189
- // The plugin was running before midnight: its last reading is the
190
- // closest available day-start balance.
191
186
  baseline = state.lastAmount;
192
187
  startAt = state.lastAt;
193
188
  } else {
194
- // No reading from before today: today's first reading is the baseline.
195
189
  baseline = amount;
196
190
  startAt = now;
197
191
  }
@@ -229,7 +223,8 @@ window.__ModuleLoader__.load({
229
223
 
230
224
  /**
231
225
  * Component-local stylesheet; unmounting the entry removes it with the
232
- * node.
226
+ * node. Every colour comes from a `--dsw-alias-*` token so themes keep
227
+ * working; the robot itself is a plain SVG drawn with `currentColor`.
233
228
  */
234
229
  const STYLES = `
235
230
  .dsh-greeting-layer {
@@ -237,18 +232,75 @@ window.__ModuleLoader__.load({
237
232
  inset: 0;
238
233
  pointer-events: none;
239
234
  }
240
- .dsh-greeting-bubble {
235
+ .dsh-greeting-widget {
241
236
  position: absolute;
242
237
  right: calc(20px + env(safe-area-inset-right, 0px));
243
238
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
244
239
  z-index: 1;
245
240
  display: flex;
241
+ align-items: flex-end;
242
+ gap: 6px;
243
+ max-width: calc(100vw - 40px);
244
+ cursor: grab;
245
+ touch-action: none;
246
+ user-select: none;
247
+ pointer-events: auto;
248
+ animation: dsh-greeting-in 320ms cubic-bezier(0.22, 0.8, 0.24, 1) 350ms both;
249
+ }
250
+ .dsh-greeting-widget[data-dragging] {
251
+ cursor: grabbing;
252
+ }
253
+ .dsh-greeting-avatar {
254
+ flex: none;
255
+ width: 34px;
256
+ height: 34px;
257
+ padding: 0;
258
+ border: 0;
259
+ border-radius: 50%;
260
+ background: transparent;
261
+ color: var(--dsw-alias-state-business-primary, #3b6fe0);
262
+ cursor: pointer;
263
+ pointer-events: auto;
264
+ transition: color 120ms ease;
265
+ }
266
+ .dsh-greeting-widget[data-low] .dsh-greeting-avatar {
267
+ color: var(--dsw-alias-state-warn-primary, #b26a00);
268
+ }
269
+ .dsh-greeting-widget[data-disconnected] .dsh-greeting-avatar {
270
+ color: var(--dsw-alias-label-tertiary);
271
+ }
272
+ .dsh-greeting-avatar svg {
273
+ display: block;
274
+ width: 100%;
275
+ height: 100%;
276
+ overflow: visible;
277
+ }
278
+ .dsh-greeting-eye {
279
+ transform-box: fill-box;
280
+ transform-origin: center;
281
+ }
282
+ .dsh-greeting-widget[data-disconnected] .dsh-greeting-eyes {
283
+ transform: scaleY(0.12);
284
+ transform-box: fill-box;
285
+ transform-origin: center;
286
+ }
287
+ .dsh-greeting-widget:not([data-disconnected]) .dsh-greeting-eyes {
288
+ animation: dsh-greeting-blink 7s ease-in-out infinite;
289
+ }
290
+ .dsh-greeting-antenna-dot {
291
+ transform-box: fill-box;
292
+ transform-origin: center;
293
+ }
294
+ .dsh-greeting-widget[data-refreshing] .dsh-greeting-antenna-dot {
295
+ animation: dsh-greeting-pulse 900ms ease-in-out infinite;
296
+ }
297
+ .dsh-greeting-card {
298
+ box-sizing: border-box;
299
+ display: flex;
246
300
  flex-direction: column;
247
- align-items: stretch;
248
301
  gap: 2px;
249
- box-sizing: border-box;
250
- max-width: min(380px, calc(100vw - 40px));
251
- padding: 8px 6px 8px 12px;
302
+ max-width: min(360px, calc(100vw - 70px));
303
+ padding: 8px 8px 8px 10px;
252
304
  border: 0;
253
305
  --dsw-elevation-stroke-color: var(--dsw-alias-border-l3);
254
306
  border-radius: var(--dsw-radius-lg, 16px);
@@ -257,37 +309,64 @@ window.__ModuleLoader__.load({
257
309
  box-shadow: var(--dsw-elevation-prominent, 0 4px 16px rgba(0, 0, 0, 0.12));
258
310
  font-size: 13px;
259
311
  line-height: 20px;
260
- cursor: grab;
261
- touch-action: none;
262
- user-select: none;
263
312
  pointer-events: auto;
264
- animation: dsh-greeting-in 320ms cubic-bezier(0.22, 0.8, 0.24, 1) 350ms both;
265
- }
266
- .dsh-greeting-bubble[data-dragging] {
267
- cursor: grabbing;
268
313
  }
269
- .dsh-greeting-main {
270
- display: flex;
314
+ .dsh-greeting-card-compact {
315
+ flex-direction: row;
271
316
  align-items: center;
272
317
  gap: 8px;
318
+ padding: 6px 10px;
319
+ cursor: pointer;
320
+ }
321
+ .dsh-greeting-card-compact:hover {
322
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-3) 92%, var(--dsw-alias-label-primary));
323
+ }
324
+ .dsh-greeting-greeting {
273
325
  min-width: 0;
326
+ overflow: hidden;
327
+ text-overflow: ellipsis;
328
+ white-space: nowrap;
329
+ color: var(--dsw-alias-label-secondary);
330
+ font-size: 12px;
331
+ }
332
+ .dsh-greeting-amount {
333
+ flex: none;
334
+ font-size: 13px;
335
+ font-weight: 600;
336
+ color: var(--dsw-alias-label-primary);
337
+ white-space: nowrap;
274
338
  }
275
- .dsh-greeting-wave {
339
+ .dsh-greeting-widget[data-low] .dsh-greeting-amount {
340
+ color: var(--dsw-alias-state-warn-primary, #b26a00);
341
+ }
342
+ .dsh-greeting-dot {
276
343
  flex: none;
277
- font-size: 16px;
278
- line-height: 1;
344
+ width: 6px;
345
+ height: 6px;
346
+ border-radius: 50%;
347
+ background: var(--dsw-alias-state-warn-primary, #b26a00);
279
348
  }
280
- .dsh-greeting-text {
349
+ .dsh-greeting-head {
350
+ display: flex;
351
+ align-items: center;
352
+ gap: 8px;
281
353
  min-width: 0;
282
- overflow-wrap: anywhere;
354
+ padding-left: 2px;
355
+ }
356
+ .dsh-greeting-head-text {
357
+ min-width: 0;
358
+ overflow: hidden;
359
+ text-overflow: ellipsis;
360
+ white-space: nowrap;
361
+ font-size: 13px;
283
362
  }
284
363
  .dsh-greeting-close {
285
364
  flex: none;
286
365
  display: inline-flex;
287
366
  align-items: center;
288
367
  justify-content: center;
289
- width: 26px;
290
- height: 26px;
368
+ width: 24px;
369
+ height: 24px;
291
370
  margin-left: auto;
292
371
  padding: 0;
293
372
  border: 0;
@@ -301,57 +380,16 @@ window.__ModuleLoader__.load({
301
380
  background: var(--dsw-alias-interactive-bg-hover);
302
381
  color: var(--dsw-alias-label-secondary);
303
382
  }
304
- .dsh-greeting-toggle {
305
- display: flex;
306
- align-items: center;
307
- gap: 6px;
308
- margin: 0;
309
- padding: 0 0 0 24px;
310
- border: 0;
311
- border-radius: var(--dsw-radius-xs, 4px);
312
- background: transparent;
313
- color: var(--dsw-alias-label-tertiary);
314
- font: inherit;
315
- font-size: 12px;
316
- line-height: 16px;
317
- text-align: left;
318
- width: fit-content;
319
- max-width: 100%;
320
- cursor: pointer;
321
- pointer-events: auto;
322
- }
323
- .dsh-greeting-toggle:hover {
324
- color: var(--dsw-alias-label-secondary);
325
- }
326
- .dsh-greeting-toggle[data-low] {
327
- color: var(--dsw-alias-state-warn-primary, #b26a00);
328
- }
329
- .dsh-greeting-chevron {
330
- display: inline-block;
331
- transition: transform 120ms ease;
332
- }
333
- .dsh-greeting-toggle[aria-expanded='true'] .dsh-greeting-chevron {
334
- transform: rotate(90deg);
335
- }
336
- .dsh-greeting-warn {
337
- flex: none;
338
- padding: 0 5px;
339
- border-radius: 999px;
340
- background: color-mix(in srgb, var(--dsw-alias-state-warn-primary, #b26a00) 14%, transparent);
341
- font-size: 11px;
342
- line-height: 16px;
343
- }
344
383
  .dsh-greeting-details {
345
384
  display: flex;
346
385
  flex-direction: column;
347
386
  gap: 3px;
348
387
  margin-top: 4px;
349
- padding: 6px 6px 2px 24px;
388
+ padding: 6px 6px 0 2px;
350
389
  border-top: 0.5px solid var(--dsw-alias-border-l3);
351
390
  color: var(--dsw-alias-label-secondary);
352
391
  font-size: 12px;
353
392
  line-height: 17px;
354
- cursor: default;
355
393
  }
356
394
  .dsh-greeting-row {
357
395
  display: flex;
@@ -393,7 +431,8 @@ window.__ModuleLoader__.load({
393
431
  text-decoration: underline;
394
432
  }
395
433
  .dsh-greeting-action:focus-visible,
396
- .dsh-greeting-toggle:focus-visible,
434
+ .dsh-greeting-card-compact:focus-visible,
435
+ .dsh-greeting-avatar:focus-visible,
397
436
  .dsh-greeting-close:focus-visible {
398
437
  outline: var(--dsw-focus-ring-width, 2px) solid
399
438
  var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
@@ -409,31 +448,69 @@ window.__ModuleLoader__.load({
409
448
  transform: translateY(0) scale(1);
410
449
  }
411
450
  }
451
+ @keyframes dsh-greeting-blink {
452
+ 0%, 92%, 100% { transform: scaleY(1); }
453
+ 95% { transform: scaleY(0.1); }
454
+ }
455
+ @keyframes dsh-greeting-pulse {
456
+ 0%, 100% { opacity: 0.35; transform: scale(0.8); }
457
+ 50% { opacity: 1; transform: scale(1.15); }
458
+ }
412
459
  @media (prefers-reduced-motion: reduce) {
413
- .dsh-greeting-bubble {
460
+ .dsh-greeting-widget,
461
+ .dsh-greeting-widget:not([data-disconnected]) .dsh-greeting-eyes,
462
+ .dsh-greeting-widget[data-refreshing] .dsh-greeting-antenna-dot {
414
463
  animation: none;
415
464
  }
416
465
  }
417
466
  `;
418
467
 
468
+ /** The little robot beside the card. */
469
+ function RobotAvatar() {
470
+ return h(
471
+ 'svg',
472
+ { viewBox: '0 0 32 32', 'aria-hidden': 'true', focusable: 'false' },
473
+ h('g', { className: 'dsh-greeting-antenna' },
474
+ h('path', { d: 'M16 7V4', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' }),
475
+ h('circle', { className: 'dsh-greeting-antenna-dot', cx: 16, cy: 2.6, r: 2, fill: 'currentColor' }),
476
+ ),
477
+ h('rect', { x: 3, y: 12, width: 2.6, height: 7, rx: 1.3, fill: 'currentColor' }),
478
+ h('rect', { x: 26.4, y: 12, width: 2.6, height: 7, rx: 1.3, fill: 'currentColor' }),
479
+ h('rect', { x: 5.5, y: 7.5, width: 21, height: 17, rx: 6.5, fill: 'currentColor' }),
480
+ h('g', { className: 'dsh-greeting-eyes', fill: 'var(--dsw-alias-label-on-color, #ffffff)' },
481
+ h('circle', { className: 'dsh-greeting-eye', cx: 12, cy: 15, r: 2.1 }),
482
+ h('circle', { className: 'dsh-greeting-eye', cx: 20, cy: 15, r: 2.1 }),
483
+ ),
484
+ h('path', {
485
+ d: 'M12 20c1.6 2.2 6.4 2.2 8 0',
486
+ fill: 'none',
487
+ stroke: 'var(--dsw-alias-label-on-color, #ffffff)',
488
+ strokeWidth: 1.6,
489
+ strokeLinecap: 'round',
490
+ }),
491
+ );
492
+ }
493
+
419
494
  /**
420
- * The greeting bubble itself.
495
+ * The greeting widget: robot + speech card, draggable as one unit.
421
496
  *
422
497
  * @param props - the framework `t` seat plus injected balance/profile loaders.
423
- * @returns the bubble, or null once the reader dismissed it.
498
+ * @returns the widget, or null once the reader dismissed it.
424
499
  */
425
500
  function GreetingBubble({ t, loadBalance, loadProfile, connection }) {
426
501
  const [dismissed, setDismissed] = React.useState(false);
427
502
  const [position, setPosition] = React.useState(readPosition);
428
503
  const [dragging, setDragging] = React.useState(false);
504
+ const [expanded, setExpanded] = React.useState(false);
429
505
  const [balance, setBalance] = React.useState(null);
430
506
  const [profile, setProfile] = React.useState(null);
431
507
  const [updatedAt, setUpdatedAt] = React.useState(null);
432
508
  const [spent, setSpent] = React.useState(null);
433
- const [expanded, setExpanded] = React.useState(false);
434
509
  const [privacy, setPrivacy] = React.useState(readPrivacy);
435
- const bubbleRef = React.useRef(null);
510
+ const [refreshing, setRefreshing] = React.useState(false);
511
+ const widgetRef = React.useRef(null);
436
512
  const dragRef = React.useRef(null);
513
+ const suppressClickRef = React.useRef(false);
437
514
  const inFlightRef = React.useRef(null);
438
515
  const profileRef = React.useRef(null);
439
516
  const timerRef = React.useRef(null);
@@ -448,6 +525,7 @@ window.__ModuleLoader__.load({
448
525
  function readBalance() {
449
526
  if (typeof loadBalance !== 'function') return Promise.resolve(null);
450
527
  if (inFlightRef.current !== null) return inFlightRef.current;
528
+ setRefreshing(true);
451
529
  const run = Promise.resolve()
452
530
  .then(() => loadBalance())
453
531
  .then((result) => {
@@ -456,7 +534,10 @@ window.__ModuleLoader__.load({
456
534
  return wallets === null ? null : { wallets, at: Date.now(), spent: trackConsumption(wallets.normal) };
457
535
  })
458
536
  .catch(() => null)
459
- .finally(() => { inFlightRef.current = null; });
537
+ .finally(() => {
538
+ inFlightRef.current = null;
539
+ if (!cancelledRef.current) setRefreshing(false);
540
+ });
460
541
  inFlightRef.current = run;
461
542
  return run;
462
543
  }
@@ -526,7 +607,7 @@ window.__ModuleLoader__.load({
526
607
  React.useEffect(() => {
527
608
  function handleResize() {
528
609
  setPosition((current) => {
529
- const element = bubbleRef.current;
610
+ const element = widgetRef.current;
530
611
  if (current === null || element === null) return current;
531
612
  const x = clamp(current.x, 0, window.innerWidth - element.offsetWidth);
532
613
  const y = clamp(current.y, 0, window.innerHeight - element.offsetHeight);
@@ -555,9 +636,8 @@ window.__ModuleLoader__.load({
555
636
  : connectionState === 'disconnected'
556
637
  ? label('disconnected', '已断开')
557
638
  : label('unavailable', '--');
558
- const spentText = spent === null
559
- ? label('unavailable', '--')
560
- : '≈ ' + currencySymbol('CNY') + formatAmount(spent.spent);
639
+ const spentText = spent === null ? label('unavailable', '--') : '≈ ' + currencySymbol('CNY') + formatAmount(spent.spent);
640
+ const collapsedLabel = greeting + ' · ' + amountText;
561
641
 
562
642
  /** Refresh now and reset the backoff. */
563
643
  function handleRefresh() {
@@ -571,7 +651,7 @@ window.__ModuleLoader__.load({
571
651
  }
572
652
 
573
653
  /** Expand/collapse; the first expansion loads the account profile. */
574
- function handleToggle() {
654
+ function toggleExpanded() {
575
655
  setExpanded((current) => {
576
656
  const next = !current;
577
657
  if (next && profile === null) {
@@ -592,11 +672,11 @@ window.__ModuleLoader__.load({
592
672
  });
593
673
  }
594
674
 
595
- /** Start a drag: switch to absolute coordinates and capture the pointer. */
596
- function handlePointerDown(event) {
675
+ /** Suppress the click that follows a drag gesture. */
676
+ function beginDrag(event) {
597
677
  if (event.button !== undefined && event.button !== 0) return;
598
678
  if (event.target && event.target.closest && event.target.closest('button, a')) return;
599
- const element = bubbleRef.current;
679
+ const element = widgetRef.current;
600
680
  if (!element) return;
601
681
  const rect = element.getBoundingClientRect();
602
682
  dragRef.current = {
@@ -607,6 +687,7 @@ window.__ModuleLoader__.load({
607
687
  top: rect.top,
608
688
  width: rect.width,
609
689
  height: rect.height,
690
+ moved: false,
610
691
  };
611
692
  setPosition({ x: rect.left, y: rect.top });
612
693
  setDragging(true);
@@ -617,24 +698,25 @@ window.__ModuleLoader__.load({
617
698
  }
618
699
 
619
700
  /** Move within the viewport while the pointer is captured. */
620
- function handlePointerMove(event) {
701
+ function moveDrag(event) {
621
702
  const drag = dragRef.current;
622
703
  if (drag === null || event.pointerId !== drag.pointerId) return;
623
- const x = drag.left + event.clientX - drag.startX;
624
- const y = drag.top + event.clientY - drag.startY;
704
+ const dx = event.clientX - drag.startX;
705
+ const dy = event.clientY - drag.startY;
706
+ if (!drag.moved && Math.abs(dx) + Math.abs(dy) > DRAG_THRESHOLD) drag.moved = true;
625
707
  setPosition({
626
- x: clamp(x, 0, window.innerWidth - drag.width),
627
- y: clamp(y, 0, window.innerHeight - drag.height),
708
+ x: clamp(drag.left + dx, 0, window.innerWidth - drag.width),
709
+ y: clamp(drag.top + dy, 0, window.innerHeight - drag.height),
628
710
  });
629
711
  }
630
712
 
631
713
  /** Finish a drag, clamp once more, and persist the dropped spot. */
632
- function handlePointerUp(event) {
714
+ function endDrag(event) {
633
715
  const drag = dragRef.current;
634
716
  if (drag === null || event.pointerId !== drag.pointerId) return;
635
717
  dragRef.current = null;
636
718
  setDragging(false);
637
- const element = bubbleRef.current;
719
+ const element = widgetRef.current;
638
720
  if (!element) return;
639
721
  const rect = element.getBoundingClientRect();
640
722
  const dropped = {
@@ -643,75 +725,90 @@ window.__ModuleLoader__.load({
643
725
  };
644
726
  setPosition(dropped);
645
727
  writePosition(dropped);
728
+ if (drag.moved) {
729
+ suppressClickRef.current = true;
730
+ window.setTimeout(() => { suppressClickRef.current = false; }, 0);
731
+ }
732
+ }
733
+
734
+ /** Toggle the card, ignoring the click that ends a drag and inner controls. */
735
+ function handleCardClick(event) {
736
+ if (suppressClickRef.current) return;
737
+ if (event.target && event.target.closest && event.target.closest('button, a')) return;
738
+ toggleExpanded();
739
+ }
740
+
741
+ /** Keyboard activation for the compact card. */
742
+ function handleCardKeyDown(event) {
743
+ if (event.key !== 'Enter' && event.key !== ' ') return;
744
+ event.preventDefault();
745
+ toggleExpanded();
646
746
  }
647
747
 
648
748
  return h(
649
749
  'div',
650
- { className: 'dsh-greeting-layer', style: { position: 'absolute', inset: 0, pointerEvents: 'none' } },
750
+ {
751
+ className: 'dsh-greeting-widget',
752
+ ref: widgetRef,
753
+ 'data-dragging': dragging ? '' : undefined,
754
+ 'data-expanded': expanded ? '' : undefined,
755
+ 'data-low': low ? '' : undefined,
756
+ 'data-refreshing': refreshing ? '' : undefined,
757
+ 'data-disconnected': connectionState === 'disconnected' ? '' : undefined,
758
+ style: position === null
759
+ ? undefined
760
+ : { left: position.x, top: position.y, right: 'auto', bottom: 'auto' },
761
+ onPointerDown: beginDrag,
762
+ onPointerMove: moveDrag,
763
+ onPointerUp: endDrag,
764
+ onPointerCancel: endDrag,
765
+ },
651
766
  h('style', { key: 'styles' }, STYLES),
652
767
  h(
653
- 'div',
768
+ 'button',
654
769
  {
655
- key: 'bubble',
656
- ref: bubbleRef,
657
- className: 'dsh-greeting-bubble',
658
- 'data-dragging': dragging ? '' : undefined,
659
- style: position === null
660
- ? undefined
661
- : { left: position.x, top: position.y, right: 'auto', bottom: 'auto' },
662
- onPointerDown: handlePointerDown,
663
- onPointerMove: handlePointerMove,
664
- onPointerUp: handlePointerUp,
665
- onPointerCancel: handlePointerUp,
770
+ className: 'dsh-greeting-avatar',
771
+ type: 'button',
772
+ title: greeting,
773
+ 'aria-label': greeting,
774
+ 'aria-expanded': expanded ? 'true' : 'false',
775
+ onClick: toggleExpanded,
666
776
  },
667
- h(
777
+ h(RobotAvatar),
778
+ ),
779
+ expanded
780
+ ? h(
668
781
  'div',
669
- { className: 'dsh-greeting-main', key: 'main' },
670
- h('span', { className: 'dsh-greeting-wave', 'aria-hidden': 'true' }, '👋'),
671
- h('span', { className: 'dsh-greeting-text', role: 'status', lang: 'zh-CN' }, greeting),
782
+ { className: 'dsh-greeting-card', key: 'card' },
672
783
  h(
673
- 'button',
674
- {
675
- className: 'dsh-greeting-close',
676
- type: 'button',
677
- title: dismissLabel,
678
- 'aria-label': dismissLabel,
679
- onClick: () => { setDismissed(true); },
680
- },
784
+ 'div',
785
+ { className: 'dsh-greeting-head' },
786
+ h('span', { className: 'dsh-greeting-head-text', role: 'status', lang: 'zh-CN' }, greeting),
681
787
  h(
682
- 'svg',
683
- { width: 13, height: 13, viewBox: '0 0 12 12', 'aria-hidden': 'true' },
684
- h('path', {
685
- d: 'M2.5 2.5l7 7M9.5 2.5l-7 7',
686
- fill: 'none',
687
- stroke: 'currentColor',
688
- strokeWidth: 1.4,
689
- strokeLinecap: 'round',
690
- }),
788
+ 'button',
789
+ {
790
+ className: 'dsh-greeting-close',
791
+ type: 'button',
792
+ title: dismissLabel,
793
+ 'aria-label': dismissLabel,
794
+ onClick: () => { setDismissed(true); },
795
+ },
796
+ h(
797
+ 'svg',
798
+ { width: 12, height: 12, viewBox: '0 0 12 12', 'aria-hidden': 'true' },
799
+ h('path', {
800
+ d: 'M2.5 2.5l7 7M9.5 2.5l-7 7',
801
+ fill: 'none',
802
+ stroke: 'currentColor',
803
+ strokeWidth: 1.4,
804
+ strokeLinecap: 'round',
805
+ }),
806
+ ),
691
807
  ),
692
808
  ),
693
- ),
694
- h(
695
- 'button',
696
- {
697
- key: 'toggle',
698
- className: 'dsh-greeting-toggle',
699
- type: 'button',
700
- 'data-low': low ? '' : undefined,
701
- 'aria-expanded': expanded ? 'true' : 'false',
702
- title: label('details', '展开详情'),
703
- onClick: handleToggle,
704
- },
705
- h('span', { className: 'dsh-greeting-chevron', 'aria-hidden': 'true' }, '▸'),
706
- h('span', null, label('balance', '余额') + ' ' + amountText),
707
- low
708
- ? h('span', { className: 'dsh-greeting-warn' }, label('lowBalance', '余额不足'))
709
- : null,
710
- ),
711
- expanded
712
- ? h(
809
+ h(
713
810
  'div',
714
- { className: 'dsh-greeting-details', key: 'details' },
811
+ { className: 'dsh-greeting-details' },
715
812
  h(
716
813
  'div',
717
814
  { className: 'dsh-greeting-row' },
@@ -721,7 +818,7 @@ window.__ModuleLoader__.load({
721
818
  h(
722
819
  'div',
723
820
  { className: 'dsh-greeting-row' },
724
- h('span', { className: 'dsh-greeting-row-label' }, label('topUpBalance', '充值')),
821
+ h('span', { className: 'dsh-greeting-row-label' }, label('topUpBalance', '充值余额')),
725
822
  h('span', { className: 'dsh-greeting-row-value' }, privacy ? label('hidden', '••••') : (normalText ?? label('unavailable', '--'))),
726
823
  ),
727
824
  h(
@@ -765,9 +862,24 @@ window.__ModuleLoader__.load({
765
862
  h('a', { className: 'dsh-greeting-action', href: USAGE_URL, target: '_blank', rel: 'noreferrer' }, label('usage', '用量')),
766
863
  h('a', { className: 'dsh-greeting-action', href: TOP_UP_URL, target: '_blank', rel: 'noreferrer' }, label('topUp', '充值')),
767
864
  ),
768
- )
769
- : null,
770
- ),
865
+ ),
866
+ )
867
+ : h(
868
+ 'div',
869
+ {
870
+ className: 'dsh-greeting-card dsh-greeting-card-compact',
871
+ key: 'compact',
872
+ role: 'button',
873
+ tabIndex: 0,
874
+ 'aria-label': collapsedLabel,
875
+ 'aria-expanded': 'false',
876
+ onClick: handleCardClick,
877
+ onKeyDown: handleCardKeyDown,
878
+ },
879
+ h('span', { className: 'dsh-greeting-greeting', role: 'status', lang: 'zh-CN' }, greeting),
880
+ h('span', { className: 'dsh-greeting-amount' }, amountText),
881
+ low ? h('span', { className: 'dsh-greeting-dot', 'aria-hidden': 'true' }) : null,
882
+ ),
771
883
  );
772
884
  }
773
885
 
@@ -790,7 +902,6 @@ window.__ModuleLoader__.load({
790
902
  greetingEvening: '晚上好,腾盛',
791
903
  dismiss: '关闭问候气泡',
792
904
  balance: '余额',
793
- bonus: '赠送',
794
905
  topUpBalance: '充值余额',
795
906
  account: '账户',
796
907
  connection: '连接',
@@ -803,7 +914,6 @@ window.__ModuleLoader__.load({
803
914
  hidden: '••••',
804
915
  unavailable: '--',
805
916
  lowBalance: '余额不足',
806
- details: '展开详情',
807
917
  refresh: '刷新',
808
918
  hideAmount: '隐藏金额',
809
919
  showAmount: '显示金额',
@@ -818,7 +928,6 @@ window.__ModuleLoader__.load({
818
928
  greetingEvening: '你好,腾盛',
819
929
  dismiss: 'Dismiss greeting',
820
930
  balance: 'Balance',
821
- bonus: 'Bonus',
822
931
  topUpBalance: 'Top-up balance',
823
932
  account: 'Account',
824
933
  connection: 'Connection',
@@ -831,7 +940,6 @@ window.__ModuleLoader__.load({
831
940
  hidden: '••••',
832
941
  unavailable: '--',
833
942
  lowBalance: 'Low balance',
834
- details: 'Show details',
835
943
  refresh: 'Refresh',
836
944
  hideAmount: 'Hide amounts',
837
945
  showAmount: 'Show amounts',
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "description": "Shows a time-aware “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer (morning/noon/afternoon/evening variants), plus the signed-in DeepSeek account balance refreshed every 60 seconds. A balance below 3 CNY is flagged. Click the balance line to expand details: account, connection state with a one-click reconnect, today's spend estimate (balance delta, ignoring top-ups; spending before the plugin was installed cannot be counted), top-up balance, last update, and shortcuts to the Platform usage/top-up pages; a privacy toggle hides amounts, and drag remembers the bubble position. Click × to dismiss it; it appears again on the next page load. Control labels are localized; the greeting stays Chinese. Balance is read through the DSH account service, so the browser never sees the account token; a signed-out or failed read shows “--”. The plugin makes no network requests of its own and collects no data. Disable or remove the bundle under Plugins to remove it.",
3
+ "description": "A small robot with a collapsing pill (greeting · balance) appears near the bottom-right corner of the window, just above the message composer; click the robot or pill to expand details: account, connection state with a one-click reconnect, today's spend estimate (balance delta, ignoring top-ups; spending before the plugin was installed cannot be counted), top-up balance, last update, and shortcuts to the Platform usage/top-up pages; a privacy toggle hides amounts, and drag remembers the bubble position. Click × to dismiss it; it appears again on the next page load. Control labels are localized; the greeting stays Chinese. Balance is read through the DSH account service, so the browser never sees the account token; a signed-out or failed read shows “--”. The plugin makes no network requests of its own and collects no data. Disable or remove the bundle under Plugins to remove it.",
4
4
  "detail": "docs/DETAIL.md"
5
5
  }
6
6
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "description": "页面加载后,在窗口右下角、输入框上方弹出按时间变化的问候气泡(早上好/中午好/下午好/晚上好,腾盛),并显示当前 DeepSeek 账号余额(充值 + 赠送),每 60 秒刷新一次。余额低于 3 元会显示提醒;点击余额行展开详情:账户信息、连接状态(断开时可一键重连)、今日消费金额估算(基于余额差,忽略充值;安装插件之前的消费无法统计)、充值余额、更新时间,以及「用量」「充值」快捷入口。支持隐藏金额(隐私模式),按住气泡可拖动并记住位置。点 × 关闭,下次页面加载会再次出现。界面文案跟随语言,问候语保持中文。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「--」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
3
+ "description": "页面加载后,在窗口右下角、输入框上方出现小机器人 + 折叠胶囊(问候语 · 余额),点击机器人或胶囊展开详情:账户信息、连接状态(断开时可一键重连)、今日消费金额估算(基于余额差,忽略充值;安装插件之前的消费无法统计)、充值余额、更新时间,以及「用量」「充值」快捷入口。支持隐藏金额(隐私模式),按住气泡可拖动并记住位置。点 × 关闭,下次页面加载会再次出现。界面文案跟随语言,问候语保持中文。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「--」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
4
4
  "detail": "docs/DETAIL.zh.md"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-greeting-bubble",
3
- "version": "1.4.2",
3
+ "version": "1.5.0-beta.1",
4
4
  "description": "Shows a “你好,腾盛” speech bubble in the bottom-right corner of the DeepSeek Harness Web GUI.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {