dsh-workbuddy-login-ui 1.0.0 → 1.0.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 +12 -0
- package/lib/client.js +44 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,6 +66,18 @@ Host 侧暴露三个方法给界面(Cordis 服务键 `workbuddyLogin`):
|
|
|
66
66
|
| `getState()` | 返回 `{ loggedIn, nickname, uid, pendingUrl, pendingExpiresInMs, lastError }` |
|
|
67
67
|
| `cancelSignIn()` | 取消等待 |
|
|
68
68
|
|
|
69
|
+
## 变更记录
|
|
70
|
+
|
|
71
|
+
### 1.0.1
|
|
72
|
+
|
|
73
|
+
- 修正:按钮在插件详情页不显示。`plugins.detail.actions` 的 `subject` 结构是 `{ kind: 'item', id }`,没有 `name` 字段;改为按 `subject.id` 匹配。
|
|
74
|
+
- 修正:客户端 `inject` 补上 `remote` 和 `remote.workbuddyLogin`,否则取不到 Host 服务。
|
|
75
|
+
- 改为用 slot 的 `inject: () => ({ service })` 标准方式传服务,不再依赖闭包。
|
|
76
|
+
|
|
77
|
+
### 1.0.0
|
|
78
|
+
|
|
79
|
+
- 首个版本。
|
|
80
|
+
|
|
69
81
|
## 依赖
|
|
70
82
|
|
|
71
83
|
- DSH 已安装(提供 `@deepseek-ai/dsh-typert-protocol`)
|
package/lib/client.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WorkBuddy 登录 UI —— 客户端
|
|
3
3
|
*
|
|
4
|
-
* 在「插件详情页」的
|
|
5
|
-
*
|
|
6
|
-
* - 已登录:显示昵称 + 退出
|
|
7
|
-
* - 等待中:显示授权链接和倒计时
|
|
4
|
+
* 在「插件详情页」的 actions 区放登录按钮。
|
|
5
|
+
* 走 OAuth device flow,不经过模型 —— 所以没有「没登录就没模型可用」的死锁。
|
|
8
6
|
*/
|
|
9
7
|
window.__ModuleLoader__.load({
|
|
10
8
|
id: 'dsh-workbuddy-login-ui',
|
|
@@ -18,74 +16,81 @@ window.__ModuleLoader__.load({
|
|
|
18
16
|
btn: {
|
|
19
17
|
appearance: 'none', border: '1px solid currentColor', borderRadius: 6,
|
|
20
18
|
background: 'transparent', color: 'inherit', cursor: 'pointer',
|
|
21
|
-
font: 'inherit', padding: '4px 12px', lineHeight: 1.5,
|
|
19
|
+
font: 'inherit', fontSize: 13, padding: '4px 12px', lineHeight: 1.5,
|
|
22
20
|
},
|
|
23
21
|
btnPrimary: { background: '#247bbf', borderColor: '#247bbf', color: '#fff' },
|
|
24
22
|
link: {
|
|
25
23
|
fontSize: 12, color: '#247bbf', wordBreak: 'break-all',
|
|
26
|
-
|
|
24
|
+
textDecoration: 'underline',
|
|
27
25
|
},
|
|
28
|
-
ok: { fontSize: 12, opacity: 0.
|
|
26
|
+
ok: { fontSize: 12, opacity: 0.75 },
|
|
29
27
|
err: { fontSize: 12, color: '#c0392b' },
|
|
30
28
|
};
|
|
31
29
|
|
|
32
|
-
/**
|
|
30
|
+
/** 登录按钮。service 由 slot 的 inject 注入。 */
|
|
33
31
|
function LoginAction(props) {
|
|
32
|
+
const svc = props?.service;
|
|
34
33
|
const [state, setState] = useState(null);
|
|
35
34
|
const [busy, setBusy] = useState(false);
|
|
36
|
-
|
|
37
|
-
// service 由 DSH 注入(Remote 服务名)
|
|
38
|
-
const svc = props?.service;
|
|
35
|
+
const [localErr, setLocalErr] = useState('');
|
|
39
36
|
|
|
40
37
|
const refresh = useCallback(async () => {
|
|
41
|
-
if (!svc) return;
|
|
38
|
+
if (!svc?.getState) return;
|
|
42
39
|
try {
|
|
43
40
|
const s = await svc.getState();
|
|
44
41
|
setState(s);
|
|
45
|
-
} catch {
|
|
42
|
+
} catch (e) {
|
|
43
|
+
setLocalErr(String(e?.message ?? e));
|
|
44
|
+
}
|
|
46
45
|
}, [svc]);
|
|
47
46
|
|
|
48
47
|
useEffect(() => {
|
|
48
|
+
if (!svc) return undefined;
|
|
49
49
|
refresh();
|
|
50
50
|
const t = setInterval(refresh, 2000);
|
|
51
51
|
return () => clearInterval(t);
|
|
52
|
-
}, [refresh]);
|
|
52
|
+
}, [svc, refresh]);
|
|
53
|
+
|
|
54
|
+
if (!svc) {
|
|
55
|
+
return h('div', { style: S.wrap },
|
|
56
|
+
h('span', { style: S.err }, '登录服务未就绪(请重启 DSH)'));
|
|
57
|
+
}
|
|
53
58
|
|
|
54
59
|
const onLogin = async () => {
|
|
55
|
-
if (!svc) return;
|
|
56
60
|
setBusy(true);
|
|
61
|
+
setLocalErr('');
|
|
57
62
|
try {
|
|
58
63
|
const r = await svc.startSignIn();
|
|
59
64
|
if (r?.ok && r.url) {
|
|
60
|
-
// 新窗口打开授权页
|
|
61
65
|
window.open(r.url, '_blank', 'noopener,noreferrer');
|
|
66
|
+
} else if (r?.error) {
|
|
67
|
+
setLocalErr(r.error);
|
|
62
68
|
}
|
|
63
69
|
await refresh();
|
|
64
70
|
} catch (e) {
|
|
65
|
-
|
|
71
|
+
setLocalErr(String(e?.message ?? e));
|
|
66
72
|
} finally {
|
|
67
73
|
setBusy(false);
|
|
68
74
|
}
|
|
69
75
|
};
|
|
70
76
|
|
|
71
|
-
|
|
77
|
+
const err = localErr || state?.lastError || '';
|
|
72
78
|
|
|
73
|
-
if (state
|
|
79
|
+
if (state?.loggedIn) {
|
|
74
80
|
return h('div', { style: S.wrap },
|
|
75
|
-
h('span', { style: S.ok }, `已登录:${state.nickname || state.uid || '账号'}`),
|
|
81
|
+
h('span', { style: S.ok }, `已登录:${state.nickname || state.uid || 'WorkBuddy 账号'}`),
|
|
76
82
|
h('button', {
|
|
77
|
-
type: 'button',
|
|
78
|
-
style: S.btn,
|
|
83
|
+
type: 'button', style: S.btn,
|
|
79
84
|
onClick: async () => {
|
|
80
|
-
await svc.cancelSignIn?.();
|
|
81
|
-
await
|
|
85
|
+
try { await svc.cancelSignIn?.(); } catch { /* 忽略 */ }
|
|
86
|
+
await onLogin();
|
|
82
87
|
},
|
|
83
88
|
}, '重新登录'),
|
|
84
89
|
);
|
|
85
90
|
}
|
|
86
91
|
|
|
87
|
-
const waiting = Boolean(state
|
|
88
|
-
const mins = Math.max(0, Math.ceil((state
|
|
92
|
+
const waiting = Boolean(state?.pendingUrl);
|
|
93
|
+
const mins = Math.max(0, Math.ceil((state?.pendingExpiresInMs || 0) / 60000));
|
|
89
94
|
|
|
90
95
|
return h('div', { style: S.wrap },
|
|
91
96
|
h('button', {
|
|
@@ -95,35 +100,31 @@ window.__ModuleLoader__.load({
|
|
|
95
100
|
onClick: onLogin,
|
|
96
101
|
}, busy ? '获取中…' : waiting ? '等待授权…' : '登录 WorkBuddy'),
|
|
97
102
|
waiting
|
|
98
|
-
? h('
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}, '点此打开授权页'),
|
|
103
|
-
h('span', { style: S.ok }, `或复制链接 · ${mins} 分钟内有效`),
|
|
104
|
-
)
|
|
103
|
+
? h('a', {
|
|
104
|
+
href: state.pendingUrl, target: '_blank', rel: 'noopener noreferrer',
|
|
105
|
+
style: S.link,
|
|
106
|
+
}, '点此打开授权页')
|
|
105
107
|
: null,
|
|
106
|
-
|
|
107
|
-
? h('span', { style: S.
|
|
108
|
+
waiting && mins
|
|
109
|
+
? h('span', { style: S.ok }, `${mins} 分钟内有效`)
|
|
108
110
|
: null,
|
|
111
|
+
err ? h('span', { style: S.err }, err) : null,
|
|
109
112
|
);
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
return {
|
|
113
|
-
inject: ['slots'],
|
|
116
|
+
inject: ['slots', 'remote', 'remote.workbuddyLogin'],
|
|
114
117
|
apply(ctx) {
|
|
115
|
-
// 插件详情页的操作区
|
|
116
118
|
ctx.slots.inject('plugins.detail.actions', () => ctx.slots.register({
|
|
117
119
|
name: 'plugins.detail.actions',
|
|
118
120
|
id: 'workbuddy-login',
|
|
119
121
|
order: 10,
|
|
122
|
+
inject: () => ({ service: ctx.remote?.workbuddyLogin }),
|
|
120
123
|
}, (props) => {
|
|
121
|
-
//
|
|
122
|
-
const
|
|
123
|
-
if (!/workbuddy/i.test(
|
|
124
|
-
|
|
125
|
-
const service = ctx.remote?.workbuddyLogin;
|
|
126
|
-
return h(LoginAction, { service });
|
|
124
|
+
// subject 是 { kind: 'item', id },没有 name
|
|
125
|
+
const id = String(props?.subject?.id ?? '');
|
|
126
|
+
if (!/workbuddy/i.test(id)) return null;
|
|
127
|
+
return h(LoginAction, props);
|
|
127
128
|
}));
|
|
128
129
|
},
|
|
129
130
|
};
|