dsh-plugin-greeting-bubble 1.0.0 → 1.2.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.
- package/README.md +56 -23
- package/client.js +368 -46
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,10 +29,13 @@
|
|
|
29
29
|
## 效果
|
|
30
30
|
|
|
31
31
|
- 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入气泡:👋 你好,腾盛 ×
|
|
32
|
+
- **第二行显示账号余额**:`余额 ¥12.34(赠送 ¥3.00)`,来自当前登录的 DeepSeek 账号(充值 + 赠送钱包);每 60 秒刷新一次,**点余额这一行可立即刷新**。
|
|
33
|
+
- 未登录、账号服务不可用或请求失败时显示 `余额 --`,不影响气泡的其他功能。
|
|
32
34
|
- 点气泡右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
35
|
+
- **按住气泡可以拖动**:光标变成抓手,拖到任意位置松手即可;位置会记在浏览器里,下次打开(包括刷新)仍在原处。
|
|
36
|
+
- 默认位置刻意抬到输入框上方,不会盖住发送按钮;拖动后由你决定位置。气泡本体需要接收拖动事件,所以它所在的小块区域会接住点击,其余区域不受影响。
|
|
37
|
+
- 在「插件」「设置」等页面同样显示(浮层属于整个应用框架)。
|
|
38
|
+
- 进入动画在系统开启“减少动态效果”时自动关闭;窄窗口下气泡最大宽度自动收缩,不会被拖出屏幕(拖动时自动限制在可视区内)。
|
|
36
39
|
|
|
37
40
|
## 安装
|
|
38
41
|
|
|
@@ -84,9 +87,11 @@ git clone https://github.com/liwei169/dsh-plugin-greeting-bubble.git
|
|
|
84
87
|
|
|
85
88
|
| 操作 | 结果 |
|
|
86
89
|
| --- | --- |
|
|
87
|
-
| 页面加载 |
|
|
90
|
+
| 页面加载 | 气泡出现(每个页面视图一次),并读取一次余额 |
|
|
91
|
+
| **按住气泡拖动** | 气泡跟着指针移动,松手后记住位置 |
|
|
92
|
+
| **点余额那一行** | 立即刷新余额(不用等 60 秒) |
|
|
88
93
|
| 点 ×(或聚焦后按 Enter / Space) | 本次页面隐藏气泡 |
|
|
89
|
-
| 刷新页面 |
|
|
94
|
+
| 刷新页面 | 气泡再次出现,位置保持上次拖到的位置 |
|
|
90
95
|
| 插件页关闭该包的开关 | 气泡立即消失(HMR 生效时无需刷新) |
|
|
91
96
|
| 插件页卸载该包 | 彻底移除,不再出现 |
|
|
92
97
|
|
|
@@ -105,9 +110,9 @@ en: { greeting: '你好,腾盛', dismiss: 'Dismiss greeting' },
|
|
|
105
110
|
|
|
106
111
|
问候语刻意在两种语言下保持一致(它是这个插件固定的“签名语”),只有关闭按钮的提示文字跟随界面语言。想让英文界面显示英文问候,把 `en.greeting` 改成 `Hello, Tengsheng` 即可。
|
|
107
112
|
|
|
108
|
-
### 2.
|
|
113
|
+
### 2. 改默认位置 / 拖动记忆
|
|
109
114
|
|
|
110
|
-
`client.js`
|
|
115
|
+
默认位置在 `client.js` 的 `.dsh-greeting-bubble` 里:
|
|
111
116
|
|
|
112
117
|
```css
|
|
113
118
|
right: calc(20px + env(safe-area-inset-right, 0px));
|
|
@@ -116,13 +121,35 @@ bottom: calc(84px + env(safe-area-inset-bottom, 0px)); /* 输入框发送按钮
|
|
|
116
121
|
|
|
117
122
|
改成 `left` / `top` 就能换角;把 `20px` 调大即离边更远。`bottom` 不要低于 `84px`:DSH 的发送按钮在输入卡右下角,贴近底边会在窄窗口下盖住它。
|
|
118
123
|
|
|
124
|
+
拖动后的位置保存在 localStorage 的 `dsh-greeting-bubble:position:v1` 键里。想恢复默认位置,在浏览器控制台执行:
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
localStorage.removeItem('dsh-greeting-bubble:position:v1')
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
然后刷新页面即可。
|
|
131
|
+
|
|
119
132
|
### 3. 改视觉
|
|
120
133
|
|
|
121
134
|
- 圆角、描边、阴影:`--dsw-radius-lg`、`--dsw-elevation-stroke-color`、`--dsw-elevation-prominent`,与 DSH 原生浮层一致;
|
|
122
135
|
- 底/字色:`--dsw-alias-bg-layer-3`、`--dsw-alias-label-primary`,自动跟随亮/暗主题;
|
|
123
136
|
- 尺寸与字号:`.dsh-greeting-bubble` 的 `font-size`、`gap`、`padding`。
|
|
124
137
|
|
|
125
|
-
### 4.
|
|
138
|
+
### 4. 改余额刷新频率
|
|
139
|
+
|
|
140
|
+
`client.js` 顶部:
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
const BALANCE_REFRESH_MS = 60_000; // 正常刷新间隔
|
|
144
|
+
const BALANCE_MAX_BACKOFF_MS = 300_000; // 连续失败后的最大退避
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
- 只在页面可见时刷新,切到后台暂停;
|
|
148
|
+
- 失败会退避(60s → 120s → 240s → 300s),成功后恢复 60s;
|
|
149
|
+
- 点击余额那一行会立即刷新并重置退避;
|
|
150
|
+
- 不建议改到 30 秒以下:余额接口是账号接口,不适合高频轮询。
|
|
151
|
+
|
|
152
|
+
### 5. 改成“只问候一次”(可选)
|
|
126
153
|
|
|
127
154
|
默认每次页面加载都会出现。如果希望用户关闭后永久不再出现,在组件里加一个 `localStorage` 开关,例如:
|
|
128
155
|
|
|
@@ -143,7 +170,7 @@ function GreetingBubble({ t }) {
|
|
|
143
170
|
|
|
144
171
|
清除 `localStorage` 里这个键即可让问候重新出现。
|
|
145
172
|
|
|
146
|
-
###
|
|
173
|
+
### 6. 改图标、名称、描述
|
|
147
174
|
|
|
148
175
|
- 图标:`icon.svg`(36×36,纯几何、无文字);
|
|
149
176
|
- 插件页显示的名称与说明:`locale/zh.json`、`locale/en.json` 的 `meta.title` / `meta.description`;
|
|
@@ -175,13 +202,15 @@ package.json
|
|
|
175
202
|
几个关键设计点:
|
|
176
203
|
|
|
177
204
|
1. **渲染位置选 `shell.overlay`**:这是 `@deepseek-ai/dsh-client-ui-layout` 声明的整帧浮层(`position: absolute; inset: 0; z-index: 20; pointer-events: none`),位于所有列之上、列滚动容器之外,适合徽标、Toast、状态胶囊这类覆盖层。注册时用一个新 `id`(`greeting-bubble`)就是**追加**一条,不会替换自带的条目。
|
|
178
|
-
2.
|
|
179
|
-
3.
|
|
180
|
-
4.
|
|
181
|
-
5.
|
|
182
|
-
6.
|
|
183
|
-
7.
|
|
184
|
-
8.
|
|
205
|
+
2. **浮层穿透、气泡可交互**:浮层本身 `pointer-events: none`,它的直接子元素默认 `auto`。插件根节点设为 `none`;气泡卡片设回 `auto`——它必须接收指针事件才能拖动。因此只有气泡这一块会接住点击,浮层的其余区域完全穿透。
|
|
206
|
+
3. **拖动实现**:`pointerdown` 时记录起始坐标与气泡矩形并 `setPointerCapture`,`pointermove` 按位移计算新坐标、限制在可视区内,`pointerup` 保存到 `localStorage` 并释放捕获;窗口缩放时也会把气泡夹回屏幕内(`ResizeObserver` 不需要,监听 `resize` 即可)。
|
|
207
|
+
4. **高度避让**:默认距底 `84px`,位于输入卡发送按钮(34px 圆钮)之上;发送按钮始终露出来,不被问候语遮挡。拖动后以用户选择为准。
|
|
208
|
+
5. **生命周期归 Cordis 管**:所有注册都放在 `ctx.effect` / `ctx.slots.inject` 里。`slots.inject` 会在槽声明存在时注册、声明消失时注销;插件停用或卸载时整个 fiber 被销毁,气泡和字典一起被清理,不需要手写 DOM 清理。
|
|
209
|
+
6. **工厂无副作用**:`client.js` 顶层只调用 `__ModuleLoader__.load`,真正的注册发生在 `apply()`;模块体不碰 DOM、不开定时器。
|
|
210
|
+
7. **样式走主题变量**:气泡用 `--dsw-alias-bg-layer-3`、`--dsw-alias-border-l3`、`--dsw-alias-label-primary`、`--dsw-alias-interactive-bg-hover` 等 token,亮/暗主题自动切换;组件内的 `<style>` 随组件卸载一起移除。
|
|
211
|
+
8. **文案走 locale**:`locale: NS` 让框架把 `t` 注入组件,切换界面语言时文案实时更新,无需重载。
|
|
212
|
+
9. **Host 端为空**:`index.js` 只导出 `export function apply() {}`。插件不注册工具、不发请求、不写会话日志,因此对模型和会话完全透明。
|
|
213
|
+
10. **余额走账号 Remote**:`ctx.remote.account.getBalance(...)` 由 Host 用本地登录凭据请求 Platform,浏览器只拿到脱敏后的钱包金额;账号令牌永远不进浏览器。未登录(返回 null)或请求失败时显示 `--`。
|
|
185
214
|
|
|
186
215
|
## 文件结构
|
|
187
216
|
|
|
@@ -237,17 +266,21 @@ node test/smoke.mjs
|
|
|
237
266
|
- 面向 **DSH Web 客户端**(`dsh.client.platform: web`):桌面版窗口和浏览器版都适用;CLI / headless 模式没有界面,插件不产生任何效果。
|
|
238
267
|
- 依赖 `shell.overlay` 槽;更老的 DSH 版本没有该槽时,插件会安静地不显示,不会报错。
|
|
239
268
|
- 每次页面加载都会出现一次,不记忆关闭状态(如需记忆见[自定义](#自定义))。
|
|
240
|
-
-
|
|
241
|
-
-
|
|
242
|
-
-
|
|
269
|
+
- 浮层位于整帧之上:气泡默认在右下角、输入框上方(距右 20px、距底 84px),可以拖到任意位置;拖动后位置记在 localStorage 里(`dsh-greeting-bubble:position:v1`)。气泡本体需要接收拖动事件,所以它所在的那一小块会接住点击,其余区域不受影响。
|
|
270
|
+
- 余额需要当前**已登录 DeepSeek 账号**;未登录、账号插件未启用或请求失败时显示 `余额 --`,不会报错。余额是 Platform 的实时钱包数据(充值 + 赠送),不是本地估算。
|
|
271
|
+
- 余额只显示在气泡里,不发送给任何第三方;但截图/录屏会带出金额,注意场合。
|
|
272
|
+
- 问候语固定为中文,在任何界面语言下都不翻译;只有按钮提示文字跟随语言。
|
|
273
|
+
- 插件自身不直接联网;余额读取经 Host 的账号服务完成。
|
|
243
274
|
|
|
244
275
|
## English
|
|
245
276
|
|
|
246
|
-
A tiny DeepSeek Harness Web UI plugin that shows a “你好,腾盛” speech bubble
|
|
277
|
+
A tiny DeepSeek Harness Web UI plugin that shows a “你好,腾盛” speech bubble near the bottom-right corner after the page loads, with the signed-in account balance on a second line. Click × to dismiss it; it returns on the next page load. The bubble can be dragged anywhere, and its position is remembered in localStorage.
|
|
247
278
|
|
|
248
|
-
- Install: **Plugins → Add plugin** → `
|
|
249
|
-
- It registers one entry into the frame-wide `shell.overlay` slot, uses `--dsw-alias-*` theme tokens, localizes its
|
|
250
|
-
-
|
|
279
|
+
- Install: **Plugins → Add plugin** → `dsh-plugin-greeting-bubble` (npm), or `https://github.com/liwei169/dsh-plugin-greeting-bubble` (GitHub).
|
|
280
|
+
- It registers one entry into the frame-wide `shell.overlay` slot, uses `--dsw-alias-*` theme tokens, localizes its labels, and keeps every registration inside `ctx.effect` / `ctx.slots.inject` so disabling the bundle removes the bubble again.
|
|
281
|
+
- Dragging uses pointer capture, clamps to the viewport, and saves the dropped position under `dsh-greeting-bubble:position:v1`.
|
|
282
|
+
- Balance comes from `ctx.remote.account.getBalance(...)` (Host-side Platform call with the stored credential; the browser never sees the account token), refreshed every 60 seconds while the page is visible and on click, with backoff on failure.
|
|
283
|
+
- No direct network access, no data collection, no model-facing behavior.
|
|
251
284
|
|
|
252
285
|
Tested with DeepSeek Harness 0.2.2-rc.5.
|
|
253
286
|
|
package/client.js
CHANGED
|
@@ -7,10 +7,15 @@
|
|
|
7
7
|
* the bundle removes the bubble again without a reload.
|
|
8
8
|
*
|
|
9
9
|
* Rendering surface: the `shell.overlay` list slot declared by
|
|
10
|
-
* `@deepseek-ai/dsh-client-ui-layout`. It is a frame-wide
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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.
|
|
14
|
+
*
|
|
15
|
+
* The bubble is draggable (pointer capture, viewport clamp, remembered in
|
|
16
|
+
* localStorage) and shows the signed-in account's wallet balance, which it
|
|
17
|
+
* reads through the Host's `account` Remote — the browser never sees the
|
|
18
|
+
* account token and never calls Platform directly.
|
|
14
19
|
*/
|
|
15
20
|
window.__ModuleLoader__.load({
|
|
16
21
|
id: 'dsh-plugin-greeting-bubble',
|
|
@@ -21,18 +26,87 @@ window.__ModuleLoader__.load({
|
|
|
21
26
|
/** Locale namespace owned by this plugin (registered in `apply`). */
|
|
22
27
|
const NS = 'greetingBubble';
|
|
23
28
|
|
|
29
|
+
/** Where the reader last dropped the bubble, as viewport px. */
|
|
30
|
+
const POSITION_KEY = 'dsh-greeting-bubble:position:v1';
|
|
31
|
+
|
|
32
|
+
/** Normal refresh cadence while the page is visible, and the failure cap. */
|
|
33
|
+
const BALANCE_REFRESH_MS = 60_000;
|
|
34
|
+
const BALANCE_MAX_BACKOFF_MS = 300_000;
|
|
35
|
+
|
|
36
|
+
/** Read the remembered spot; a corrupt or absent value means "default". */
|
|
37
|
+
function readPosition() {
|
|
38
|
+
try {
|
|
39
|
+
const raw = window.localStorage.getItem(POSITION_KEY);
|
|
40
|
+
if (!raw) return null;
|
|
41
|
+
const value = JSON.parse(raw);
|
|
42
|
+
if (typeof value?.x === 'number' && typeof value?.y === 'number') {
|
|
43
|
+
return { x: value.x, y: value.y };
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
// Private mode, blocked storage, or malformed JSON: fall through.
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Persist the dropped spot; failures must never break the bubble. */
|
|
52
|
+
function writePosition(position) {
|
|
53
|
+
try {
|
|
54
|
+
window.localStorage.setItem(POSITION_KEY, JSON.stringify(position));
|
|
55
|
+
} catch {
|
|
56
|
+
// Storage unavailable: position simply does not survive the reload.
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Keep a value inside [min, max], tolerating a viewport smaller than the card. */
|
|
61
|
+
function clamp(value, min, max) {
|
|
62
|
+
return Math.max(min, Math.min(value, Math.max(min, max)));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Platform wallet currency symbol. */
|
|
66
|
+
function currencySymbol(currency) {
|
|
67
|
+
if (currency === 'CNY') return '¥';
|
|
68
|
+
if (currency === 'USD') return '$';
|
|
69
|
+
return currency + ' ';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Display a Platform decimal string with two fraction digits. */
|
|
73
|
+
const AMOUNT_FORMAT = new Intl.NumberFormat(undefined, {
|
|
74
|
+
minimumFractionDigits: 2,
|
|
75
|
+
maximumFractionDigits: 2,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
function formatAmount(value) {
|
|
79
|
+
const amount = Number(value);
|
|
80
|
+
return Number.isFinite(amount) ? AMOUNT_FORMAT.format(amount) : value;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** True when a wallet amount is exactly zero (Platform sends decimal strings). */
|
|
84
|
+
function isZeroAmount(value) {
|
|
85
|
+
return Number(value) === 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Turn one `getBalance` result into the amount text for the second bubble
|
|
90
|
+
* line, or null when nothing sensible can be shown (signed out, failed, or
|
|
91
|
+
* empty wallets). The caller adds the localized "balance" label.
|
|
92
|
+
* @param balance - `AccountDetails['balance']` or null.
|
|
93
|
+
* @param bonusLabel - localized "bonus" word.
|
|
94
|
+
*/
|
|
95
|
+
function formatBalance(balance, bonusLabel) {
|
|
96
|
+
if (!balance || balance.status !== 'ready' || !Array.isArray(balance.value)) return null;
|
|
97
|
+
const normal = balance.value
|
|
98
|
+
.filter((wallet) => wallet && typeof wallet.balance === 'string')
|
|
99
|
+
.map((wallet) => currencySymbol(wallet.currency) + formatAmount(wallet.balance));
|
|
100
|
+
if (normal.length === 0) return null;
|
|
101
|
+
const bonus = (balance.bonusWallets ?? [])
|
|
102
|
+
.filter((wallet) => wallet && typeof wallet.balance === 'string' && !isZeroAmount(wallet.balance))
|
|
103
|
+
.map((wallet) => currencySymbol(wallet.currency) + formatAmount(wallet.balance));
|
|
104
|
+
return bonus.length === 0 ? normal.join(' / ') : normal.join(' / ') + '(' + bonusLabel + ' ' + bonus.join(' / ') + ')';
|
|
105
|
+
}
|
|
106
|
+
|
|
24
107
|
/**
|
|
25
108
|
* Component-local stylesheet; unmounting the entry removes it with the
|
|
26
109
|
* node.
|
|
27
|
-
*
|
|
28
|
-
* Placement notes:
|
|
29
|
-
* - 84px above the bottom edge clears the composer's 34px send button and
|
|
30
|
-
* its card padding, so the greeting never covers the primary control.
|
|
31
|
-
* - The card itself is click-through (`pointer-events: none`); only the
|
|
32
|
-
* dismiss button opts back in, so a residual overlap can never swallow a
|
|
33
|
-
* click meant for the app underneath.
|
|
34
|
-
* - Radii and elevation reuse the host tokens, so the bubble reads as one
|
|
35
|
-
* of the app's own floating surfaces in both themes.
|
|
36
110
|
*/
|
|
37
111
|
const STYLES = `
|
|
38
112
|
.dsh-greeting-layer {
|
|
@@ -46,10 +120,11 @@ window.__ModuleLoader__.load({
|
|
|
46
120
|
bottom: calc(84px + env(safe-area-inset-bottom, 0px));
|
|
47
121
|
z-index: 1;
|
|
48
122
|
display: flex;
|
|
49
|
-
|
|
50
|
-
|
|
123
|
+
flex-direction: column;
|
|
124
|
+
align-items: stretch;
|
|
125
|
+
gap: 2px;
|
|
51
126
|
box-sizing: border-box;
|
|
52
|
-
max-width: min(
|
|
127
|
+
max-width: min(340px, calc(100vw - 40px));
|
|
53
128
|
padding: 8px 6px 8px 12px;
|
|
54
129
|
border: 0;
|
|
55
130
|
--dsw-elevation-stroke-color: var(--dsw-alias-border-l3);
|
|
@@ -59,9 +134,21 @@ window.__ModuleLoader__.load({
|
|
|
59
134
|
box-shadow: var(--dsw-elevation-prominent, 0 4px 16px rgba(0, 0, 0, 0.12));
|
|
60
135
|
font-size: 13px;
|
|
61
136
|
line-height: 20px;
|
|
62
|
-
|
|
137
|
+
cursor: grab;
|
|
138
|
+
touch-action: none;
|
|
139
|
+
user-select: none;
|
|
140
|
+
pointer-events: auto;
|
|
63
141
|
animation: dsh-greeting-in 320ms cubic-bezier(0.22, 0.8, 0.24, 1) 350ms both;
|
|
64
142
|
}
|
|
143
|
+
.dsh-greeting-bubble[data-dragging] {
|
|
144
|
+
cursor: grabbing;
|
|
145
|
+
}
|
|
146
|
+
.dsh-greeting-main {
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
gap: 8px;
|
|
150
|
+
min-width: 0;
|
|
151
|
+
}
|
|
65
152
|
.dsh-greeting-wave {
|
|
66
153
|
flex: none;
|
|
67
154
|
font-size: 16px;
|
|
@@ -71,6 +158,31 @@ window.__ModuleLoader__.load({
|
|
|
71
158
|
min-width: 0;
|
|
72
159
|
overflow-wrap: anywhere;
|
|
73
160
|
}
|
|
161
|
+
.dsh-greeting-balance {
|
|
162
|
+
margin: 0;
|
|
163
|
+
padding: 0 0 0 24px;
|
|
164
|
+
border: 0;
|
|
165
|
+
border-radius: var(--dsw-radius-xs, 4px);
|
|
166
|
+
background: transparent;
|
|
167
|
+
color: var(--dsw-alias-label-tertiary);
|
|
168
|
+
font: inherit;
|
|
169
|
+
font-size: 12px;
|
|
170
|
+
line-height: 16px;
|
|
171
|
+
text-align: left;
|
|
172
|
+
width: fit-content;
|
|
173
|
+
max-width: 100%;
|
|
174
|
+
overflow-wrap: anywhere;
|
|
175
|
+
cursor: pointer;
|
|
176
|
+
pointer-events: auto;
|
|
177
|
+
}
|
|
178
|
+
.dsh-greeting-balance:hover {
|
|
179
|
+
color: var(--dsw-alias-label-secondary);
|
|
180
|
+
}
|
|
181
|
+
.dsh-greeting-balance:focus-visible {
|
|
182
|
+
outline: var(--dsw-focus-ring-width, 2px) solid
|
|
183
|
+
var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
|
|
184
|
+
outline-offset: 1px;
|
|
185
|
+
}
|
|
74
186
|
.dsh-greeting-close {
|
|
75
187
|
flex: none;
|
|
76
188
|
display: inline-flex;
|
|
@@ -78,6 +190,7 @@ window.__ModuleLoader__.load({
|
|
|
78
190
|
justify-content: center;
|
|
79
191
|
width: 26px;
|
|
80
192
|
height: 26px;
|
|
193
|
+
margin-left: auto;
|
|
81
194
|
padding: 0;
|
|
82
195
|
border: 0;
|
|
83
196
|
border-radius: var(--dsw-radius-sm, 8px);
|
|
@@ -115,53 +228,226 @@ window.__ModuleLoader__.load({
|
|
|
115
228
|
/**
|
|
116
229
|
* The greeting bubble itself.
|
|
117
230
|
*
|
|
118
|
-
* @param props - the framework `t` seat
|
|
231
|
+
* @param props - the framework `t` seat plus the injected balance loader.
|
|
119
232
|
* @returns the bubble, or null once the reader dismissed it.
|
|
120
233
|
*/
|
|
121
|
-
function GreetingBubble({ t }) {
|
|
234
|
+
function GreetingBubble({ t, loadBalance }) {
|
|
122
235
|
const [dismissed, setDismissed] = React.useState(false);
|
|
236
|
+
const [position, setPosition] = React.useState(readPosition);
|
|
237
|
+
const [dragging, setDragging] = React.useState(false);
|
|
238
|
+
const [walletText, setWalletText] = React.useState(null);
|
|
239
|
+
const bubbleRef = React.useRef(null);
|
|
240
|
+
const dragRef = React.useRef(null);
|
|
241
|
+
const inFlightRef = React.useRef(null);
|
|
242
|
+
const timerRef = React.useRef(null);
|
|
243
|
+
const backoffRef = React.useRef(BALANCE_REFRESH_MS);
|
|
244
|
+
const cancelledRef = React.useRef(false);
|
|
245
|
+
|
|
246
|
+
const label = (key, fallback) => (typeof t === 'function' ? t(key) : fallback);
|
|
247
|
+
|
|
248
|
+
/** Fetch once, deduplicating concurrent calls; resolves to wallet text or null. */
|
|
249
|
+
function readBalance() {
|
|
250
|
+
if (typeof loadBalance !== 'function') return Promise.resolve(null);
|
|
251
|
+
if (inFlightRef.current !== null) return inFlightRef.current;
|
|
252
|
+
const run = Promise.resolve()
|
|
253
|
+
.then(() => loadBalance())
|
|
254
|
+
.then((result) => {
|
|
255
|
+
if (!result || result.ok !== true) return null;
|
|
256
|
+
return formatBalance(result.value, label('bonus', '赠送'));
|
|
257
|
+
})
|
|
258
|
+
.catch(() => null)
|
|
259
|
+
.finally(() => { inFlightRef.current = null; });
|
|
260
|
+
inFlightRef.current = run;
|
|
261
|
+
return run;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** One polling cycle: refresh, then schedule the next attempt with backoff. */
|
|
265
|
+
function tick() {
|
|
266
|
+
if (cancelledRef.current) return;
|
|
267
|
+
const visible = typeof document === 'undefined' || document.visibilityState !== 'hidden';
|
|
268
|
+
if (!visible) {
|
|
269
|
+
timerRef.current = window.setTimeout(tick, BALANCE_REFRESH_MS);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
void readBalance().then((text) => {
|
|
273
|
+
if (cancelledRef.current) return;
|
|
274
|
+
setWalletText(text);
|
|
275
|
+
backoffRef.current = text === null
|
|
276
|
+
? Math.min(backoffRef.current * 2, BALANCE_MAX_BACKOFF_MS)
|
|
277
|
+
: BALANCE_REFRESH_MS;
|
|
278
|
+
timerRef.current = window.setTimeout(tick, backoffRef.current);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Balance polling: visible-only, deduplicated, backed off on failure.
|
|
283
|
+
React.useEffect(() => {
|
|
284
|
+
cancelledRef.current = false;
|
|
285
|
+
tick();
|
|
286
|
+
function handleVisibility() {
|
|
287
|
+
if (typeof document !== 'undefined' && document.visibilityState === 'visible') {
|
|
288
|
+
backoffRef.current = BALANCE_REFRESH_MS;
|
|
289
|
+
if (timerRef.current !== null) window.clearTimeout(timerRef.current);
|
|
290
|
+
tick();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
document.addEventListener('visibilitychange', handleVisibility);
|
|
294
|
+
return () => {
|
|
295
|
+
cancelledRef.current = true;
|
|
296
|
+
if (timerRef.current !== null) window.clearTimeout(timerRef.current);
|
|
297
|
+
document.removeEventListener('visibilitychange', handleVisibility);
|
|
298
|
+
};
|
|
299
|
+
// The loader is stable for the registration's lifetime.
|
|
300
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
301
|
+
}, []);
|
|
302
|
+
|
|
303
|
+
// Keep a remembered spot on screen when the window shrinks.
|
|
304
|
+
React.useEffect(() => {
|
|
305
|
+
function handleResize() {
|
|
306
|
+
setPosition((current) => {
|
|
307
|
+
const element = bubbleRef.current;
|
|
308
|
+
if (current === null || element === null) return current;
|
|
309
|
+
const x = clamp(current.x, 0, window.innerWidth - element.offsetWidth);
|
|
310
|
+
const y = clamp(current.y, 0, window.innerHeight - element.offsetHeight);
|
|
311
|
+
return x === current.x && y === current.y ? current : { x, y };
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
window.addEventListener('resize', handleResize);
|
|
315
|
+
return () => { window.removeEventListener('resize', handleResize); };
|
|
316
|
+
}, []);
|
|
317
|
+
|
|
123
318
|
if (dismissed) return null;
|
|
124
|
-
const text =
|
|
125
|
-
const dismissLabel =
|
|
319
|
+
const text = label('greeting', '你好,腾盛');
|
|
320
|
+
const dismissLabel = label('dismiss', '关闭问候气泡');
|
|
321
|
+
const balanceLine = label('balance', '余额') + ' ' + (walletText ?? label('unavailable', '--'));
|
|
322
|
+
|
|
323
|
+
/** Manual refresh: reset the backoff and read once. */
|
|
324
|
+
function handleBalanceClick(event) {
|
|
325
|
+
event.stopPropagation();
|
|
326
|
+
backoffRef.current = BALANCE_REFRESH_MS;
|
|
327
|
+
void readBalance().then((value) => {
|
|
328
|
+
if (!cancelledRef.current) setWalletText(value);
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Start a drag: switch to absolute coordinates and capture the pointer. */
|
|
333
|
+
function handlePointerDown(event) {
|
|
334
|
+
if (event.button !== undefined && event.button !== 0) return;
|
|
335
|
+
if (event.target && event.target.closest && event.target.closest('button')) return;
|
|
336
|
+
const element = bubbleRef.current;
|
|
337
|
+
if (!element) return;
|
|
338
|
+
const rect = element.getBoundingClientRect();
|
|
339
|
+
dragRef.current = {
|
|
340
|
+
pointerId: event.pointerId,
|
|
341
|
+
startX: event.clientX,
|
|
342
|
+
startY: event.clientY,
|
|
343
|
+
left: rect.left,
|
|
344
|
+
top: rect.top,
|
|
345
|
+
width: rect.width,
|
|
346
|
+
height: rect.height,
|
|
347
|
+
};
|
|
348
|
+
setPosition({ x: rect.left, y: rect.top });
|
|
349
|
+
setDragging(true);
|
|
350
|
+
if (typeof element.setPointerCapture === 'function') {
|
|
351
|
+
element.setPointerCapture(event.pointerId);
|
|
352
|
+
}
|
|
353
|
+
event.preventDefault();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** Move within the viewport while the pointer is captured. */
|
|
357
|
+
function handlePointerMove(event) {
|
|
358
|
+
const drag = dragRef.current;
|
|
359
|
+
if (drag === null || event.pointerId !== drag.pointerId) return;
|
|
360
|
+
const x = drag.left + event.clientX - drag.startX;
|
|
361
|
+
const y = drag.top + event.clientY - drag.startY;
|
|
362
|
+
setPosition({
|
|
363
|
+
x: clamp(x, 0, window.innerWidth - drag.width),
|
|
364
|
+
y: clamp(y, 0, window.innerHeight - drag.height),
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** Finish a drag, clamp once more, and persist the dropped spot. */
|
|
369
|
+
function handlePointerUp(event) {
|
|
370
|
+
const drag = dragRef.current;
|
|
371
|
+
if (drag === null || event.pointerId !== drag.pointerId) return;
|
|
372
|
+
dragRef.current = null;
|
|
373
|
+
setDragging(false);
|
|
374
|
+
const element = bubbleRef.current;
|
|
375
|
+
if (!element) return;
|
|
376
|
+
const rect = element.getBoundingClientRect();
|
|
377
|
+
const dropped = {
|
|
378
|
+
x: Math.round(clamp(rect.left, 0, window.innerWidth - rect.width)),
|
|
379
|
+
y: Math.round(clamp(rect.top, 0, window.innerHeight - rect.height)),
|
|
380
|
+
};
|
|
381
|
+
setPosition(dropped);
|
|
382
|
+
writePosition(dropped);
|
|
383
|
+
}
|
|
384
|
+
|
|
126
385
|
return h(
|
|
127
386
|
'div',
|
|
128
387
|
{ className: 'dsh-greeting-layer', style: { position: 'absolute', inset: 0, pointerEvents: 'none' } },
|
|
129
388
|
h('style', { key: 'styles' }, STYLES),
|
|
130
389
|
h(
|
|
131
390
|
'div',
|
|
132
|
-
{
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
391
|
+
{
|
|
392
|
+
key: 'bubble',
|
|
393
|
+
ref: bubbleRef,
|
|
394
|
+
className: 'dsh-greeting-bubble',
|
|
395
|
+
'data-dragging': dragging ? '' : undefined,
|
|
396
|
+
style: position === null
|
|
397
|
+
? undefined
|
|
398
|
+
: { left: position.x, top: position.y, right: 'auto', bottom: 'auto' },
|
|
399
|
+
onPointerDown: handlePointerDown,
|
|
400
|
+
onPointerMove: handlePointerMove,
|
|
401
|
+
onPointerUp: handlePointerUp,
|
|
402
|
+
onPointerCancel: handlePointerUp,
|
|
403
|
+
},
|
|
404
|
+
h(
|
|
405
|
+
'div',
|
|
406
|
+
{ className: 'dsh-greeting-main', key: 'main' },
|
|
407
|
+
h('span', { className: 'dsh-greeting-wave', 'aria-hidden': 'true' }, '👋'),
|
|
408
|
+
// `lang` pins the reading voice for this fixed Chinese phrase; the
|
|
409
|
+
// status role lives on the text so the controls stay outside the
|
|
410
|
+
// live region.
|
|
411
|
+
h('span', { className: 'dsh-greeting-text', role: 'status', lang: 'zh-CN' }, text),
|
|
412
|
+
h(
|
|
413
|
+
'button',
|
|
414
|
+
{
|
|
415
|
+
className: 'dsh-greeting-close',
|
|
416
|
+
type: 'button',
|
|
417
|
+
title: dismissLabel,
|
|
418
|
+
'aria-label': dismissLabel,
|
|
419
|
+
onClick: () => { setDismissed(true); },
|
|
420
|
+
},
|
|
421
|
+
h(
|
|
422
|
+
'svg',
|
|
423
|
+
{ width: 13, height: 13, viewBox: '0 0 12 12', 'aria-hidden': 'true' },
|
|
424
|
+
h('path', {
|
|
425
|
+
d: 'M2.5 2.5l7 7M9.5 2.5l-7 7',
|
|
426
|
+
fill: 'none',
|
|
427
|
+
stroke: 'currentColor',
|
|
428
|
+
strokeWidth: 1.4,
|
|
429
|
+
strokeLinecap: 'round',
|
|
430
|
+
}),
|
|
431
|
+
),
|
|
432
|
+
),
|
|
433
|
+
),
|
|
138
434
|
h(
|
|
139
435
|
'button',
|
|
140
436
|
{
|
|
141
|
-
|
|
437
|
+
key: 'balance',
|
|
438
|
+
className: 'dsh-greeting-balance',
|
|
142
439
|
type: 'button',
|
|
143
|
-
title:
|
|
144
|
-
|
|
145
|
-
onClick: () => { setDismissed(true); },
|
|
440
|
+
title: label('refreshBalance', '刷新余额'),
|
|
441
|
+
onClick: handleBalanceClick,
|
|
146
442
|
},
|
|
147
|
-
|
|
148
|
-
'svg',
|
|
149
|
-
{ width: 13, height: 13, viewBox: '0 0 12 12', 'aria-hidden': 'true' },
|
|
150
|
-
h('path', {
|
|
151
|
-
d: 'M2.5 2.5l7 7M9.5 2.5l-7 7',
|
|
152
|
-
fill: 'none',
|
|
153
|
-
stroke: 'currentColor',
|
|
154
|
-
strokeWidth: 1.4,
|
|
155
|
-
strokeLinecap: 'round',
|
|
156
|
-
}),
|
|
157
|
-
),
|
|
443
|
+
balanceLine,
|
|
158
444
|
),
|
|
159
445
|
),
|
|
160
446
|
);
|
|
161
447
|
}
|
|
162
448
|
|
|
163
449
|
return {
|
|
164
|
-
inject: ['slots', 'locale'],
|
|
450
|
+
inject: ['slots', 'locale', 'remote', 'remote.account'],
|
|
165
451
|
/**
|
|
166
452
|
* Register the plugin's dictionary and its single overlay entry.
|
|
167
453
|
* @param ctx - client plugin context.
|
|
@@ -170,17 +456,53 @@ window.__ModuleLoader__.load({
|
|
|
170
456
|
ctx.effect(
|
|
171
457
|
() => ctx.locale.register(NS, {
|
|
172
458
|
// The greeting is the plugin's fixed signature phrase, so it stays
|
|
173
|
-
// identical in every locale; only
|
|
174
|
-
zh: {
|
|
175
|
-
|
|
459
|
+
// identical in every locale; only control labels are localized.
|
|
460
|
+
zh: {
|
|
461
|
+
greeting: '你好,腾盛',
|
|
462
|
+
dismiss: '关闭问候气泡',
|
|
463
|
+
balance: '余额',
|
|
464
|
+
bonus: '赠送',
|
|
465
|
+
unavailable: '--',
|
|
466
|
+
refreshBalance: '刷新余额',
|
|
467
|
+
},
|
|
468
|
+
en: {
|
|
469
|
+
greeting: '你好,腾盛',
|
|
470
|
+
dismiss: 'Dismiss greeting',
|
|
471
|
+
balance: 'Balance',
|
|
472
|
+
bonus: 'Bonus',
|
|
473
|
+
unavailable: '--',
|
|
474
|
+
refreshBalance: 'Refresh balance',
|
|
475
|
+
},
|
|
176
476
|
}),
|
|
177
477
|
'greeting-bubble: dictionaries',
|
|
178
478
|
);
|
|
479
|
+
/** Current request identity for the Host's Platform calls. */
|
|
480
|
+
const metadata = () => {
|
|
481
|
+
let version = '';
|
|
482
|
+
try {
|
|
483
|
+
version = (typeof process !== 'undefined' && process.env && process.env.DSH_CLIENT_VERSION) || '';
|
|
484
|
+
} catch {
|
|
485
|
+
// `process` is absent in some browser builds; an empty version is fine.
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
version,
|
|
489
|
+
locale: ctx.locale.getSnapshot().active,
|
|
490
|
+
timezoneOffsetSeconds: -new Date().getTimezoneOffset() * 60,
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
const loadBalance = () => {
|
|
494
|
+
const account = ctx.remote && ctx.remote.account;
|
|
495
|
+
if (!account || typeof account.getBalance !== 'function') {
|
|
496
|
+
throw new Error('account service unavailable');
|
|
497
|
+
}
|
|
498
|
+
return account.getBalance(metadata());
|
|
499
|
+
};
|
|
179
500
|
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
180
501
|
name: 'shell.overlay',
|
|
181
502
|
id: 'greeting-bubble',
|
|
182
503
|
order: 50,
|
|
183
504
|
locale: NS,
|
|
505
|
+
inject: () => ({ loadBalance }),
|
|
184
506
|
}, GreetingBubble));
|
|
185
507
|
},
|
|
186
508
|
};
|
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Greeting bubble",
|
|
4
|
-
"description": "Shows a “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer,
|
|
4
|
+
"description": "Shows a “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer, plus the signed-in DeepSeek account balance (top-up and bonus wallets) refreshed every 60 seconds; click the balance line to refresh it immediately. Drag the bubble anywhere; its position is remembered for the next visit. Click × to dismiss it; it appears again on the next page load. The greeting stays Chinese in every interface language; only control labels are localized. Balance is read through the DSH account service, so the browser never sees the account token; a signed-out or failed read shows “Balance --”. The plugin makes no network requests of its own and collects no data. Disable or remove the bundle under Plugins to remove it.",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "右下角问候气泡",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "页面加载后,在窗口右下角、输入框上方弹出「你好,腾盛」问候气泡,并显示当前 DeepSeek 账号余额(充值 + 赠送),每 60 秒刷新一次,点击余额行可立即刷新。按住气泡可以拖到任意位置,位置会记住,下次打开仍在原处。点气泡上的 × 即可关闭,下次页面加载时会再次出现。问候语在任何界面语言下都保持中文,只有按钮提示跟随界面语言。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「余额 --」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
|
|
5
5
|
"detail": "docs/DETAIL.zh.md"
|
|
6
6
|
}
|
|
7
7
|
}
|