@xmanrui/dsh-im 5.2.0 → 5.4.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/THIRD_PARTY_NOTICES.md +209 -0
- package/docs/client-integration.md +8 -4
- package/lib/client.js +1988 -250
- package/lib/index.js +327 -321
- package/package.json +1 -1
- package/plugin-src/client/channels/telegram/group-triggers-settings.js +393 -0
- package/plugin-src/client/connection-error.js +2 -1
- package/plugin-src/client/delivery-settings.js +21 -1
- package/plugin-src/client/ds-bot-avatar-data.js +537 -0
- package/plugin-src/client/ds-bot-avatar.js +55 -0
- package/plugin-src/client/ds-bot-session-avatars.js +77 -0
- package/plugin-src/client/ds-bot-settings.js +194 -0
- package/plugin-src/client/global-settings.js +2 -1
- package/plugin-src/client/i18n.js +67 -1
- package/plugin-src/client/index.js +49 -18
- package/plugin-src/client/plugin-page.js +39 -17
- package/plugin-src/client/sidebar-settings.js +129 -0
- package/plugin-src/client/styles.js +33 -5
- package/plugin-src/host/channels/dingtalk/production.mjs +2 -1
- package/plugin-src/host/channels/dingtalk/rpc.mjs +5 -1
- package/plugin-src/host/channels/feishu/production.mjs +13 -5
- package/plugin-src/host/channels/feishu/rpc.mjs +5 -1
- package/plugin-src/host/channels/qq/production.mjs +2 -1
- package/plugin-src/host/channels/qq/rpc.mjs +5 -1
- package/plugin-src/host/channels/shared/group-triggers-rpc.mjs +110 -0
- package/plugin-src/host/channels/shared/production.mjs +7 -1
- package/plugin-src/host/channels/slack/production.mjs +2 -1
- package/plugin-src/host/channels/telegram/index.mjs +1 -0
- package/plugin-src/host/channels/telegram/production.mjs +2 -0
- package/plugin-src/host/channels/telegram/rpc.mjs +17 -2
- package/plugin-src/host/channels/wecom/production.mjs +4 -1
- package/plugin-src/host/channels/wecom/rpc.mjs +5 -1
- package/plugin-src/host/channels/wecom-app/production.mjs +2 -1
- package/plugin-src/host/channels/weixin/production.mjs +2 -1
- package/plugin-src/host/channels/weixin/rpc.mjs +3 -2
- package/plugin-src/host/channels/whatsapp/production.mjs +2 -1
- package/plugin-src/host/channels/whatsapp/rpc.mjs +5 -1
- package/plugin-src/host/delivery-adapter.mjs +89 -9
- package/plugin-src/host/delivery-rpc.mjs +33 -1
- package/plugin-src/host/delivery-service.mjs +70 -1
- package/plugin-src/host/delivery-suggestions.mjs +11 -0
- package/plugin-src/host/ds-bot-client.mjs +74 -0
- package/plugin-src/host/index.mjs +12 -1
- package/plugin-src/host/sidebar-settings.mjs +113 -0
- package/src/channels/feishu/feishu-cards.mjs +11 -7
- package/src/channels/imessage/imessage-api.mjs +67 -2
- package/src/channels/shared/bot-workspace-store.mjs +136 -7
- package/src/channels/shared/connection-error.mjs +5 -5
- package/src/channels/shared/diagnostic-details.mjs +15 -1
- package/src/channels/shared/group-history-store.mjs +26 -0
- package/src/channels/shared/i18n-en/diagnostics.mjs +5 -0
- package/src/channels/shared/i18n-en/feishu.mjs +1 -0
- package/src/channels/shared/i18n-en/wecom.mjs +4 -0
- package/src/channels/shared/qr-encoding-error.mjs +39 -0
- package/src/channels/shared/session-binding-lock.mjs +2 -0
- package/src/channels/shared/workspace-session.mjs +5 -1
- package/src/channels/telegram/config-store.mjs +5 -1
- package/src/channels/telegram/group-triggers.mjs +229 -0
- package/src/channels/telegram/telegram-api.mjs +12 -0
- package/src/channels/telegram/telegram-controller.mjs +110 -1
- package/src/channels/telegram/telegram-runtime.mjs +15 -2
- package/src/channels/wecom/stream-supervisor.mjs +184 -0
- package/src/channels/wecom/wecom-bridge.mjs +25 -11
- package/src/channels/wecom/wecom-runtime.mjs +12 -1
- package/src/channels/weixin/connection-error.mjs +1 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { h } from './i18n.js';
|
|
3
|
+
import { DsBotAvatar } from './ds-bot-avatar.js';
|
|
4
|
+
|
|
5
|
+
export const DS_BOT_MESSAGES = Object.freeze({
|
|
6
|
+
missing: '未安装 DS Bot,请先在 DSH 插件管理中安装 ds-bot,然后刷新。',
|
|
7
|
+
disabled: 'DS Bot 尚未启用,请在 DSH 插件管理中启用后刷新。',
|
|
8
|
+
unavailable: '暂时无法读取 DS Bot,请检查插件是否正常运行后重试。',
|
|
9
|
+
readonly: 'DS Bot 当前由其他 Host 管理,请在运行它的 Host 中绑定。',
|
|
10
|
+
remote: '绑定bot仅支持当前 Host 的会话,请先检查机器人的 Harness 连接设置。',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export function dsBotErrorMessage(error) {
|
|
14
|
+
return {
|
|
15
|
+
'ds-bot-unavailable': DS_BOT_MESSAGES.unavailable,
|
|
16
|
+
'ds-bot-not-found': '所选 DS Bot 已不存在,请刷新后重新选择。',
|
|
17
|
+
'ds-bot-private-required': '仅支持已经建立会话的私聊,请先与机器人私聊后刷新。',
|
|
18
|
+
'ds-bot-binding-conflict': '所选 DS Bot 或私聊对象已绑定,请刷新后重新选择。',
|
|
19
|
+
}[error?.code] ?? '绑定设置保存失败,请刷新后重试。';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function DsBotPicker({ bots, value, onChange, disabled }) {
|
|
23
|
+
const [open, setOpen] = React.useState(false);
|
|
24
|
+
const [active, setActive] = React.useState(0);
|
|
25
|
+
const root = React.useRef(null);
|
|
26
|
+
const trigger = React.useRef(null);
|
|
27
|
+
const listId = React.useId();
|
|
28
|
+
const selected = bots.find((bot) => bot.id === value);
|
|
29
|
+
const isOpen = open && !disabled && bots.length > 0;
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
const dismiss = (event) => { if (!root.current?.contains(event.target)) setOpen(false); };
|
|
32
|
+
if (open) globalThis.document?.addEventListener('pointerdown', dismiss);
|
|
33
|
+
return () => globalThis.document?.removeEventListener('pointerdown', dismiss);
|
|
34
|
+
}, [open]);
|
|
35
|
+
const choose = (bot) => { onChange(bot.id); setOpen(false); trigger.current?.focus(); };
|
|
36
|
+
const optionId = (index) => `${listId}-${index}`;
|
|
37
|
+
return h('div', { className: 'dim-dsBotPicker', ref: root },
|
|
38
|
+
h('button', {
|
|
39
|
+
type: 'button', role: 'combobox', ref: trigger, className: 'dim-dsBotPickerTrigger',
|
|
40
|
+
disabled: disabled || !bots.length, 'aria-label': 'DS Bot', 'aria-expanded': isOpen, 'aria-controls': listId,
|
|
41
|
+
'aria-haspopup': 'listbox', 'aria-activedescendant': isOpen ? optionId(active) : undefined,
|
|
42
|
+
onClick: () => { setActive(Math.max(0, bots.findIndex((bot) => bot.id === value))); setOpen(!open); },
|
|
43
|
+
onKeyDown: (event) => {
|
|
44
|
+
if (disabled || !bots.length) return;
|
|
45
|
+
if (['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
const index = event.key === 'Home' ? 0 : event.key === 'End' ? bots.length - 1
|
|
48
|
+
: open ? (active + (event.key === 'ArrowDown' ? 1 : -1) + bots.length) % bots.length
|
|
49
|
+
: Math.max(0, bots.findIndex((bot) => bot.id === value));
|
|
50
|
+
setActive(index); setOpen(true);
|
|
51
|
+
} else if (open && ['Enter', ' '].includes(event.key)) {
|
|
52
|
+
event.preventDefault(); if (bots[active]) choose(bots[active]);
|
|
53
|
+
} else if (event.key === 'Escape' || event.key === 'Tab') setOpen(false);
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
selected ? h(DsBotAvatar, { bot: selected }) : null,
|
|
57
|
+
selected ? React.createElement('span', { className: 'dim-dsBotPickerName' }, selected.name)
|
|
58
|
+
: h('span', { className: 'dim-dsBotPickerName' }, bots.length ? '选择 DS Bot' : '暂无可选 DS Bot'),
|
|
59
|
+
h('svg', { width: 14, height: 14, viewBox: '0 0 16 16', 'aria-hidden': true },
|
|
60
|
+
h('path', { d: 'm4 6 4 4 4-4', fill: 'none', stroke: 'currentColor', strokeWidth: 1.5, strokeLinecap: 'round' }))),
|
|
61
|
+
isOpen ? h('div', { id: listId, role: 'listbox', 'aria-label': 'DS Bot', className: 'dim-dsBotOptions' },
|
|
62
|
+
bots.map((bot, index) => h('button', {
|
|
63
|
+
key: bot.id, id: optionId(index), type: 'button', role: 'option', tabIndex: -1,
|
|
64
|
+
'aria-selected': value === bot.id, 'data-active': active === index,
|
|
65
|
+
onMouseDown: (event) => event.preventDefault(), onMouseEnter: () => setActive(index), onClick: () => choose(bot),
|
|
66
|
+
}, h(DsBotAvatar, { bot }),
|
|
67
|
+
React.createElement('span', { className: 'dim-dsBotPickerName' }, bot.name),
|
|
68
|
+
value === bot.id ? h('span', { 'aria-hidden': true }, '✓') : null))) : null);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function conversationLabel(conversation) {
|
|
72
|
+
if (conversation.name) return conversation.name;
|
|
73
|
+
const value = conversation.address;
|
|
74
|
+
return value.length > 24 ? `${value.slice(0, 10)}…${value.slice(-8)}` : value;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function DsBotSettingsPage({ botId, rpcCall }) {
|
|
78
|
+
const [status, setStatus] = React.useState(null);
|
|
79
|
+
const [dsBotId, setDsBotId] = React.useState('');
|
|
80
|
+
const [conversationKey, setConversationKey] = React.useState('');
|
|
81
|
+
const [loading, setLoading] = React.useState(true);
|
|
82
|
+
const [busy, setBusy] = React.useState(false);
|
|
83
|
+
const [feedback, setFeedback] = React.useState(null);
|
|
84
|
+
const [feedbackTone, setFeedbackTone] = React.useState('success');
|
|
85
|
+
const requests = React.useRef({ revision: 0, busy: false, controller: null });
|
|
86
|
+
const refresh = React.useCallback(async (signal = requests.current.controller?.signal) => {
|
|
87
|
+
const state = requests.current;
|
|
88
|
+
if (signal?.aborted) return;
|
|
89
|
+
const revision = ++state.revision;
|
|
90
|
+
const current = () => !signal?.aborted && revision === state.revision;
|
|
91
|
+
setLoading(true);
|
|
92
|
+
try {
|
|
93
|
+
const value = await rpcCall('ds-bot.status', { botId }, signal);
|
|
94
|
+
if (current()) setStatus(value);
|
|
95
|
+
} catch {
|
|
96
|
+
if (current()) setStatus((previous) => ({ ...previous, state: 'unavailable' }));
|
|
97
|
+
} finally {
|
|
98
|
+
if (current()) setLoading(false);
|
|
99
|
+
}
|
|
100
|
+
}, [botId, rpcCall]);
|
|
101
|
+
React.useEffect(() => {
|
|
102
|
+
const controller = new AbortController();
|
|
103
|
+
requests.current.controller = controller;
|
|
104
|
+
void refresh(controller.signal);
|
|
105
|
+
return () => {
|
|
106
|
+
controller.abort();
|
|
107
|
+
requests.current.revision++;
|
|
108
|
+
};
|
|
109
|
+
}, [refresh]);
|
|
110
|
+
const conversations = status?.conversations ?? [];
|
|
111
|
+
const bots = status?.bots ?? [];
|
|
112
|
+
const bindings = conversations.filter((conversation) => conversation.dsBotId);
|
|
113
|
+
const usedBotIds = new Set(bindings.map((binding) => binding.dsBotId));
|
|
114
|
+
const availableBots = bots.filter((bot) => !usedBotIds.has(bot.id));
|
|
115
|
+
const availableConversations = conversations.filter((conversation) => !conversation.dsBotId);
|
|
116
|
+
const canSave = !busy && !loading && status?.state === 'ready'
|
|
117
|
+
&& availableBots.some((bot) => bot.id === dsBotId)
|
|
118
|
+
&& availableConversations.some((conversation) => conversation.conversationKey === conversationKey);
|
|
119
|
+
React.useEffect(() => {
|
|
120
|
+
setDsBotId((value) => availableBots.some((bot) => bot.id === value) ? value : '');
|
|
121
|
+
setConversationKey((value) => availableConversations.some((conversation) => conversation.conversationKey === value) ? value : '');
|
|
122
|
+
}, [status]);
|
|
123
|
+
const save = async (event) => {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
if (!canSave || requests.current.busy) return;
|
|
126
|
+
requests.current.busy = true;
|
|
127
|
+
requests.current.revision++;
|
|
128
|
+
setBusy(true); setFeedback(null);
|
|
129
|
+
try {
|
|
130
|
+
await rpcCall('ds-bot.bind', { botId, conversationKey, dsBotId });
|
|
131
|
+
setDsBotId(''); setConversationKey('');
|
|
132
|
+
await refresh();
|
|
133
|
+
setFeedbackTone('success'); setFeedback('绑定已保存。');
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error?.code === 'ds-bot-binding-conflict') await refresh();
|
|
136
|
+
setFeedbackTone('error'); setFeedback(dsBotErrorMessage(error));
|
|
137
|
+
} finally { requests.current.busy = false; setBusy(false); }
|
|
138
|
+
};
|
|
139
|
+
const unbind = async (key) => {
|
|
140
|
+
if (requests.current.busy) return;
|
|
141
|
+
requests.current.busy = true;
|
|
142
|
+
requests.current.revision++;
|
|
143
|
+
setBusy(true); setFeedback(null);
|
|
144
|
+
try {
|
|
145
|
+
await rpcCall('ds-bot.unbind', { botId, conversationKey: key });
|
|
146
|
+
await refresh();
|
|
147
|
+
setFeedbackTone('success'); setFeedback('已解除绑定,聊天记录保留。');
|
|
148
|
+
} catch (error) {
|
|
149
|
+
setFeedbackTone('error'); setFeedback(dsBotErrorMessage(error));
|
|
150
|
+
} finally { requests.current.busy = false; setBusy(false); }
|
|
151
|
+
};
|
|
152
|
+
return h('section', { className: 'dim-deliveryTargets dim-dsBotSettings', 'aria-label': '绑定bot' },
|
|
153
|
+
h('div', { className: 'dim-deliverySectionHeading' },
|
|
154
|
+
h('div', null, h('h3', null, '绑定bot'), h('p', null, '选择 DS Bot 和私聊对象,直接使用 Bot 的会话。')),
|
|
155
|
+
h('button', { className: 'dim-deliveryButton', type: 'button', disabled: busy || loading, onClick: () => void refresh() }, '刷新')),
|
|
156
|
+
!status ? h('p', { className: 'dim-dsBotNotice', role: 'status' }, '正在检测 DS Bot…')
|
|
157
|
+
: status.state !== 'ready' ? h('p', { className: 'dim-dsBotNotice', role: 'status' }, DS_BOT_MESSAGES[status.state] ?? DS_BOT_MESSAGES.unavailable)
|
|
158
|
+
: !bots.length ? h('p', { className: 'dim-dsBotNotice' }, '还没有 DS Bot,请先在 DS Bot 中创建机器人后刷新。')
|
|
159
|
+
: !conversations.length ? h('p', { className: 'dim-dsBotNotice' }, '还没有可绑定的私聊。先给这个机器人发一条私聊消息,再点击刷新。')
|
|
160
|
+
: h('form', { className: 'dim-dsBotForm', onSubmit: save },
|
|
161
|
+
h('div', { className: 'dim-targetFormGrid' },
|
|
162
|
+
h('div', { className: 'dim-targetField' }, h('span', null, 'DS Bot'),
|
|
163
|
+
h(DsBotPicker, { bots: availableBots, value: dsBotId, onChange: setDsBotId, disabled: busy || loading })),
|
|
164
|
+
h('label', { className: 'dim-targetField' }, h('span', null, '私聊对象'),
|
|
165
|
+
h('select', {
|
|
166
|
+
value: conversationKey, required: true, disabled: busy || loading || !availableConversations.length,
|
|
167
|
+
onChange: (event) => setConversationKey(event.target.value),
|
|
168
|
+
}, h('option', { value: '' }, availableConversations.length ? '选择私聊对象' : '暂无可选私聊对象'),
|
|
169
|
+
availableConversations.map((conversation) => React.createElement('option', {
|
|
170
|
+
key: conversation.conversationKey, value: conversation.conversationKey,
|
|
171
|
+
}, conversationLabel(conversation)))))),
|
|
172
|
+
!availableBots.length || !availableConversations.length
|
|
173
|
+
? h('p', { className: 'dim-dsBotNotice' }, '已绑定的 DS Bot 和私聊对象不可重复选择,解除绑定后可重新选择。')
|
|
174
|
+
: null,
|
|
175
|
+
h('div', { className: 'dim-targetFormActions' },
|
|
176
|
+
h('button', { type: 'submit', className: 'dim-deliveryButton', 'data-kind': 'primary',
|
|
177
|
+
disabled: !canSave,
|
|
178
|
+
}, busy ? '正在保存…' : '保存绑定'))),
|
|
179
|
+
bindings.length ? h('ul', { className: 'dim-targetList' }, bindings.map((conversation) => {
|
|
180
|
+
const bot = bots.find((entry) => entry.id === conversation.dsBotId);
|
|
181
|
+
return h('li', { className: 'dim-targetRow dim-dsBotBinding', key: conversation.conversationKey },
|
|
182
|
+
h('div', { className: 'dim-dsBotBoundIdentity' },
|
|
183
|
+
h(DsBotAvatar, { bot: bot ?? { id: conversation.dsBotId }, size: 32 }),
|
|
184
|
+
h('div', { className: 'dim-targetSummary' },
|
|
185
|
+
h('div', { className: 'dim-targetTitle' },
|
|
186
|
+
bot ? React.createElement('strong', null, bot.name) : h('strong', null, 'DS Bot 暂不可用'),
|
|
187
|
+
h('span', null, '已绑定')),
|
|
188
|
+
React.createElement('p', { className: 'dim-dsBotDestination' }, conversationLabel(conversation)))),
|
|
189
|
+
h('button', { type: 'button', className: 'dim-deliveryButton', 'data-kind': 'danger', disabled: busy || loading,
|
|
190
|
+
onClick: () => void unbind(conversation.conversationKey),
|
|
191
|
+
}, '解除绑定'));
|
|
192
|
+
})) : null,
|
|
193
|
+
feedback ? h('p', { role: 'status', className: 'dim-targetFeedback', 'data-tone': feedbackTone }, feedback) : null);
|
|
194
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GroupHistorySettings } from './group-history-settings.js';
|
|
2
|
+
import { SidebarSettings } from './sidebar-settings.js';
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
|
|
4
5
|
import {
|
|
@@ -433,6 +434,6 @@ export function GlobalSettingsPanel({ rpcCall }) {
|
|
|
433
434
|
},
|
|
434
435
|
}, item.label)))),
|
|
435
436
|
tab === 'general' ? h('div', { id: 'dim-general-settings-panel-general', className: 'dim-generalSettingsTabPanel', role: 'tabpanel',
|
|
436
|
-
'aria-labelledby': 'dim-general-settings-tab-general' }, h(GroupHistorySettings, { rpcCall }))
|
|
437
|
+
'aria-labelledby': 'dim-general-settings-tab-general' }, h(SidebarSettings, { rpcCall }), h(GroupHistorySettings, { rpcCall }))
|
|
437
438
|
: h(AttachmentSettingsPanel, { rpcCall }));
|
|
438
439
|
}
|
|
@@ -6,10 +6,45 @@ import * as React from 'react';
|
|
|
6
6
|
export const IM_LOCALE_NAMESPACE = 'dsh-im';
|
|
7
7
|
|
|
8
8
|
const EN = Object.freeze({
|
|
9
|
+
"私聊对象": "Private chat",
|
|
10
|
+
"选择私聊对象": "Select a private chat",
|
|
11
|
+
"仅支持已经建立会话的私聊,请先与机器人私聊后刷新。": "Only established private chats are supported. Message the bot privately, then refresh.",
|
|
12
|
+
"选择 DS Bot 和私聊对象,直接使用 Bot 的会话。": "Choose a DS Bot and a private chat to use the Bot’s session.",
|
|
13
|
+
"还没有可绑定的私聊。先给这个机器人发一条私聊消息,再点击刷新。": "No private chats yet. Send this bot a private message, then refresh.",
|
|
14
|
+
|
|
15
|
+
"绑定bot": "Bind bot",
|
|
16
|
+
"正在检测 DS Bot…": "Checking DS Bot…",
|
|
17
|
+
"选择 DS Bot": "Select DS Bot",
|
|
18
|
+
"暂无可选 DS Bot": "No available DS Bots",
|
|
19
|
+
"暂无可选私聊对象": "No available private chats",
|
|
20
|
+
"已绑定的 DS Bot 和私聊对象不可重复选择,解除绑定后可重新选择。": "Bound DS Bots and private chats cannot be selected again. Unbind them to make them available.",
|
|
21
|
+
"所选 DS Bot 或私聊对象已绑定,请刷新后重新选择。": "The selected DS Bot or private chat is already bound. Refresh and choose again.",
|
|
22
|
+
"解除绑定": "Unbind",
|
|
23
|
+
"已绑定": "Bound",
|
|
24
|
+
"未安装 DS Bot,请先在 DSH 插件管理中安装 ds-bot,然后刷新。": "DS Bot is not installed. Install ds-bot in DSH plugin management, then refresh.",
|
|
25
|
+
"DS Bot 尚未启用,请在 DSH 插件管理中启用后刷新。": "DS Bot is disabled. Enable it in DSH plugin management, then refresh.",
|
|
26
|
+
"暂时无法读取 DS Bot,请检查插件是否正常运行后重试。": "Unable to read DS Bot. Check that the plugin is running, then retry.",
|
|
27
|
+
"DS Bot 当前由其他 Host 管理,请在运行它的 Host 中绑定。": "DS Bot is managed by another Host. Bind it on that Host.",
|
|
28
|
+
"绑定bot仅支持当前 Host 的会话,请先检查机器人的 Harness 连接设置。": "Bot binding requires the current Host. Check the bot’s Harness connection settings.",
|
|
29
|
+
"所选 DS Bot 已不存在,请刷新后重新选择。": "The selected DS Bot no longer exists. Refresh and select another.",
|
|
30
|
+
"绑定设置保存失败,请刷新后重试。": "Could not save the binding. Refresh and retry.",
|
|
31
|
+
"绑定已保存。": "Binding saved.",
|
|
32
|
+
"已解除绑定,聊天记录保留。": "Binding removed. Chat history is preserved.",
|
|
33
|
+
"还没有 DS Bot,请先在 DS Bot 中创建机器人后刷新。": "No bots yet. Create a bot in DS Bot, then refresh.",
|
|
34
|
+
"DS Bot 暂不可用": "DS Bot unavailable",
|
|
35
|
+
|
|
9
36
|
...weixinDiagnostics,
|
|
10
37
|
...diagnostics,
|
|
11
38
|
...imageInput,
|
|
12
39
|
'$locale': 'en',
|
|
40
|
+
'侧边栏入口': 'Sidebar entry',
|
|
41
|
+
'自动模式:未配置渠道时显示,配置至少一个渠道后隐藏。隐藏后仍可从插件详情或设置进入,不影响机器人后台运行。': 'Automatic: show before any channel is configured, then hide. Plugin details and Settings remain available; bots keep running in the background.',
|
|
42
|
+
'自动隐藏': 'Auto-hide',
|
|
43
|
+
'始终显示': 'Always show',
|
|
44
|
+
'始终隐藏': 'Always hide',
|
|
45
|
+
'正在读取侧边栏设置…': 'Loading sidebar settings…',
|
|
46
|
+
'无法读取或保存侧边栏设置,请稍后重试。': 'Unable to read or save sidebar settings. Try again.',
|
|
47
|
+
'侧边栏设置返回了无法识别的响应。': 'Unrecognized sidebar settings response.',
|
|
13
48
|
'保持本页打开,等待权限生效': 'Keep this page open while the permission takes effect',
|
|
14
49
|
"群聊天记录": "Group chat history",
|
|
15
50
|
"群聊天记录保留天数": "Group chat retention (days)",
|
|
@@ -59,7 +94,6 @@ const EN = Object.freeze({
|
|
|
59
94
|
'macOS Messages 权限': 'macOS Messages permissions',
|
|
60
95
|
'IM机器人': 'IM bots',
|
|
61
96
|
'打开 IM机器人': 'Open IM bots',
|
|
62
|
-
'返回插件详情': 'Back to plugin details',
|
|
63
97
|
'IM机器人设置': 'IM bot settings',
|
|
64
98
|
'IM 面板加载失败': 'Could not load the IM panel',
|
|
65
99
|
'更多机器人设置': 'More bot settings',
|
|
@@ -70,6 +104,38 @@ const EN = Object.freeze({
|
|
|
70
104
|
'机器人设置': 'Bot settings',
|
|
71
105
|
'机器人设置页签': 'Bot settings tabs',
|
|
72
106
|
'投递设置': 'Delivery settings',
|
|
107
|
+
'机器人群聊行为': 'Bot in groups',
|
|
108
|
+
'新群聊默认设置': 'Default for new groups',
|
|
109
|
+
'响应条件': 'React to',
|
|
110
|
+
'不响应': 'Do not react',
|
|
111
|
+
'被 @ 或回复时(任何人)': 'Mention or reply, anyone',
|
|
112
|
+
'被 @ 或回复时(仅名单成员)': 'Mention or reply, listed members only',
|
|
113
|
+
'所有消息(任何人)': 'All messages, anyone',
|
|
114
|
+
'所有消息(仅名单成员)': 'All messages, listed members only',
|
|
115
|
+
'成员名单': 'Members list',
|
|
116
|
+
'名单为空:该模式不会响应任何成员。': 'The list is empty, so nobody can trigger the bot in this mode.',
|
|
117
|
+
'当前模式不使用名单。': 'This mode does not use the list.',
|
|
118
|
+
'群 ID': 'Group',
|
|
119
|
+
'标题': 'Title',
|
|
120
|
+
'最近活动': 'Last activity',
|
|
121
|
+
'(默认)': ' (default)',
|
|
122
|
+
'× 移除': '× Remove',
|
|
123
|
+
'自定义': 'Customize',
|
|
124
|
+
'添加群聊': 'Add group',
|
|
125
|
+
'群 ID、@用户名或消息链接': 'Group ID, @username or message link',
|
|
126
|
+
'支持数字 ID、@用户名、t.me/<name> 或 t.me/c/<id>/<msg>;真实 ID 通过 getChat 解析。': 'Accepts a numeric ID, @username, t.me/<name> or t.me/c/<id>/<msg>; the real ID is resolved through getChat.',
|
|
127
|
+
'+ 添加': '+ Add',
|
|
128
|
+
'保存群聊设置': 'Save group settings',
|
|
129
|
+
'已从列表移除,保存后生效。': 'Removed from the list. Save to apply.',
|
|
130
|
+
'已添加,保存后生效。': 'Added. Save to apply.',
|
|
131
|
+
'已添加。Telegram 未确认该群(机器人可能还不在群里),保存后生效。': 'Added without Telegram confirmation (the bot may not be in that group yet). Save to apply.',
|
|
132
|
+
'群聊设置已保存。': 'Group settings saved.',
|
|
133
|
+
'正在读取群聊设置…': 'Loading group settings…',
|
|
134
|
+
'无法读取群聊设置,请稍后重试。': 'Unable to read group settings. Try again.',
|
|
135
|
+
'无法保存群聊设置,请稍后重试。': 'Unable to save group settings. Try again.',
|
|
136
|
+
'无法读取或保存群聊设置,请稍后重试。': 'Unable to read or save group settings. Try again.',
|
|
137
|
+
'无法解析该群聊,请重试或填写数字群 ID。': 'Could not resolve this group. Try again or enter the numeric group ID.',
|
|
138
|
+
'该群已在列表中,请编辑上方的卡片。': 'This group is already in the list. Edit its card above instead.',
|
|
73
139
|
'访问设置': 'Access settings',
|
|
74
140
|
'查看访问权限说明': 'View access permission details',
|
|
75
141
|
'允许所有用户': 'Allow all users',
|
|
@@ -80,10 +80,12 @@ import {
|
|
|
80
80
|
} from './loopback-recovery.js';
|
|
81
81
|
import { installImStyles } from './styles.js';
|
|
82
82
|
import { installSessionChannelLogos } from './session-channel-logos.js';
|
|
83
|
+
import { installDsBotSessionAvatars } from './ds-bot-session-avatars.js';
|
|
83
84
|
import { UpdatePanel, UPDATE_RPC_CHANNEL } from './update-panel.js';
|
|
84
85
|
import { WorkspaceDirectoryPickerContext } from './workspace-editor.js';
|
|
85
86
|
import { IMPanelErrorBoundary } from './panel-error-boundary.js';
|
|
86
87
|
import { installImPluginPage } from './plugin-page.js';
|
|
88
|
+
import { installSidebarVisibilitySync, SIDEBAR_SETTINGS_ENDPOINTS, SIDEBAR_SETTINGS_RPC_CHANNEL } from './sidebar-settings.js';
|
|
87
89
|
|
|
88
90
|
export const name = 'im-settings';
|
|
89
91
|
export const inject = ['slots', 'connection', 'locale', 'workspaces'];
|
|
@@ -469,6 +471,14 @@ export function apply(ctx) {
|
|
|
469
471
|
);
|
|
470
472
|
|
|
471
473
|
ctx.effect(() => installSessionChannelLogos(), 'im-settings: Session channel logos');
|
|
474
|
+
let dsBotAvatars;
|
|
475
|
+
ctx.effect(() => {
|
|
476
|
+
dsBotAvatars = installDsBotSessionAvatars(ctx, {
|
|
477
|
+
rpcCall: (endpoint, payload, signal) =>
|
|
478
|
+
callManagementRpc(ctx.connection, DELIVERY_RPC_CHANNEL, endpoint, payload, signal),
|
|
479
|
+
});
|
|
480
|
+
return () => { dsBotAvatars.dispose(); dsBotAvatars = null; };
|
|
481
|
+
}, 'im-settings: bound DS Bot session avatars');
|
|
472
482
|
|
|
473
483
|
ctx.effect(() => {
|
|
474
484
|
const disposers = [
|
|
@@ -492,40 +502,52 @@ export function apply(ctx) {
|
|
|
492
502
|
};
|
|
493
503
|
}, 'im-settings: install combined channel styles');
|
|
494
504
|
|
|
505
|
+
let sidebarSync;
|
|
506
|
+
const managementRpc = async (connection, channel, endpoint, payload, signal) => {
|
|
507
|
+
const result = await callManagementRpc(connection, channel, endpoint, payload, signal);
|
|
508
|
+
if (result?.ok === true) {
|
|
509
|
+
const dsBotRead = channel === DELIVERY_RPC_CHANNEL && endpoint === 'ds-bot.status';
|
|
510
|
+
if (channel === DELIVERY_RPC_CHANNEL && ['ds-bot.bind', 'ds-bot.unbind'].includes(endpoint)) dsBotAvatars?.refresh();
|
|
511
|
+
if (endpoint === SIDEBAR_SETTINGS_ENDPOINTS.set) sidebarSync?.apply(result);
|
|
512
|
+
else if (!dsBotRead && endpoint !== SIDEBAR_SETTINGS_ENDPOINTS.get) sidebarSync?.refresh();
|
|
513
|
+
}
|
|
514
|
+
return result;
|
|
515
|
+
};
|
|
495
516
|
const feishuRpcCall = (endpoint, payload, signal) =>
|
|
496
|
-
|
|
517
|
+
managementRpc(ctx.connection, FEISHU_RPC_CHANNEL, endpoint, payload, signal);
|
|
497
518
|
const weixinRpcCall = (endpoint, payload, signal) =>
|
|
498
|
-
|
|
519
|
+
managementRpc(ctx.connection, WEIXIN_RPC_CHANNEL, endpoint, payload, signal);
|
|
499
520
|
const dingtalkRpcCall = (endpoint, payload, signal) =>
|
|
500
|
-
|
|
521
|
+
managementRpc(ctx.connection, DINGTALK_RPC_CHANNEL, endpoint, payload, signal);
|
|
501
522
|
const qqRpcCall = (endpoint, payload, signal) =>
|
|
502
|
-
|
|
523
|
+
managementRpc(ctx.connection, QQ_RPC_CHANNEL, endpoint, payload, signal);
|
|
503
524
|
const wecomRpcCall = (endpoint, payload, signal) =>
|
|
504
|
-
|
|
525
|
+
managementRpc(ctx.connection, WECOM_RPC_CHANNEL, endpoint, payload, signal);
|
|
505
526
|
const wecomAppRpcCall = (endpoint, payload, signal) =>
|
|
506
|
-
|
|
527
|
+
managementRpc(ctx.connection, WECOM_APP_RPC_CHANNEL, endpoint, payload, signal);
|
|
507
528
|
const telegramRpcCall = (endpoint, payload, signal) =>
|
|
508
|
-
|
|
529
|
+
managementRpc(ctx.connection, TELEGRAM_RPC_CHANNEL, endpoint, payload, signal);
|
|
509
530
|
const discordRpcCall = (endpoint, payload, signal) =>
|
|
510
|
-
|
|
531
|
+
managementRpc(ctx.connection, DISCORD_RPC_CHANNEL, endpoint, payload, signal);
|
|
511
532
|
const whatsappRpcCall = (endpoint, payload, signal) =>
|
|
512
|
-
|
|
533
|
+
managementRpc(ctx.connection, WHATSAPP_RPC_CHANNEL, endpoint, payload, signal);
|
|
513
534
|
const imessageRpcCall = (endpoint, payload, signal) =>
|
|
514
|
-
|
|
535
|
+
managementRpc(ctx.connection, IMESSAGE_RPC_CHANNEL, endpoint, payload, signal);
|
|
515
536
|
const emailRpcCall = (endpoint, payload, signal) =>
|
|
516
|
-
|
|
537
|
+
managementRpc(ctx.connection, EMAIL_RPC_CHANNEL, endpoint, payload, signal);
|
|
517
538
|
const matrixRpcCall = (endpoint, payload, signal) =>
|
|
518
|
-
|
|
539
|
+
managementRpc(ctx.connection, MATRIX_RPC_CHANNEL, endpoint, payload, signal);
|
|
519
540
|
const slackRpcCall = (endpoint, payload, signal) =>
|
|
520
|
-
|
|
541
|
+
managementRpc(ctx.connection, SLACK_RPC_CHANNEL, endpoint, payload, signal);
|
|
521
542
|
const officeRpcCall = (endpoint, payload, signal) =>
|
|
522
|
-
|
|
543
|
+
managementRpc(ctx.connection, OFFICE_RPC_CHANNEL, endpoint, payload, signal);
|
|
523
544
|
const updateRpcCall = (endpoint, payload, signal) =>
|
|
524
|
-
|
|
545
|
+
managementRpc(ctx.connection, UPDATE_RPC_CHANNEL, endpoint, payload, signal);
|
|
525
546
|
const deliveryRpcCall = (endpoint, payload, signal) =>
|
|
526
|
-
|
|
547
|
+
managementRpc(ctx.connection, DELIVERY_RPC_CHANNEL, endpoint, payload, signal);
|
|
527
548
|
const globalSettingsRpcCall = (endpoint, payload, signal) =>
|
|
528
|
-
|
|
549
|
+
managementRpc(ctx.connection, Object.values(SIDEBAR_SETTINGS_ENDPOINTS).includes(endpoint)
|
|
550
|
+
? SIDEBAR_SETTINGS_RPC_CHANNEL : GLOBAL_SETTINGS_RPC_CHANNEL, endpoint, payload, signal);
|
|
529
551
|
const workspaceDirectoryPicker = Object.freeze({
|
|
530
552
|
listDirectory: (path, signal) =>
|
|
531
553
|
callWorkspaceDirectoryApi(ctx, 'listDirectory', path, signal),
|
|
@@ -567,11 +589,20 @@ export function apply(ctx) {
|
|
|
567
589
|
preferredSectionId: props.preferredSectionId,
|
|
568
590
|
});
|
|
569
591
|
|
|
570
|
-
installImPluginPage(ctx, {
|
|
592
|
+
const pluginPage = installImPluginPage(ctx, {
|
|
571
593
|
packageName: manifest.name,
|
|
572
594
|
renderPanel: buildPanelElement,
|
|
573
595
|
});
|
|
574
596
|
|
|
597
|
+
ctx.effect(() => {
|
|
598
|
+
sidebarSync = installSidebarVisibilitySync({
|
|
599
|
+
rpcCall: (endpoint, payload, signal) =>
|
|
600
|
+
callManagementRpc(ctx.connection, SIDEBAR_SETTINGS_RPC_CHANNEL, endpoint, payload, signal),
|
|
601
|
+
setVisible: (visible) => pluginPage.setSidebarVisible(visible),
|
|
602
|
+
});
|
|
603
|
+
return () => { sidebarSync.dispose(); sidebarSync = null; };
|
|
604
|
+
}, 'im-settings: sidebar visibility');
|
|
605
|
+
|
|
575
606
|
ctx.effect(() => {
|
|
576
607
|
let disposed = false;
|
|
577
608
|
let stopSettings = null;
|
|
@@ -13,11 +13,9 @@ function OpenImAction({ subject, packageName, onOpen, t }) {
|
|
|
13
13
|
}, t('打开 IM机器人'));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function ImPluginPage({ renderPanel
|
|
16
|
+
function ImPluginPage({ renderPanel }) {
|
|
17
17
|
return h('div', { className: 'dim-pluginPage' },
|
|
18
18
|
h('div', { className: 'dim-pluginPageContent' },
|
|
19
|
-
h('button', { type: 'button', className: 'dim-pluginBack', onClick: onBack },
|
|
20
|
-
h('span', { 'aria-hidden': true }, '‹'), t('返回插件详情')),
|
|
21
19
|
renderPanel()));
|
|
22
20
|
}
|
|
23
21
|
|
|
@@ -34,23 +32,45 @@ function ImSidebarIcon({ size }) {
|
|
|
34
32
|
|
|
35
33
|
// Optional services and slots keep the existing settings entry working on
|
|
36
34
|
// older DSH versions. Reuse the same panel through public navigation APIs.
|
|
37
|
-
export function installImPluginPage(ctx, { packageName, renderPanel }) {
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
export function installImPluginPage(ctx, { packageName, renderPanel, sidebarVisible = false }) {
|
|
36
|
+
// Wait for the Host's saved preference before adding a navigation row. An
|
|
37
|
+
// optimistic show would briefly shift the sidebar on every configured start.
|
|
38
|
+
let visible = sidebarVisible;
|
|
39
|
+
let updateSidebar = null;
|
|
40
|
+
const controller = {
|
|
41
|
+
setSidebarVisible(value) {
|
|
42
|
+
if (typeof value !== 'boolean') throw new TypeError('visible must be a boolean');
|
|
43
|
+
visible = value;
|
|
44
|
+
updateSidebar?.();
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
if (typeof ctx.inject !== 'function') return controller;
|
|
48
|
+
ctx.inject(['layout'], (pageCtx) =>
|
|
40
49
|
pageCtx.slots.inject('main', () => {
|
|
41
50
|
const unregisterPage = pageCtx.slots.register({
|
|
42
51
|
name: 'main', key: IM_MAIN_PANEL_ID, locale: IM_LOCALE_NAMESPACE,
|
|
43
|
-
inject: () => ({
|
|
44
|
-
renderPanel,
|
|
45
|
-
onBack: () => pageCtx.pluginNavigation.openBundle(packageName),
|
|
46
|
-
}),
|
|
52
|
+
inject: () => ({ renderPanel }),
|
|
47
53
|
}, ImPluginPage);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
let stopSidebar = null;
|
|
55
|
+
const update = () => {
|
|
56
|
+
if (visible === (stopSidebar !== null)) return;
|
|
57
|
+
if (!visible) {
|
|
58
|
+
const stop = stopSidebar;
|
|
59
|
+
stopSidebar = null;
|
|
60
|
+
stop();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Own the slot subscription, including late declarations, so toggling
|
|
64
|
+
// cannot leave a pending registration or add a duplicate entry.
|
|
65
|
+
stopSidebar = pageCtx.slots.inject('sidebar.panellist', () =>
|
|
66
|
+
pageCtx.slots.register({
|
|
67
|
+
name: 'sidebar.panellist', id: IM_MAIN_PANEL_ID,
|
|
68
|
+
order: 10, label: () => pageCtx.locale.bind(IM_LOCALE_NAMESPACE)('IM机器人'),
|
|
69
|
+
locale: IM_LOCALE_NAMESPACE,
|
|
70
|
+
}, ImSidebarIcon));
|
|
71
|
+
};
|
|
72
|
+
updateSidebar = update;
|
|
73
|
+
update();
|
|
54
74
|
const stopActions = pageCtx.slots.inject('plugins.detail.actions', () =>
|
|
55
75
|
pageCtx.slots.register({
|
|
56
76
|
name: 'plugins.detail.actions', id: 'xmanrui-dsh-im-open',
|
|
@@ -62,8 +82,10 @@ export function installImPluginPage(ctx, { packageName, renderPanel }) {
|
|
|
62
82
|
}, OpenImAction));
|
|
63
83
|
return () => {
|
|
64
84
|
stopActions();
|
|
65
|
-
|
|
85
|
+
updateSidebar = null;
|
|
86
|
+
stopSidebar?.();
|
|
66
87
|
unregisterPage();
|
|
67
88
|
};
|
|
68
89
|
}));
|
|
90
|
+
return controller;
|
|
69
91
|
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { h } from './i18n.js';
|
|
3
|
+
|
|
4
|
+
export const SIDEBAR_SETTINGS_RPC_CHANNEL = '/dsh-im-sidebar';
|
|
5
|
+
export const SIDEBAR_SETTINGS_ENDPOINTS = Object.freeze({
|
|
6
|
+
get: 'settings.sidebar-entry.get', set: 'settings.sidebar-entry.set',
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
function settingsResult(result) {
|
|
10
|
+
if (result?.ok === false) throw new Error(result.error?.message || '无法读取或保存侧边栏设置,请稍后重试。');
|
|
11
|
+
const value = result?.ok === true ? result.value : result;
|
|
12
|
+
if (!['auto', 'show', 'hide'].includes(value?.mode) || typeof value.visible !== 'boolean') {
|
|
13
|
+
throw new Error('侧边栏设置返回了无法识别的响应。');
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** One small Host read at startup and after management calls. A slow fallback
|
|
19
|
+
* observes changes made by another client without mounting a management panel. */
|
|
20
|
+
export function installSidebarVisibilitySync({ rpcCall, setVisible,
|
|
21
|
+
setTimeoutFn = globalThis.setTimeout, clearTimeoutFn = globalThis.clearTimeout,
|
|
22
|
+
pollMs = 30_000,
|
|
23
|
+
}) {
|
|
24
|
+
const abort = new AbortController();
|
|
25
|
+
let timer;
|
|
26
|
+
let running = false;
|
|
27
|
+
let pending = false;
|
|
28
|
+
let revision = 0;
|
|
29
|
+
const schedule = (delay) => {
|
|
30
|
+
clearTimeoutFn(timer);
|
|
31
|
+
if (!abort.signal.aborted) timer = setTimeoutFn(refresh, delay);
|
|
32
|
+
};
|
|
33
|
+
const refresh = async () => {
|
|
34
|
+
if (abort.signal.aborted) return;
|
|
35
|
+
if (running) { pending = true; return; }
|
|
36
|
+
running = true;
|
|
37
|
+
pending = false;
|
|
38
|
+
const current = revision;
|
|
39
|
+
try {
|
|
40
|
+
const value = settingsResult(await rpcCall(SIDEBAR_SETTINGS_ENDPOINTS.get, {}, abort.signal));
|
|
41
|
+
if (!abort.signal.aborted && current === revision && !pending) setVisible(value.visible);
|
|
42
|
+
} catch {
|
|
43
|
+
// Retain the last confirmed visibility (initially hidden) on failure.
|
|
44
|
+
// Settings and plugin details remain available independently.
|
|
45
|
+
} finally {
|
|
46
|
+
running = false;
|
|
47
|
+
schedule(pending ? 0 : pollMs);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
void refresh();
|
|
51
|
+
return {
|
|
52
|
+
refresh() {
|
|
53
|
+
revision++;
|
|
54
|
+
if (running) pending = true;
|
|
55
|
+
else schedule(0);
|
|
56
|
+
},
|
|
57
|
+
apply(value) {
|
|
58
|
+
revision++;
|
|
59
|
+
if (!abort.signal.aborted) setVisible(settingsResult(value).visible);
|
|
60
|
+
},
|
|
61
|
+
dispose() { abort.abort(); clearTimeoutFn(timer); },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function SidebarSettings({ rpcCall }) {
|
|
66
|
+
const [mode, setMode] = React.useState('auto');
|
|
67
|
+
const [phase, setPhase] = React.useState('loading');
|
|
68
|
+
const [error, setError] = React.useState(null);
|
|
69
|
+
const [saved, setSaved] = React.useState(false);
|
|
70
|
+
const mounted = React.useRef(false);
|
|
71
|
+
const busy = React.useRef(false);
|
|
72
|
+
const failedMode = React.useRef(null);
|
|
73
|
+
const id = React.useId();
|
|
74
|
+
const disabled = phase === 'loading' || phase === 'saving';
|
|
75
|
+
const load = React.useCallback(async (signal) => {
|
|
76
|
+
setPhase('loading'); setError(null); setSaved(false);
|
|
77
|
+
failedMode.current = null;
|
|
78
|
+
try {
|
|
79
|
+
const value = settingsResult(await rpcCall(SIDEBAR_SETTINGS_ENDPOINTS.get, {}, signal));
|
|
80
|
+
if (signal?.aborted || !mounted.current) return;
|
|
81
|
+
setMode(value.mode); setPhase('ready');
|
|
82
|
+
} catch (caught) {
|
|
83
|
+
if (signal?.aborted || !mounted.current) return;
|
|
84
|
+
setError(caught.message); setPhase('error');
|
|
85
|
+
}
|
|
86
|
+
}, [rpcCall]);
|
|
87
|
+
React.useEffect(() => {
|
|
88
|
+
mounted.current = true;
|
|
89
|
+
const abort = new AbortController();
|
|
90
|
+
void load(abort.signal);
|
|
91
|
+
return () => { mounted.current = false; abort.abort(); };
|
|
92
|
+
}, [load]);
|
|
93
|
+
const save = async (nextMode) => {
|
|
94
|
+
if (busy.current || disabled) return;
|
|
95
|
+
const previousMode = mode;
|
|
96
|
+
busy.current = true; setPhase('saving'); setError(null); setSaved(false);
|
|
97
|
+
setMode(nextMode);
|
|
98
|
+
failedMode.current = null;
|
|
99
|
+
try {
|
|
100
|
+
const value = settingsResult(await rpcCall(SIDEBAR_SETTINGS_ENDPOINTS.set, { mode: nextMode }));
|
|
101
|
+
if (mounted.current) { setMode(value.mode); setSaved(true); setPhase('ready'); }
|
|
102
|
+
} catch (caught) {
|
|
103
|
+
if (mounted.current) {
|
|
104
|
+
failedMode.current = nextMode;
|
|
105
|
+
setMode(previousMode); setError(caught.message); setPhase('error');
|
|
106
|
+
}
|
|
107
|
+
} finally { busy.current = false; }
|
|
108
|
+
};
|
|
109
|
+
return h('section', { className: 'dim-botGeneralSettings dim-sidebarSettings', 'aria-label': '侧边栏入口', 'aria-busy': disabled },
|
|
110
|
+
h('div', { className: 'dim-botGeneralRow' },
|
|
111
|
+
h('div', { className: 'dim-botGeneralText' },
|
|
112
|
+
h('div', { className: 'dim-sidebarHeading' },
|
|
113
|
+
h('label', { className: 'dim-botGeneralTitle', htmlFor: id }, '侧边栏入口'),
|
|
114
|
+
h('span', { role: 'status', className: 'dim-botGeneralHelp' },
|
|
115
|
+
phase === 'loading' ? '正在读取侧边栏设置…' : phase === 'saving' ? '保存中…' : saved ? '已保存' : '')),
|
|
116
|
+
h('p', { className: 'dim-botGeneralHelp', id: `${id}-help` }, '自动模式:未配置渠道时显示,配置至少一个渠道后隐藏。隐藏后仍可从插件详情或设置进入,不影响机器人后台运行。')),
|
|
117
|
+
h('div', { className: 'dim-botGeneralControl' },
|
|
118
|
+
h('select', { id, className: 'dim-sidebarSelect', value: mode, disabled, 'aria-describedby': `${id}-help`,
|
|
119
|
+
onChange: (event) => save(event.target.value) },
|
|
120
|
+
h('option', { value: 'auto' }, '自动隐藏'),
|
|
121
|
+
h('option', { value: 'show' }, '始终显示'),
|
|
122
|
+
h('option', { value: 'hide' }, '始终隐藏')),
|
|
123
|
+
h('svg', { width: 16, height: 16, viewBox: '0 0 16 16', 'aria-hidden': true },
|
|
124
|
+
h('path', { d: 'm4 6 4 4 4-4', fill: 'none', stroke: 'currentColor', strokeWidth: 1.5 })))),
|
|
125
|
+
error ? h('div', { className: 'dim-sidebarFeedback' },
|
|
126
|
+
h('p', { role: 'alert', className: 'dim-accessFeedback', 'data-tone': 'error' }, error),
|
|
127
|
+
h('button', { type: 'button', className: 'dim-deliveryButton',
|
|
128
|
+
onClick: () => failedMode.current === null ? load() : save(failedMode.current) }, '重试')) : null);
|
|
129
|
+
}
|