dsh-postbox 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +524 -2
- package/client.js +2717 -0
- package/cordis.patch.yml +83 -0
- package/docs/DETAIL.md +50 -0
- package/icon.svg +1 -0
- package/index.js +2312 -0
- package/lib/backend-sqlite.js +65 -0
- package/lib/bridge.js +940 -0
- package/lib/config.js +289 -0
- package/lib/digest.js +213 -0
- package/lib/errors.js +83 -0
- package/lib/ft.js +211 -0
- package/lib/host-settings.js +237 -0
- package/lib/imap.js +635 -0
- package/lib/importance.js +83 -0
- package/lib/llm.js +411 -0
- package/lib/log.js +75 -0
- package/lib/mime.js +381 -0
- package/lib/mutf7.js +54 -0
- package/lib/notify.js +328 -0
- package/lib/oauth.js +275 -0
- package/lib/schema.js +177 -0
- package/lib/search.js +129 -0
- package/lib/settings.js +395 -0
- package/lib/smtp.js +153 -0
- package/lib/store.js +1068 -0
- package/lib/sync.js +899 -0
- package/lib/tool.js +232 -0
- package/lib/tools-m4.js +863 -0
- package/lib/update.js +642 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +60 -4
package/client.js
ADDED
|
@@ -0,0 +1,2717 @@
|
|
|
1
|
+
// dsh-postbox — 浏览器半边(host 是 index.js)。
|
|
2
|
+
//
|
|
3
|
+
// 形态由 DSH 0.2.0-rc.2 的客户端模块系统决定(内部复核记录 §2.2,不随包发布):
|
|
4
|
+
// · 产物必须是**闭包工厂**:`window.__ModuleLoader__.load({ id, factory })`,
|
|
5
|
+
// factory 返回本插件的模块导出(`{ inject, apply }`)。**不是**普通 ESM 模块。
|
|
6
|
+
// · 依赖只能用 `require()` 从外壳**冻结平台表**取(实测 9 个种子:react / react/jsx-runtime /
|
|
7
|
+
// react-dom / react-dom/client / @deepseek-ai/cordis / dsh-client-store / dsh-client-ui-slots /
|
|
8
|
+
// dsh-client-ui-primitives / dsh-client-ui-dockkit)。因此**不需要打包机**:
|
|
9
|
+
// 只用 `React.createElement`(不写 JSX),文件本身就是可加载产物。
|
|
10
|
+
// · `package.json` 声明 `exports["./client"]` + `dsh.client { platform:"web" }`,缺一不可。
|
|
11
|
+
//
|
|
12
|
+
// 挂载点:`plugins.row.config`(键 `<包名>#<行 id>`)—— 设置 → 插件 → dsh-postbox 那一行的
|
|
13
|
+
// 「配置」控件。只在宿主**服务 `mailbox` 命名空间**期间注册(`configForms.whileServed`)。
|
|
14
|
+
//
|
|
15
|
+
// ── 真机三轮踩过的坑(都留在这里,别再踩)──────────────────────────────────────────
|
|
16
|
+
// ① **表单值的键是 volatile 节点名 `runtime`**,不是命名空间 `mailbox`。
|
|
17
|
+
// 首版用 SETTINGS_NAMESPACE 索引 `state.value` ⇒ 字段全空。
|
|
18
|
+
// ② **页面给的 `form.state` 可能是挂载时的快照**(实测保存失败后 revision 仍显示 0)
|
|
19
|
+
// ⇒ 不能拿它当 revision 来源。改为**自己调 `remote.settings.describe()`** 取权威 revision;
|
|
20
|
+
// `remote.settings` 对任意客户端插件可用(dsh-client-ui-settings 注释:"every caller declare
|
|
21
|
+
// `remote.settings` in its own inject")。
|
|
22
|
+
// ③ **乐观并发失败只返回 true/false,不给原因** ⇒ 直连 RPC 还拿到 `{ok:false,code,error}`,
|
|
23
|
+
// 卡片把 code/message 显示出来,不再靠猜("宿主仍在并发修改"就是这么来的)。
|
|
24
|
+
// ④ 字段表要覆盖 volatile 节点的**全部叶子**;通知方式(notify.channel)是用户明确要的项。
|
|
25
|
+
|
|
26
|
+
(function bootstrap() {
|
|
27
|
+
const ID = "dsh-postbox";
|
|
28
|
+
const NS = "settings.mailbox";
|
|
29
|
+
/** 宿主服务这个命名空间 = cordis.patch.yml 里 `id: mailbox`(浏览器包不能 import host 包)。 */
|
|
30
|
+
const SETTINGS_NAMESPACE = "mailbox";
|
|
31
|
+
/** ⚠️ `Config` 里那个 volatile 节点的名字 —— 表单值与写入路径的第一段都是它。 */
|
|
32
|
+
const VOLATILE_KEY = "runtime";
|
|
33
|
+
/** `plugins.row.config` 的键 = `<包名>#<行 id>`。 */
|
|
34
|
+
const ROW_KEY = `${ID}#${SETTINGS_NAMESPACE}`;
|
|
35
|
+
|
|
36
|
+
const DICT = {
|
|
37
|
+
zh: {
|
|
38
|
+
summary: "个人邮箱运行时设置", save: "保存", revert: "撤销改动", refresh: "重新读取",
|
|
39
|
+
saved: "已保存(免重启)", retried: "已自动重试并保存", conflict: "宿主拒绝了这次写入",
|
|
40
|
+
noread: "当前部署不提供可编辑设置", readonlyRemote: "该页面不持久化设置(远程 Web 只读)",
|
|
41
|
+
nochange: "没有改动", state: "原始状态", reload: "刷新",
|
|
42
|
+
group_notify: "通知", group_watcher: "轮询", group_archive: "归档与保留",
|
|
43
|
+
hint_channel: "auto=有 IM 就走 IM;im=必须走 IM(没目标时只留痕并提示);local=只在 DSH 内留痕",
|
|
44
|
+
hint_mode: "online / metadata 模式下搜不了正文(M5 耦合)",
|
|
45
|
+
hint_bot: "留空 = 自动发现;先用 mailbox_notify(action=\"targets\") 看候选",
|
|
46
|
+
hint_botid: "留空 = 自动发现;或从下拉选(下拉来自 dsh-im 的真实列表)",
|
|
47
|
+
hint_targetid: "留空 = 自动发现;或从下拉选;目标需在 dsh-im 的「投递设置 → 新建目标」里创建",
|
|
48
|
+
hint_list: "多个值用逗号分隔", hint_quiet: "如 23:00-08:00;留空 = 不静音",
|
|
49
|
+
bar_title: "邮箱", bar_check: "立刻检查", bar_checking: "检查中…", bar_close: "关闭",
|
|
50
|
+
bar_none: "还没有归档的邮件", bar_unread: "封未读", bar_total: "共",
|
|
51
|
+
// M6.6:对话框上方的邮件提示栏(conversation.input.dock)
|
|
52
|
+
dock_title: "邮箱", dock_all: "全部", dock_expand: "展开", dock_collapse: "收起",
|
|
53
|
+
dock_insert: "点击把邮件坐标插进输入框", dock_inserted: "已插进输入框", dock_copied: "已复制坐标(请粘贴到输入框)",
|
|
54
|
+
dock_failed: "插入失败,请手动复制坐标", dock_empty: "这个邮箱还没有归档邮件",
|
|
55
|
+
dock_scope: "范围", dock_last_check: "Last Check", dock_never: "还没跑过第一轮",
|
|
56
|
+
dock_check_title: "立刻同步邮箱:真的去连服务器抓一轮(不是刷新显示)",
|
|
57
|
+
dock_checked: "已同步", dock_checked_none: "已同步:没有新邮件",
|
|
58
|
+
dock_check_failed: "同步失败:",
|
|
59
|
+
// 账号管理
|
|
60
|
+
label_account_email: "邮箱地址", label_account_alias: "别名", label_account_imap_host: "IMAP 主机",
|
|
61
|
+
label_account_imap_port: "IMAP 端口", label_account_smtp_host: "SMTP 主机",
|
|
62
|
+
label_account_smtp_port: "SMTP 端口", label_account_default_folder: "默认文件夹",
|
|
63
|
+
placeholder_email: "yourname@outlook.com", placeholder_alias: "主邮箱",
|
|
64
|
+
hint_account_email: "Outlook/Hotmail 等 Microsoft 个人邮箱",
|
|
65
|
+
hint_account_alias: "工具中用来指代这个账号,留空则用邮箱地址",
|
|
66
|
+
hint_account_imap: "默认 outlook.office365.com:993",
|
|
67
|
+
hint_account_smtp: "默认 smtp-mail.outlook.com:587",
|
|
68
|
+
hint_account_folder: "默认 INBOX",
|
|
69
|
+
btn_add_account: "添加账号", btn_auth: "认证", btn_delete: "删除", btn_refresh_accounts: "刷新账号列表",
|
|
70
|
+
account_col_email: "邮箱", account_col_alias: "别名", account_col_status: "授权状态",
|
|
71
|
+
account_col_action: "操作", account_authorized: "已授权", account_unauthorized: "未授权",
|
|
72
|
+
account_no_accounts: "暂无账号。先在下方填写邮箱地址,点「添加账号」,再点「认证」完成 OAuth2 授权。",
|
|
73
|
+
account_adding: "添加中...", account_auth_started: "设备码流已启动:打开验证链接,输入验码,完成后点「完成认证」",
|
|
74
|
+
account_auth_done: "授权成功,token 已保存。下一轮轮询即可抓取该账号邮件。",
|
|
75
|
+
account_auth_failed: "认证失败:",
|
|
76
|
+
account_add_failed: "添加账号失败:",
|
|
77
|
+
account_delete_failed: "删除账号失败:",
|
|
78
|
+
account_fetch_failed: "获取账号列表失败:",
|
|
79
|
+
account_confirm_delete: "确定要删除账号",
|
|
80
|
+
btn_resync_hint: "重置水位并回填该账户监控文件夹的全部历史邮件(≤重置时刻的邮件只入库不通知)",
|
|
81
|
+
account_confirm_resync: "回填该账户监控文件夹的全部历史邮件?(下一轮轮询开始,分多轮补完)",
|
|
82
|
+
account_resync_done: "已重置水位,下一轮起回填历史(≤重置时刻水位的邮件只入库不通知)…",
|
|
83
|
+
account_resync_failed: "重置水位失败:",
|
|
84
|
+
account_source_runtime: "运行时层(可在此增删)",
|
|
85
|
+
account_source_deploy: "部署层(改 cordis.patch.yml + 重启)",
|
|
86
|
+
account_delete_deploy_hint: "该账号来自 cordis.patch.yml(部署层),配置页删不掉;请改文件里的 accounts 后重启 DSH。",
|
|
87
|
+
account_added: "已保存(免重启),请点「认证」完成 OAuth2 授权(微软设备码流,无需密码)。",
|
|
88
|
+
account_advanced_toggle: "高级选项:IMAP/SMTP 端点(一般保持默认)",
|
|
89
|
+
account_advanced_hint: "授权始终走微软 OAuth2 设备码流(Thunderbird 公共 Client ID,免注册、无需密码);下面的端点只对 Outlook/Hotmail 等 Microsoft 个人邮箱有效,非 Microsoft 邮箱不支持。",
|
|
90
|
+
},
|
|
91
|
+
en: {
|
|
92
|
+
summary: "Mailbox runtime settings", save: "Save", revert: "Revert", refresh: "Reload",
|
|
93
|
+
saved: "Saved (no restart)", retried: "Saved after automatic retry", conflict: "Host refused the write",
|
|
94
|
+
noread: "This deployment serves no editable settings", readonlyRemote: "Settings are not persisted here (remote Web is read-only)",
|
|
95
|
+
nochange: "No changes", state: "raw state", reload: "reload",
|
|
96
|
+
group_notify: "Notifications", group_watcher: "Polling", group_archive: "Archive & retention",
|
|
97
|
+
hint_channel: "auto = IM when available; im = IM only; local = in-app record only",
|
|
98
|
+
hint_mode: "online / metadata cannot full-text search bodies (M5)",
|
|
99
|
+
hint_bot: "empty = auto-discover; list candidates with mailbox_notify(action=\"targets\")",
|
|
100
|
+
hint_botid: "empty = auto-discover; or pick from the dropdown (loaded from dsh-im)",
|
|
101
|
+
hint_targetid: "empty = auto-discover; or pick from the dropdown; create targets in dsh-im's Delivery settings → New target",
|
|
102
|
+
hint_list: "comma separated", hint_quiet: "e.g. 23:00-08:00; empty = no quiet hours",
|
|
103
|
+
bar_title: "Mailbox", bar_check: "Check now", bar_checking: "Checking…", bar_close: "Close",
|
|
104
|
+
bar_none: "No archived mail yet", bar_unread: "unread", bar_total: "total",
|
|
105
|
+
// M6.6:mail info bar above the composer (conversation.input.dock)
|
|
106
|
+
dock_title: "Mailbox", dock_all: "All", dock_expand: "Expand", dock_collapse: "Collapse",
|
|
107
|
+
dock_insert: "Click to insert the mail coordinate into the composer", dock_inserted: "Inserted into the composer",
|
|
108
|
+
dock_copied: "Coordinate copied (paste it into the composer)", dock_failed: "Insert failed — copy the coordinate manually",
|
|
109
|
+
dock_empty: "No archived mail for this account",
|
|
110
|
+
dock_scope: "Scope", dock_last_check: "Last Check", dock_never: "never ran yet",
|
|
111
|
+
dock_check_title: "Sync now: really connects to the servers for a full round",
|
|
112
|
+
dock_checked: "Synced", dock_checked_none: "Synced: no new mail",
|
|
113
|
+
dock_check_failed: "Sync failed:",
|
|
114
|
+
// Account management
|
|
115
|
+
label_account_email: "Email", label_account_alias: "Alias", label_account_imap_host: "IMAP Host",
|
|
116
|
+
label_account_imap_port: "IMAP Port", label_account_smtp_host: "SMTP Host",
|
|
117
|
+
label_account_smtp_port: "SMTP Port", label_account_default_folder: "Default Folder",
|
|
118
|
+
placeholder_email: "yourname@outlook.com", placeholder_alias: "Main mailbox",
|
|
119
|
+
hint_account_email: "Outlook/Hotmail or other Microsoft personal mailbox",
|
|
120
|
+
hint_account_alias: "Alias used by tools to refer to this account; leave empty to use email",
|
|
121
|
+
hint_account_imap: "Default outlook.office365.com:993",
|
|
122
|
+
hint_account_smtp: "Default smtp-mail.outlook.com:587",
|
|
123
|
+
hint_account_folder: "Default INBOX",
|
|
124
|
+
btn_add_account: "Add Account", btn_auth: "Auth", btn_delete: "Delete", btn_refresh_accounts: "Refresh accounts",
|
|
125
|
+
account_col_email: "Email", account_col_alias: "Alias", account_col_status: "Auth status",
|
|
126
|
+
account_col_action: "Action", account_authorized: "Authorized", account_unauthorized: "Not authorized",
|
|
127
|
+
account_no_accounts: "No accounts yet. Fill in an email below, click \"Add Account\", then click \"Auth\" to complete OAuth2.",
|
|
128
|
+
account_adding: "Adding...", account_auth_started: "Device code flow started: open the verification link, enter the code, then click \"Complete Auth\"",
|
|
129
|
+
account_auth_done: "Authorization succeeded, token saved. Next poll will fetch this account's mail.",
|
|
130
|
+
account_auth_failed: "Auth failed:",
|
|
131
|
+
account_add_failed: "Add account failed:",
|
|
132
|
+
account_delete_failed: "Delete account failed:",
|
|
133
|
+
account_fetch_failed: "Fetch account list failed:",
|
|
134
|
+
account_confirm_delete: "Delete account",
|
|
135
|
+
account_source_runtime: "Runtime (add/remove here)",
|
|
136
|
+
account_source_deploy: "Deployed (edit cordis.patch.yml + restart)",
|
|
137
|
+
account_delete_deploy_hint: "This account comes from cordis.patch.yml (deploy layer) and cannot be deleted here; edit accounts there and restart DSH.",
|
|
138
|
+
account_added: "Saved (no restart). Click \"Auth\" to finish OAuth2 (Microsoft device-code flow, no password).",
|
|
139
|
+
account_advanced_toggle: "Advanced: IMAP/SMTP endpoints (defaults usually fine)",
|
|
140
|
+
account_advanced_hint: "Authorization always uses the Microsoft OAuth2 device-code flow (Thunderbird public Client ID, no registration, no password). The endpoints below only apply to Microsoft personal mail (Outlook/Hotmail); non-Microsoft IMAP accounts are not supported.",
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/** 字段全集 = volatile 节点的全部叶子(与 host 的 SETTINGS_FIELDS 一一对应;有测试断言两者相等)。
|
|
145
|
+
* 路径相对 volatile 节点 ⇒ 写入路径 = `[VOLATILE_KEY, ...path]`。 */
|
|
146
|
+
const GROUPS = [
|
|
147
|
+
{
|
|
148
|
+
id: "notify", fields: [
|
|
149
|
+
{ path: ["notify", "enabled"], label: "通知开关", type: "bool" },
|
|
150
|
+
{ path: ["notify", "channel"], label: "通知方式", type: "enum", options: ["auto", "im", "local"], hintKey: "hint_channel" },
|
|
151
|
+
{ path: ["notify", "importanceThreshold"], label: "重要度阈值(0-100;0=全部即时推)", type: "int", min: 0, max: 100 },
|
|
152
|
+
{ path: ["notify", "batch"], label: "单批合并条数", type: "int", min: 1, max: 50 },
|
|
153
|
+
{ path: ["notify", "includeCodes"], label: "推送里显示验证码", type: "bool" },
|
|
154
|
+
{ path: ["notify", "botId"], label: "投递机器人", type: "str", hintKey: "hint_botid" },
|
|
155
|
+
{ path: ["notify", "targetId"], label: "投递目标", type: "str", hintKey: "hint_targetid" },
|
|
156
|
+
{ path: ["notify", "dailyDigest", "enabled"], label: "每日汇总开关", type: "bool" },
|
|
157
|
+
{ path: ["notify", "dailyDigest", "at"], label: "每日汇总时间(HH:MM)", type: "str" },
|
|
158
|
+
{ path: ["notify", "quietHours"], label: "静音时段", type: "str", hintKey: "hint_quiet" },
|
|
159
|
+
{ path: ["notify", "filter", "skip"], label: "跳过关键词", type: "list", hintKey: "hint_list" },
|
|
160
|
+
{ path: ["notify", "filter", "only"], label: "只看关键词", type: "list", hintKey: "hint_list" },
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: "watcher", fields: [
|
|
165
|
+
{ path: ["watcher", "enabled"], label: "watcher 开关", type: "bool" },
|
|
166
|
+
{ path: ["watcher", "pollIntervalSeconds"], label: "轮询间隔(秒)", type: "int", min: 5 },
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
id: "archive", fields: [
|
|
171
|
+
{ path: ["archive", "mode"], label: "归档模式", type: "enum", options: ["online", "metadata", "full"], hintKey: "hint_mode" },
|
|
172
|
+
{ path: ["archive", "snippet"], label: "抓正文抽摘要(snippet)", type: "bool" },
|
|
173
|
+
{ path: ["archive", "retentionDays"], label: "原文保留天数(0=不修剪)", type: "int", min: 0 },
|
|
174
|
+
{ path: ["archive", "maxBytes"], label: "原文大小上限(字节,0=不限)", type: "int", min: 0 },
|
|
175
|
+
{ path: ["archive", "maintenanceDays"], label: "元数据维护天数(0=不清)", type: "int", min: 0 },
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
// 2026-11-30:用户要「按自己习惯调配」。这两项以前藏在 cordis.patch.yml 顶层,
|
|
180
|
+
// 现在走运行层,改了下一轮/下一次调用就生效(不用重启)。
|
|
181
|
+
id: "mail", fields: [
|
|
182
|
+
{ path: ["mail", "bodyLimit"], label: "正文截断字符数(默认 4000)", type: "int", min: 200, max: 20000 },
|
|
183
|
+
{ path: ["mail", "attachMaxBytes"], label: "附件落盘上限(字节,0=不限)", type: "int", min: 0 },
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
];
|
|
187
|
+
const FIELDS = GROUPS.flatMap((group) => group.fields);
|
|
188
|
+
const keyOf = (field) => field.path.join(".");
|
|
189
|
+
const getIn = (obj, path) => path.reduce((node, key) => (node === null || node === undefined ? undefined : node[key]), obj);
|
|
190
|
+
|
|
191
|
+
/** 表单值 → runtime 子树(首选 volatile 节点名;命名空间键只作兜底)。 */
|
|
192
|
+
function resolveRuntimeSection(stateValue) {
|
|
193
|
+
const root = stateValue && typeof stateValue === "object" ? stateValue : {};
|
|
194
|
+
const section = root[VOLATILE_KEY] ?? root[SETTINGS_NAMESPACE];
|
|
195
|
+
return section && typeof section === "object" ? section : {};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** 候选 → 下拉选项(**纯函数**,便于离线断言)。
|
|
199
|
+
* 机器人列表来自 dsh-im 的 `listBots`,目标列表来自 `listTargets`;两者**独立** ——
|
|
200
|
+
* 有机器人但还没建投递目标时,机器人依然必须可选(否则界面上看不出"已经拿到机器人")。 */
|
|
201
|
+
function candidateOptions(cand, currentBot) {
|
|
202
|
+
const bots = Array.isArray(cand?.bots) ? cand.bots : [];
|
|
203
|
+
const targets = Array.isArray(cand?.targets) ? cand.targets : [];
|
|
204
|
+
const ids = bots.length ? bots.map((b) => b.botId) : [...new Set(targets.map((t) => t.botId))];
|
|
205
|
+
const labelOf = (id) => {
|
|
206
|
+
const b = bots.find((x) => x.botId === id);
|
|
207
|
+
if (!b) return id;
|
|
208
|
+
const user = b.username ? ` (@${String(b.username).replace(/^@/, "")})` : "";
|
|
209
|
+
return `${id}${b.name ? ` · ${b.name}` : ""}${user}`;
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
botOptions: ids.filter(Boolean).map((id) => ({ value: id, label: labelOf(id) })),
|
|
213
|
+
targetOptions: targets.filter((t) => !currentBot || t.botId === currentBot),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Telegram bot token 形状:`<数字>:<35 位左右>`。
|
|
218
|
+
* 实测有人把 token 粘进 botId(2026-10-16)—— 卡片必须当场点出来,而不是等他去猜为什么没提醒。 */
|
|
219
|
+
function looksLikeTelegramToken(value) {
|
|
220
|
+
return /^\d{6,}:[A-Za-z0-9_-]{20,}$/.test(String(value ?? "").trim());
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** 相对时间:**只用于"上次成功同步"这类粗粒度提示**,精确到分钟足够。
|
|
224
|
+
* 配置卡里的状态卡用它显示"3 分钟前",避免用户对着时间戳做减法。 */
|
|
225
|
+
function agoText(ts, now = Date.now()) {
|
|
226
|
+
const n = Number(ts);
|
|
227
|
+
if (!Number.isFinite(n) || n <= 0) return "从未";
|
|
228
|
+
const sec = Math.max(0, Math.round((Number(now) - n) / 1000));
|
|
229
|
+
if (sec < 60) return "刚刚";
|
|
230
|
+
const min = Math.round(sec / 60);
|
|
231
|
+
if (min < 60) return `${min} 分钟前`;
|
|
232
|
+
const hr = Math.round(min / 60);
|
|
233
|
+
if (hr < 24) return `${hr} 小时前`;
|
|
234
|
+
return `${Math.round(hr / 24)} 天前`;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** 同步健康的用户话术(sync_state.health 的取值见 lib/sync.js / lib/errors.js)。 */
|
|
238
|
+
function healthText(health) {
|
|
239
|
+
switch (String(health ?? "")) {
|
|
240
|
+
case "ok": return "正常";
|
|
241
|
+
case "warn": return "暂时失败,还在重试";
|
|
242
|
+
case "error": return "失败";
|
|
243
|
+
case "auth-error": return "需重新授权";
|
|
244
|
+
case "throttled": return "被服务商限流";
|
|
245
|
+
default: return String(health || "未知");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/* ── 设置卡移植(ui-design/MailboxSettings.jsx → 原生 h();展示层纯函数) ─────── */
|
|
250
|
+
|
|
251
|
+
/** 枚举值的友好文案(存储值不变,只换显示;未知值原样回显)。 */
|
|
252
|
+
function friendlyLabel(key, value) {
|
|
253
|
+
const v = String(value ?? "");
|
|
254
|
+
const table = {
|
|
255
|
+
"notify.channel": { auto: "自动选择(推荐)", im: "仅即时消息", local: "仅本地记录" },
|
|
256
|
+
"archive.mode": { online: "仅计数,不存正文(纯在线)", metadata: "存元数据与摘要", full: "全量(本地落库)" },
|
|
257
|
+
};
|
|
258
|
+
return table[key]?.[v] ?? v;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** "HH:MM" 规范化:<input type="time"> 只吃零填充两位;非法输入回 ""(控件显示为空)。 */
|
|
262
|
+
function hhmm(value) {
|
|
263
|
+
const m = /^(\d{1,2}):(\d{1,2})$/.exec(String(value ?? "").trim());
|
|
264
|
+
if (!m) return "";
|
|
265
|
+
const hh = Number(m[1]), mm = Number(m[2]);
|
|
266
|
+
if (!(hh >= 0 && hh <= 23 && mm >= 0 && mm <= 59)) return "";
|
|
267
|
+
return `${String(hh).padStart(2, "0")}:${String(mm).padStart(2, "0")}`;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** 关键词逗号串 → Tag 数组(仅展示;提交仍走 coerce 的 list 语义)。半角/全角逗号都切。 */
|
|
271
|
+
function splitKeywords(value) {
|
|
272
|
+
return String(value ?? "").split(/[,,]/).map((s) => s.trim()).filter(Boolean);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** 账号表单播种:添加 = 全默认;编辑 = 预填该账号(folders 拷贝成数组,勾选列表直接吃)。 */
|
|
276
|
+
function seedAccountDraft(acc) {
|
|
277
|
+
return {
|
|
278
|
+
email: acc?.email ?? "",
|
|
279
|
+
alias: acc?.alias ?? "",
|
|
280
|
+
imapHost: acc?.imapHost ?? "outlook.office365.com",
|
|
281
|
+
imapPort: acc?.imapPort ?? 993,
|
|
282
|
+
smtpHost: acc?.smtpHost ?? "smtp-mail.outlook.com",
|
|
283
|
+
smtpPort: acc?.smtpPort ?? 587,
|
|
284
|
+
defaultFolder: acc?.defaultFolder ?? "INBOX",
|
|
285
|
+
folders: Array.isArray(acc?.folders) ? [...acc.folders] : [],
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** 按字段类型把输入框的值转成 schema 认的类型;不合法返回 undefined(该字段跳过,不写 NaN)。 */
|
|
290
|
+
function coerce(field, raw) {
|
|
291
|
+
if (field.type === "int") {
|
|
292
|
+
if (raw === "" || raw === undefined || raw === null) return undefined;
|
|
293
|
+
const n = Number(raw);
|
|
294
|
+
return Number.isFinite(n) ? n : undefined;
|
|
295
|
+
}
|
|
296
|
+
if (field.type === "bool") return raw === true || raw === "true";
|
|
297
|
+
if (field.type === "list") {
|
|
298
|
+
if (Array.isArray(raw)) return raw;
|
|
299
|
+
return String(raw ?? "").split(/[,,\s]+/).map((s) => s.trim()).filter(Boolean);
|
|
300
|
+
}
|
|
301
|
+
// 字符串类一律 trim:实测有人把 " DSH(O)"(前导空格)写进了 targetId ⇒ 发不出去。
|
|
302
|
+
return raw === undefined || raw === null ? "" : String(raw).trim();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** 只提交"变了"的字段。 */
|
|
306
|
+
function buildOps(draft, runtimeValue) {
|
|
307
|
+
const ops = [];
|
|
308
|
+
for (const field of FIELDS) {
|
|
309
|
+
const key = keyOf(field);
|
|
310
|
+
if (!Object.hasOwn(draft, key)) continue;
|
|
311
|
+
const next = coerce(field, draft[key]);
|
|
312
|
+
if (next === undefined) continue;
|
|
313
|
+
const current = getIn(runtimeValue, field.path);
|
|
314
|
+
if (JSON.stringify(current ?? null) === JSON.stringify(next)) continue;
|
|
315
|
+
ops.push({ op: "set", path: [VOLATILE_KEY, ...field.path], value: next });
|
|
316
|
+
}
|
|
317
|
+
return ops;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** 页面能否写:远程 Web 的宿主只给 `mode:'memory'`(**不持久化**)⇒ 必须禁用控件 + 明确提示,
|
|
321
|
+
* 绝不能让用户以为"保存成功了"。ROADMAP §8-9 的验收点,单独抽出来是为了能离线测。
|
|
322
|
+
* live(自己 RPC 读到的)优先,缺哪个字段就退回页面给的;两者都为 undefined 时视为可写。 */
|
|
323
|
+
function isWritable(live, pageState) {
|
|
324
|
+
const l = live ?? {};
|
|
325
|
+
const p = pageState ?? {};
|
|
326
|
+
return (l.writable ?? p.writable) !== false && (l.mode ?? p.mode) !== "memory";
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** 把宿主 `{ok:false,...}` 翻译成一行可读的原因(这是三轮里最缺的东西)。 */
|
|
330
|
+
function describeRefusal(response) {
|
|
331
|
+
if (!response) return "no response";
|
|
332
|
+
const code = response.code ?? response.error?.code;
|
|
333
|
+
const message = response.error?.message ?? response.message;
|
|
334
|
+
const parts = [code, message].filter(Boolean);
|
|
335
|
+
return parts.length ? parts.join(": ") : JSON.stringify(response).slice(0, 240);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** 读宿主的权威命名空间视图(含 revision / value / user / base)。 */
|
|
339
|
+
async function readNamespaceView(settings, ns) {
|
|
340
|
+
if (!settings || typeof settings.describe !== "function") return { ok: false, message: "remote.settings 不可用" };
|
|
341
|
+
try {
|
|
342
|
+
const response = await settings.describe();
|
|
343
|
+
if (!response?.ok) return { ok: false, message: describeRefusal(response) };
|
|
344
|
+
const view = response.value?.namespaces?.find((row) => row.ns === ns);
|
|
345
|
+
return view ? { ok: true, view } : { ok: false, message: `宿主未服务命名空间 ${ns}` };
|
|
346
|
+
} catch (e) {
|
|
347
|
+
return { ok: false, message: String(e?.message ?? e) };
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** 直连 RPC 保存:**每次写入前现读 revision**(页面给的快照可能是挂载时的),失败重读再试一次。
|
|
352
|
+
* @returns { accepted, attempts, value?, reason?, firstReason? } */
|
|
353
|
+
async function saveViaRemote(settings, ns, ops) {
|
|
354
|
+
if (!ops || ops.length === 0) return { accepted: true, attempts: 0, reason: "nochange" };
|
|
355
|
+
if (!settings || typeof settings.mutate !== "function") return { accepted: false, attempts: 0, reason: "remote.settings 不可用" };
|
|
356
|
+
const before = await readNamespaceView(settings, ns);
|
|
357
|
+
let response = await settings.mutate(ns, ops, before.ok ? before.view.revision : undefined);
|
|
358
|
+
if (response?.ok) return { accepted: true, attempts: 1, value: response.value, reason: describeRefusal(response) };
|
|
359
|
+
const firstReason = describeRefusal(response);
|
|
360
|
+
const again = await readNamespaceView(settings, ns);
|
|
361
|
+
response = await settings.mutate(ns, ops, again.ok ? again.view.revision : undefined);
|
|
362
|
+
if (response?.ok) return { accepted: true, attempts: 2, value: response.value, firstReason };
|
|
363
|
+
return { accepted: false, attempts: 2, reason: describeRefusal(response), firstReason };
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** 退路:没有 `remote.settings` 时用页面给的 form(行为与上一版一致)。 */
|
|
367
|
+
async function saveWithRetry(form, ops, revision) {
|
|
368
|
+
if (!ops || ops.length === 0) return { accepted: true, attempts: 0, reason: "nochange" };
|
|
369
|
+
if (!form || typeof form.mutate !== "function") return { accepted: false, attempts: 0, reason: "no form" };
|
|
370
|
+
let accepted = await form.mutate(ops, revision);
|
|
371
|
+
if (accepted) return { accepted: true, attempts: 1 };
|
|
372
|
+
accepted = await form.mutate(ops);
|
|
373
|
+
return accepted ? { accepted: true, attempts: 2, reason: "retried" } : { accepted: false, attempts: 2, reason: "conflict" };
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
window.__ModuleLoader__.load({
|
|
377
|
+
id: ID,
|
|
378
|
+
factory: (require) => {
|
|
379
|
+
const React = require("react");
|
|
380
|
+
const h = React.createElement;
|
|
381
|
+
|
|
382
|
+
/** 由 apply() 在 remote.settings 就绪时填上(整个浏览器半边共享一份)。 */
|
|
383
|
+
let remoteSettings = null;
|
|
384
|
+
|
|
385
|
+
const S = {
|
|
386
|
+
wrap: { display: "flex", flexDirection: "column", gap: "10px", maxWidth: "46em" },
|
|
387
|
+
status: { fontSize: "12px", opacity: 0.65, fontFamily: "ui-monospace, monospace" },
|
|
388
|
+
group: { border: "1px solid rgba(128,128,128,0.25)", borderRadius: "6px", padding: "8px 10px" },
|
|
389
|
+
groupTitle: { fontSize: "12px", fontWeight: 600, opacity: 0.75, marginBottom: "4px" },
|
|
390
|
+
row: { display: "grid", gridTemplateColumns: "minmax(12em, 18em) 1fr", gap: "8px", alignItems: "center", margin: "4px 0" },
|
|
391
|
+
label: { fontSize: "13px" },
|
|
392
|
+
hint: { gridColumn: "2", fontSize: "11px", opacity: 0.6, marginTop: "-2px" },
|
|
393
|
+
actions: { display: "flex", gap: "8px", alignItems: "center" },
|
|
394
|
+
msg: { fontSize: "12px" },
|
|
395
|
+
err: { fontSize: "12px", color: "#c0392b", whiteSpace: "pre-wrap" },
|
|
396
|
+
raw: { maxHeight: "16em", overflow: "auto", fontSize: "11px", opacity: 0.85 },
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// ── 设置卡移植样式(MailboxSettings.jsx 的 Card/Modal/Tag/Badge → 原生内联) ────
|
|
400
|
+
const M = {
|
|
401
|
+
card: { border: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,0.25))", borderRadius: "8px", padding: "10px 12px", background: "var(--dsw-alias-bg-layer-1, transparent)" },
|
|
402
|
+
cardHead: { display: "flex", alignItems: "baseline", justifyContent: "space-between", gap: "8px", marginBottom: "6px" },
|
|
403
|
+
cardTitle: { fontSize: "13px", fontWeight: 600 },
|
|
404
|
+
cardExtra: { fontSize: "11px", opacity: 0.6 },
|
|
405
|
+
muted: { fontSize: "11px", opacity: 0.6 },
|
|
406
|
+
info: { display: "inline-flex", width: "14px", height: "14px", marginLeft: "5px", borderRadius: "50%", border: "1px solid rgba(128,128,128,0.5)", color: "var(--dsw-alias-label-secondary, inherit)", fontSize: "10px", lineHeight: "12px", justifyContent: "center", cursor: "help", userSelect: "none", verticalAlign: "1px" },
|
|
407
|
+
subcard: { border: "1px dashed var(--dsw-alias-border-l1, rgba(128,128,128,0.3))", borderRadius: "6px", padding: "8px 10px", margin: "6px 0" },
|
|
408
|
+
subcardTitle: { fontSize: "12px", fontWeight: 600, marginBottom: "4px" },
|
|
409
|
+
row: { display: "flex", flexWrap: "wrap", gap: "6px 10px", alignItems: "center", margin: "6px 0" },
|
|
410
|
+
rowLabel: { minWidth: "7.5em", fontSize: "12px", opacity: 0.85 },
|
|
411
|
+
acctRow: { display: "flex", alignItems: "center", gap: "8px", padding: "6px 4px", borderBottom: "1px solid rgba(128,128,128,0.15)" },
|
|
412
|
+
acctName: { fontWeight: 600, fontSize: "12px" },
|
|
413
|
+
acctSub: { fontSize: "11px", opacity: 0.65 },
|
|
414
|
+
badge: { display: "inline-flex", alignItems: "center", gap: "4px", fontSize: "11px" },
|
|
415
|
+
badgeDot: (color) => ({ width: "7px", height: "7px", borderRadius: "50%", background: color, flex: "0 0 auto" }),
|
|
416
|
+
tag: { fontSize: "10px", padding: "0 6px", borderRadius: "999px", border: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,0.3))", opacity: 0.8 },
|
|
417
|
+
chip: { display: "inline-flex", alignItems: "center", gap: "3px", fontSize: "11px", padding: "0 4px 0 8px", borderRadius: "999px", background: "var(--dsw-alias-bg-layer-2, rgba(128,128,128,0.12))" },
|
|
418
|
+
chipX: { border: "none", background: "transparent", cursor: "pointer", font: "inherit", padding: "0 3px", opacity: 0.7 },
|
|
419
|
+
mask: { position: "fixed", top: 0, right: 0, bottom: 0, left: 0, zIndex: 1000, background: "rgba(0,0,0,0.45)", display: "flex", alignItems: "center", justifyContent: "center", padding: "16px" },
|
|
420
|
+
modal: { width: "min(560px, 94vw)", maxHeight: "84vh", overflow: "auto", background: "var(--dsw-alias-bg-layer-1, #fff)", color: "var(--dsw-alias-label-primary, inherit)", border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.35))", borderRadius: "10px", padding: "14px 16px", boxShadow: "0 12px 40px rgba(0,0,0,0.35)" },
|
|
421
|
+
modalHead: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "8px" },
|
|
422
|
+
modalTitle: { fontSize: "14px", fontWeight: 600 },
|
|
423
|
+
foot: { display: "flex", gap: "8px", alignItems: "center", justifyContent: "flex-end", marginTop: "10px" },
|
|
424
|
+
banner: { background: "rgba(183,121,31,0.12)", border: "1px solid rgba(183,121,31,0.4)", borderRadius: "6px", padding: "8px 10px", marginBottom: "10px", fontSize: "12px" },
|
|
425
|
+
primary: { background: "var(--dsw-alias-brand-primary, #3b82f6)", borderColor: "transparent", color: "#fff" },
|
|
426
|
+
breath: "mbx-auth-breath",
|
|
427
|
+
zone: "mbx-folder-zone",
|
|
428
|
+
};
|
|
429
|
+
// 只放动画/过渡(内联 style 写不了 @keyframes);其余全走内联,不依赖外部样式表。
|
|
430
|
+
const SETTINGS_CSS = [
|
|
431
|
+
"@keyframes mbx-breath { 0%,100% { box-shadow: 0 0 0 0 rgba(59,130,246,0.45); } 50% { box-shadow: 0 0 0 6px rgba(59,130,246,0); } }",
|
|
432
|
+
".mbx-auth-breath { animation: mbx-breath 1.6s ease-in-out infinite; }",
|
|
433
|
+
".mbx-folder-zone { overflow: hidden; transition: max-height .24s ease, opacity .18s ease; }",
|
|
434
|
+
'.mbx-folder-zone[data-open="false"] { max-height: 0; opacity: 0; }',
|
|
435
|
+
'.mbx-folder-zone[data-open="true"] { max-height: 320px; opacity: 1; }',
|
|
436
|
+
].join("\n");
|
|
437
|
+
|
|
438
|
+
// ── M6.4:输入框浮动栏 ──────────────────────────────────────────────────────
|
|
439
|
+
// 挂 `conversation.input.overlay`(list / session 作用域 / "composer 卡片里的浮层")。
|
|
440
|
+
//
|
|
441
|
+
// 为什么走 HTTP 而不是 host.call:我们这个半边是**闭包工厂**形态
|
|
442
|
+
// (window.__ModuleLoader__.load),factory 只拿到 `require` —— 平台冻结表里只有 9 个模块,
|
|
443
|
+
// `host.call` / `ctx` / `styles` 那套内建是给「动态客户端半边」的,这里拿不到。
|
|
444
|
+
// 所以运行时状态只能走 M6.3 的回环桥(/api/mailbox/status|check)。
|
|
445
|
+
//
|
|
446
|
+
// 降噪原则(别让浮层变成噪音):**拿不到数据就什么都不画**。
|
|
447
|
+
// 主页面上没装 mailbox、或宿主没挂桥(403/404)时返回 null,而不是画一个红色错误块。
|
|
448
|
+
const BAR_PREFIX = "/api/mailbox";
|
|
449
|
+
const BAR_SLOT = "conversation.input.overlay";
|
|
450
|
+
const BAR_ID = `${ID}#status-bar`;
|
|
451
|
+
const BAR_POLL_MS = 30_000;
|
|
452
|
+
|
|
453
|
+
const B = {
|
|
454
|
+
wrap: { display: "flex", justifyContent: "flex-end", alignItems: "center", gap: "6px", fontSize: "12px" },
|
|
455
|
+
pill: {
|
|
456
|
+
display: "inline-flex", alignItems: "center", gap: "6px", padding: "2px 8px",
|
|
457
|
+
border: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,0.3))", borderRadius: "999px",
|
|
458
|
+
background: "var(--dsw-alias-bg-layer-1, transparent)", color: "var(--dsw-alias-label-secondary, inherit)",
|
|
459
|
+
cursor: "pointer", font: "inherit", lineHeight: "1.6",
|
|
460
|
+
},
|
|
461
|
+
dot: { width: "7px", height: "7px", borderRadius: "50%", flex: "0 0 auto" },
|
|
462
|
+
panel: {
|
|
463
|
+
position: "absolute", right: "12px", bottom: "calc(100% + 6px)", zIndex: 40,
|
|
464
|
+
width: "min(24em, 80vw)", maxHeight: "18em", overflow: "auto", padding: "8px 10px",
|
|
465
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.35))", borderRadius: "8px",
|
|
466
|
+
background: "var(--dsw-alias-bg-overlay, rgba(24,24,26,0.98))",
|
|
467
|
+
color: "var(--dsw-alias-label-primary, inherit)",
|
|
468
|
+
boxShadow: "0 6px 24px rgba(0,0,0,0.28)", textAlign: "left",
|
|
469
|
+
},
|
|
470
|
+
head: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "8px", marginBottom: "6px" },
|
|
471
|
+
title: { fontWeight: 600, fontSize: "12px" },
|
|
472
|
+
kv: { fontSize: "11px", color: "var(--dsw-alias-label-secondary, inherit)", lineHeight: "1.7" },
|
|
473
|
+
row: { borderTop: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,0.2))", padding: "4px 0", fontSize: "12px" },
|
|
474
|
+
sub: { fontSize: "11px", color: "var(--dsw-alias-label-secondary, inherit)" },
|
|
475
|
+
btn: {
|
|
476
|
+
font: "inherit", fontSize: "11px", padding: "1px 8px", cursor: "pointer", borderRadius: "5px",
|
|
477
|
+
border: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,0.3))",
|
|
478
|
+
background: "var(--dsw-alias-bg-layer-2, transparent)", color: "inherit",
|
|
479
|
+
},
|
|
480
|
+
err: { color: "var(--dsw-alias-state-error-primary, #c0392b)", fontSize: "11px", marginTop: "4px" },
|
|
481
|
+
};
|
|
482
|
+
const TONE = {
|
|
483
|
+
idle: "var(--dsw-alias-state-idle-primary, #8a8a8a)",
|
|
484
|
+
ok: "var(--dsw-alias-state-success-primary, #2e8b57)",
|
|
485
|
+
warn: "var(--dsw-alias-state-warn-primary, #b7791f)",
|
|
486
|
+
error: "var(--dsw-alias-state-error-primary, #c0392b)",
|
|
487
|
+
// 2026-10-27:barSummary 在"有新留痕"时返回 tone="alert",此前 TONE 里没有
|
|
488
|
+
// 这个键 → 落回 idle(灰点),最该被看见的状态反而不显眼。补上。
|
|
489
|
+
alert: "var(--dsw-alias-state-warn-primary, #b7791f)",
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
/** 秒 → 中文"多久以前"。纯函数,便于离线断言。 */
|
|
493
|
+
function formatAgo(seconds) {
|
|
494
|
+
const s = Number(seconds);
|
|
495
|
+
if (!Number.isFinite(s) || s < 0) return "(未知)";
|
|
496
|
+
if (s < 60) return `${Math.round(s)} 秒前`;
|
|
497
|
+
if (s < 3600) return `${Math.round(s / 60)} 分钟前`;
|
|
498
|
+
if (s < 86400) return `${Math.round(s / 3600)} 小时前`;
|
|
499
|
+
return `${Math.round(s / 86400)} 天前`;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** 视图 → 一粒徽标的文案/颜色/提示。纯函数(渲染之外的全部判断都在这里,好测)。 */
|
|
503
|
+
function barSummary(view, error) {
|
|
504
|
+
if (!view) {
|
|
505
|
+
const silent = error?.silent === true || error == null;
|
|
506
|
+
return {
|
|
507
|
+
text: silent ? "" : "邮箱:读取失败", tone: silent ? "idle" : "error",
|
|
508
|
+
title: silent ? "" : String(error?.message ?? error?.code ?? "读取失败"),
|
|
509
|
+
detail: "", silent,
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
const c = view.counts ?? {};
|
|
513
|
+
// M6.7(2026-10-30):**服务器实时数优先**(view.live 来自最近一轮 watcher 的
|
|
514
|
+
// STATUS)。没有实时数(首轮没跑/watcher 未运行)才退回报归档计数 —— online
|
|
515
|
+
// 模式下归档计数是切换前遗留的旧档,直接展示会误导。
|
|
516
|
+
const live = view.live && view.live.counts && view.live.at ? view.live : null;
|
|
517
|
+
const src = live ? live.counts : c;
|
|
518
|
+
const unread = Number(src.unread ?? 0);
|
|
519
|
+
const total = Number(src.messages ?? 0);
|
|
520
|
+
const unseen = Number(c.noticesUnseen ?? 0);
|
|
521
|
+
const running = view.watcher?.running === true && view.watcher?.paused !== true;
|
|
522
|
+
const lc = view.lastCheck;
|
|
523
|
+
const failed = Number(lc?.failures ?? 0);
|
|
524
|
+
// ⚠️ channel=local 时浮动栏是**唯一的提醒面**:未看留痕必须在最显眼的位置(2026-10-16)
|
|
525
|
+
const text = unseen > 0
|
|
526
|
+
? `📬 ${unseen} 新` + (unread > 0 ? ` · ${unread} 封未读` : "")
|
|
527
|
+
: `${unread > 0 ? `${unread} 封未读` : "无未读"} · 共 ${total}`;
|
|
528
|
+
const tone = unseen > 0 ? "alert" : ((view.warnings?.length || failed) ? "warn" : (running ? "ok" : "idle"));
|
|
529
|
+
const bits = [];
|
|
530
|
+
bits.push(running ? "轮询中" : (view.watcher?.reason ? `未轮询(${view.watcher.reason})` : "未轮询"));
|
|
531
|
+
bits.push(`每 ${view.watcher?.pollIntervalSeconds ?? 0}s`);
|
|
532
|
+
// 计数来源标注:让「这些数字哪来的」一眼可考(2026-10-30 用户被旧档数字迷惑过)
|
|
533
|
+
if (live) {
|
|
534
|
+
const ago = Math.max(0, Math.round((Number(view.at ?? 0) - Number(live.at ?? 0)) / 1000));
|
|
535
|
+
bits.push(`实时(服务器,${formatAgo(ago)})`);
|
|
536
|
+
if (live.counts?.known === false) bits.push("部分文件夹未读数未知");
|
|
537
|
+
} else if (view.archiveMode === "online") {
|
|
538
|
+
bits.push("归档计数(online 模式,首轮未跑前可能停旧)");
|
|
539
|
+
}
|
|
540
|
+
if (lc) bits.push(`上次检查 ${formatAgo(lc.agoSeconds)}取到 ${lc.fetched} 封${failed ? `,${failed} 个文件夹失败` : ""}`);
|
|
541
|
+
else bits.push("还没跑过第一轮");
|
|
542
|
+
if (unseen > 0) bits.push(`留痕 ${c.notices ?? 0} 条,未看 ${unseen} 条`);
|
|
543
|
+
// 多账户(2026-10-23):悬停提示给出分账户明细;徽标本体保持聚合短文案
|
|
544
|
+
const perAccount = accountsRows(view);
|
|
545
|
+
if (perAccount.length) bits.push(perAccount.join(" · "));
|
|
546
|
+
const title = `邮箱:${text}\n${bits.join(" · ")}`;
|
|
547
|
+
return { text, tone, title, detail: bits.join(" · "), silent: false };
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** 多账户时的分账户明细行(纯函数,2026-10-23)。
|
|
551
|
+
* 2026-10-30 监控文件夹选项:账户行追加**分文件夹**细分「(INBOX 230/1 · Projects 78/18)」
|
|
552
|
+
* —— 只有一个账户但配了多个监控文件夹时也要出明细(否则看不到各文件夹的隔离数据)。
|
|
553
|
+
* unread 为 null(STATUS 没给)显示 "?";只轮询到一个文件夹时不细分(等于聚合行)。 */
|
|
554
|
+
function folderBreakdownText(a) {
|
|
555
|
+
const fs = Array.isArray(a.folders) ? a.folders : [];
|
|
556
|
+
if (fs.length < 2) return "";
|
|
557
|
+
return "(" + fs.map((f) => `${f.folder || "?"} ${Number(f.total ?? 0)}/${f.unread == null ? "?" : Number(f.unread)}`).join(" · ") + ")";
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/** 监控文件夹按「大小写不敏感」去重(纯函数,2026-10-30 需求,与 lib/config.js dedupeFolders 同口径):
|
|
561
|
+
* Outlook/Exchange 邮箱名不分大小写,"INBOX"/"inbox" 是同一文件夹,重复会造成双轮询与同义标签。
|
|
562
|
+
* 保留首个书写形式;空白项丢弃;非数组安全返回 []。 */
|
|
563
|
+
function dedupeFoldersCase(list) {
|
|
564
|
+
const seen = new Set();
|
|
565
|
+
const out = [];
|
|
566
|
+
for (const raw of Array.isArray(list) ? list : []) {
|
|
567
|
+
if (raw == null) continue; // String(null)="null" 会混进真文件夹,先拦
|
|
568
|
+
const f = String(raw).trim();
|
|
569
|
+
if (!f) continue;
|
|
570
|
+
const key = f.toLowerCase();
|
|
571
|
+
if (!seen.has(key)) { seen.add(key); out.push(f); }
|
|
572
|
+
}
|
|
573
|
+
return out;
|
|
574
|
+
}
|
|
575
|
+
function accountsRows(view) {
|
|
576
|
+
const accounts = Array.isArray(view?.accounts) ? view.accounts : [];
|
|
577
|
+
const multi = accounts.length >= 2 || accounts.some((a) => Array.isArray(a.folders) && a.folders.length > 1);
|
|
578
|
+
if (!multi) return [];
|
|
579
|
+
return accounts.map((a) =>
|
|
580
|
+
`${a.alias || a.account}:未读 ${a.unread == null ? "?" : Number(a.unread ?? 0)} · 共 ${Number(a.messages ?? 0)}${folderBreakdownText(a)}`);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* 收起态「严格单行流」的四个键值块(纯函数,2026-10-30 需求 5)。
|
|
585
|
+
* 收起时界面只保留:🔄 监控状态 | ⏱️ 上次同步 | 📧 分账户未读 | 💡 提示;
|
|
586
|
+
* 文件夹数字/留痕数/日报缓冲这类 log 级调试信息全部退场(悬停 title 或展开面板里才给)。
|
|
587
|
+
* accounts 每项 {label, unread}:unread>0 渲染高亮色,0/null 浅灰。
|
|
588
|
+
*/
|
|
589
|
+
function collapsedBlocks(view) {
|
|
590
|
+
const w = view?.watcher ?? {};
|
|
591
|
+
const running = w.running === true && w.paused !== true;
|
|
592
|
+
const monitor = running
|
|
593
|
+
? `🔄 自动监控中 (${Number(w.pollIntervalSeconds ?? 0)}s)`
|
|
594
|
+
: "⏸️ 自动监控未运行";
|
|
595
|
+
const lc = view?.lastCheck ?? null;
|
|
596
|
+
const sync = view
|
|
597
|
+
? `⏱️ 上次同步: ${lc ? formatAgo(Number(lc.agoSeconds ?? 0)) : "还没跑过"}`
|
|
598
|
+
: "";
|
|
599
|
+
const accounts = (Array.isArray(view?.accounts) ? view.accounts : [])
|
|
600
|
+
.filter((a) => String(a?.account ?? ""))
|
|
601
|
+
.map((a) => ({ label: String(a.alias || a.account), unread: a.unread == null ? null : Number(a.unread) }));
|
|
602
|
+
const unseen = Number(view?.counts?.noticesUnseen ?? 0);
|
|
603
|
+
// 有未看留痕时,第 4 块要扛起「提醒」职责(否则 channel=local 的用户在收起态没有任何新邮件信号)
|
|
604
|
+
const hint = unseen > 0
|
|
605
|
+
? { text: `💡 ${unseen} 封新邮件在「未看提示」里`, unseen }
|
|
606
|
+
: { text: "💡 详情请展开「未看提示」列表", unseen: 0 };
|
|
607
|
+
return { monitor, sync, accounts, hint, running };
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/** 展开面板的「多账户 × 多文件夹」网格数据(纯函数)。folders 缺省 → 回退聚合数。 */
|
|
611
|
+
function accountGridCells(view) {
|
|
612
|
+
const accounts = Array.isArray(view?.accounts) ? view.accounts : [];
|
|
613
|
+
return accounts.filter((a) => String(a?.account ?? "")).map((a) => ({
|
|
614
|
+
label: String(a.alias || a.account),
|
|
615
|
+
unread: a.unread == null ? null : Number(a.unread ?? 0),
|
|
616
|
+
total: Number(a.messages ?? 0),
|
|
617
|
+
folders: Array.isArray(a.folders) ? a.folders.map((f) => ({
|
|
618
|
+
folder: String(f.folder ?? "?"),
|
|
619
|
+
total: Number(f.total ?? 0),
|
|
620
|
+
unread: f.unread == null ? null : Number(f.unread),
|
|
621
|
+
})) : [],
|
|
622
|
+
}));
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/** 展开面板顶部的一句话状态(纯函数,2026-10-30 需求 6):去日志化后的三段摘要。
|
|
626
|
+
* 「🔄 后台检测中 (每60s) | ⏱️ 上次检查: 21秒前 | 🔒 归档: 纯在线模式 (无本地落库)」
|
|
627
|
+
* 替代旧面板里 未读/共/留痕/日报缓冲/归档模式/设置真相 那坨 log 级文本。 */
|
|
628
|
+
function panelStatusLine(view) {
|
|
629
|
+
const w = view?.watcher ?? {};
|
|
630
|
+
const monitor = (w.running === true && w.paused !== true)
|
|
631
|
+
? `🔄 后台检测中 (每${Number(w.pollIntervalSeconds ?? 0)}s)`
|
|
632
|
+
: "⏸️ 后台检测未运行";
|
|
633
|
+
const lc = view?.lastCheck ?? null;
|
|
634
|
+
const last = lc ? `⏱️ 上次检查: ${formatAgo(Number(lc.agoSeconds ?? 0))}` : "⏱️ 上次检查: 还没跑过";
|
|
635
|
+
const mode = view?.archiveMode === "online" ? "🔒 归档: 纯在线模式 (无本地落库)"
|
|
636
|
+
: view?.archiveMode === "local" ? "🔒 归档: 纯本地模式"
|
|
637
|
+
: "🔒 归档: 全量模式 (本地落库)";
|
|
638
|
+
return [monitor, last, mode];
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/** dock 展开面板的状态行(2026-10-31 用户反馈去重):收起态单行已展示
|
|
642
|
+
* 「🔄 自动监控中 / ⏱️ 上次同步」,面板不再重复这两段;只保留面板独有的
|
|
643
|
+
* 归档模式说明,且仅纯在线模式有解释价值(解释"为什么没有本地明细、
|
|
644
|
+
* 计数为何是服务器实时"),metadata/full 模式下面板不出现状态行。 */
|
|
645
|
+
function dockPanelStatusLine(view) {
|
|
646
|
+
if (view?.archiveMode !== "online") return [];
|
|
647
|
+
return panelStatusLine(view).filter((seg) => seg.startsWith("🔒"));
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/** 未看通知留痕块(2026-10-30 需求 6 深度升级):
|
|
651
|
+
* 高密度卡片行:第一行粗体 ✉️ 主题;第二行小字 👤 发件人 · 📧 账户 / 📂 文件夹 · ⏰ 时间。
|
|
652
|
+
* 整行可点(uid 在手)= onPick 插入输入框;行尾「已看」= 单条消费
|
|
653
|
+
* (opts.onConsume(key,id) 由 dock 注入淡出动画;缺省直呼 onAckOne,浮层用)。
|
|
654
|
+
* opts.onAckAll = 列表底部「全部标记为已看」;opts.hover/setHover/acking = dock 注入
|
|
655
|
+
* 的悬停高亮与消费中淡出状态;浮层不注入 → 纯静态行。纯展示组件,异常全吞。 */
|
|
656
|
+
function noticesBlock(view, onAckOne, onPick, opts = {}) {
|
|
657
|
+
const items = Array.isArray(view?.notices) ? view.notices : [];
|
|
658
|
+
if (items.length === 0) return null;
|
|
659
|
+
return h("div", { style: { marginTop: "6px" } },
|
|
660
|
+
h("div", { style: D.sub },
|
|
661
|
+
view?.recentUnavailable
|
|
662
|
+
? `📬 未看提示 ${items.length} 封(online 模式不落库:徽标上的新邮件在这里,点一封即可追问)`
|
|
663
|
+
: `📬 未看提示 ${items.length} 封`),
|
|
664
|
+
items.map((n) => {
|
|
665
|
+
const pickable = n.uid != null;
|
|
666
|
+
const key = `n:${n.id}-${n.uid ?? "x"}`;
|
|
667
|
+
const refText = pickable ? mailRefText(n) : "";
|
|
668
|
+
const consuming = opts.acking?.has?.(key) === true;
|
|
669
|
+
return h("div", {
|
|
670
|
+
key,
|
|
671
|
+
role: pickable ? "button" : undefined,
|
|
672
|
+
tabIndex: pickable ? 0 : undefined,
|
|
673
|
+
style: {
|
|
674
|
+
...D.mailRow,
|
|
675
|
+
...(pickable && opts.hover === key ? D.mailRowHover : {}),
|
|
676
|
+
...(pickable ? { cursor: "pointer" } : {}),
|
|
677
|
+
opacity: consuming ? 0 : 1,
|
|
678
|
+
transition: "opacity .18s ease",
|
|
679
|
+
},
|
|
680
|
+
title: pickable
|
|
681
|
+
? `${refText}\n${n.noticeTitle ?? ""}\n点击把邮件坐标插进输入框,即可对这封继续提问/操作`
|
|
682
|
+
: (n.body || n.noticeTitle || ""),
|
|
683
|
+
onMouseEnter: pickable && typeof opts.setHover === "function" ? () => opts.setHover(key) : undefined,
|
|
684
|
+
onMouseLeave: pickable && typeof opts.setHover === "function" ? () => opts.setHover("") : undefined,
|
|
685
|
+
onClick: pickable ? () => { try { onPick?.(n); } catch { /* 展示块不抛 */ } } : undefined,
|
|
686
|
+
onKeyDown: pickable ? (e) => { if (e?.key === "Enter") { try { onPick?.(n); } catch { /* ignore */ } } } : undefined,
|
|
687
|
+
},
|
|
688
|
+
h("div", { style: D.subject }, `${pickable ? "✉️" : "🔔"} ${n.subject || "(无主题)"}`),
|
|
689
|
+
h("div", { style: D.metaLine },
|
|
690
|
+
[
|
|
691
|
+
`👤 ${n.from || "(未知发件人)"}`,
|
|
692
|
+
`📧 ${n.account}${n.folder ? ` / 📂 ${n.folder}` : ""}`,
|
|
693
|
+
n.at ? `⏰ ${new Date(n.at).toLocaleString()}` : "",
|
|
694
|
+
].filter(Boolean).map((txt, i, arr) =>
|
|
695
|
+
h("span", { key: i }, txt + (i < arr.length - 1 ? " · " : "")))),
|
|
696
|
+
h("button", { type: "button", style: { ...D.iconBtn, padding: "0 6px" },
|
|
697
|
+
title: "只把这条通知标为已看(徽标与上方网格数字随之减少)",
|
|
698
|
+
onClick: (e) => {
|
|
699
|
+
e?.stopPropagation?.();
|
|
700
|
+
if (consuming) return;
|
|
701
|
+
if (typeof opts.onConsume === "function") { try { opts.onConsume(key, n.id); } catch { /* 展示块不抛 */ } }
|
|
702
|
+
else { try { onAckOne?.(n.id); } catch { /* 展示块不抛 */ } }
|
|
703
|
+
} },
|
|
704
|
+
"已看"));
|
|
705
|
+
}),
|
|
706
|
+
typeof opts.onAckAll === "function"
|
|
707
|
+
? h("div", { style: { display: "flex", justifyContent: "flex-end", marginTop: "4px" } },
|
|
708
|
+
h("button", { type: "button", style: { ...D.iconBtn, padding: "2px 8px" },
|
|
709
|
+
title: "把列表里的通知全部标为已看(徽标清零)",
|
|
710
|
+
onClick: () => { try { opts.onAckAll(); } catch { /* 展示块不抛 */ } } },
|
|
711
|
+
"📋 全部标记为已看"))
|
|
712
|
+
: null);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/** 邮件坐标文本(点 📋 复制,粘到对话里 AI 即可定位读/回这封)。纯函数。 */
|
|
716
|
+
function mailRefText(m) {
|
|
717
|
+
return `${m?.account ?? "?"}/${m?.folder ?? "?"}/uid=${m?.uid ?? "?"}`;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/** 调桥。**静默失败**(403/404 表示宿主没挂桥:这个 profile 里没有邮件功能,不该报警)。 */
|
|
721
|
+
async function bridgeCall(action, body, method = "POST") {
|
|
722
|
+
try {
|
|
723
|
+
const opts = {
|
|
724
|
+
method,
|
|
725
|
+
headers: { "content-type": "application/json" },
|
|
726
|
+
credentials: "same-origin",
|
|
727
|
+
};
|
|
728
|
+
if (method === "POST" || method === "PUT" || method === "DELETE") {
|
|
729
|
+
opts.body = JSON.stringify(body ?? {});
|
|
730
|
+
}
|
|
731
|
+
const res = await fetch(`${BAR_PREFIX}${action}`, opts);
|
|
732
|
+
if (res.status === 403 || res.status === 404) return { ok: false, silent: true, code: `http-${res.status}` };
|
|
733
|
+
if (!res.ok) return { ok: false, code: `http-${res.status}`, message: `宿主返回 ${res.status}` };
|
|
734
|
+
const data = await res.json();
|
|
735
|
+
// 不是对象 ⇒ 桥没在回答(可能是别的服务/反代接手了)。同样按"拿不到数据"处理。
|
|
736
|
+
return data && typeof data === "object"
|
|
737
|
+
? data
|
|
738
|
+
: { ok: false, silent: true, code: "bad-response", message: "响应不是对象" };
|
|
739
|
+
} catch (e) {
|
|
740
|
+
// 网络层失败(页面刚启动 / 宿主还没监听)也算静默:下次轮询再试,不打扰用户
|
|
741
|
+
return { ok: false, silent: true, code: "network", message: String(e?.message ?? e) };
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/** 浮动栏的轮询调度:**可见时**按 BAR_POLL_MS 轮询;**页面隐藏时停表**(不白烧),
|
|
746
|
+
* 重新可见时先立刻刷一次再恢复。抽成纯函数是为了能离线断言(假定时器 + 假 document)。 */
|
|
747
|
+
function makeBarPoller({
|
|
748
|
+
load, intervalMs = BAR_POLL_MS,
|
|
749
|
+
doc = (typeof document === "undefined" ? null : document),
|
|
750
|
+
setTimer = setInterval, clearTimer = clearInterval,
|
|
751
|
+
}) {
|
|
752
|
+
let timer = null;
|
|
753
|
+
const hidden = () => doc?.visibilityState === "hidden";
|
|
754
|
+
const tick = () => { void load(); };
|
|
755
|
+
const arm = () => { if (timer === null && !hidden()) timer = setTimer(tick, intervalMs); };
|
|
756
|
+
const disarm = () => { if (timer !== null) { clearTimer(timer); timer = null; } };
|
|
757
|
+
const onVisibilityChange = () => { if (hidden()) disarm(); else { tick(); arm(); } };
|
|
758
|
+
return {
|
|
759
|
+
arm, disarm, onVisibilityChange,
|
|
760
|
+
armed: () => timer !== null,
|
|
761
|
+
attach() { doc?.addEventListener?.("visibilitychange", onVisibilityChange); arm(); },
|
|
762
|
+
detach() { doc?.removeEventListener?.("visibilitychange", onVisibilityChange); disarm(); },
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
function MailboxFloatingBar() {
|
|
767
|
+
const [view, setView] = React.useState(null);
|
|
768
|
+
const [error, setError] = React.useState(null);
|
|
769
|
+
const [open, setOpen] = React.useState(false);
|
|
770
|
+
const [busy, setBusy] = React.useState(false);
|
|
771
|
+
|
|
772
|
+
React.useEffect(() => {
|
|
773
|
+
let alive = true;
|
|
774
|
+
const load = async () => {
|
|
775
|
+
const r = await bridgeCall("/status", { limit: 5 });
|
|
776
|
+
if (!alive) return;
|
|
777
|
+
if (r.ok) { setView(r.value ?? null); setError(null); } else setError(r);
|
|
778
|
+
};
|
|
779
|
+
const poller = makeBarPoller({ load });
|
|
780
|
+
poller.attach(); // 隐藏态启动则只挂监听,不轮询;变可见时自己补一次
|
|
781
|
+
void load();
|
|
782
|
+
return () => { alive = false; poller.detach(); };
|
|
783
|
+
}, []);
|
|
784
|
+
|
|
785
|
+
const s = barSummary(view, error);
|
|
786
|
+
if (s.silent && !view) return null; // 这个 profile 没有 mailbox:不画任何东西
|
|
787
|
+
|
|
788
|
+
const tt = (key, fallback) => (DICT.zh[key] ?? fallback ?? key);
|
|
789
|
+
const doCheck = async () => {
|
|
790
|
+
setBusy(true);
|
|
791
|
+
const r = await bridgeCall("/check", {});
|
|
792
|
+
if (r.ok) setView(r.value?.status ?? view); else setError(r);
|
|
793
|
+
const after = await bridgeCall("/status", { limit: 5 });
|
|
794
|
+
if (after.ok) { setView(after.value ?? null); setError(null); }
|
|
795
|
+
setBusy(false);
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
const c = view?.counts ?? {};
|
|
799
|
+
const panel = open ? h("div", { style: B.panel, key: "panel" },
|
|
800
|
+
h("div", { style: B.head },
|
|
801
|
+
h("span", { style: B.title }, tt("bar_title", "邮箱")),
|
|
802
|
+
h("button", { type: "button", style: B.btn, disabled: busy, onClick: () => { void doCheck(); } },
|
|
803
|
+
busy ? tt("bar_checking", "检查中…") : tt("bar_check", "立刻检查")),
|
|
804
|
+
(c.noticesUnseen ?? 0) > 0
|
|
805
|
+
? h("button", {
|
|
806
|
+
type: "button", style: { ...B.btn, fontWeight: 600 },
|
|
807
|
+
onClick: async () => {
|
|
808
|
+
const r = await bridgeCall("/ack", {});
|
|
809
|
+
if (r.ok) { const after = await bridgeCall("/status", { limit: 5 }); if (after.ok) setView(after.value ?? null); }
|
|
810
|
+
},
|
|
811
|
+
}, `📬 标为已看(${c.noticesUnseen})`)
|
|
812
|
+
: null,
|
|
813
|
+
h("button", { type: "button", style: B.btn, onClick: () => setOpen(false) }, tt("bar_close", "关闭"))),
|
|
814
|
+
h("div", { style: B.kv },
|
|
815
|
+
// 需求 6(2026-10-30):浮层面板同步去日志化 —— 一句话状态摘要替代 计数/留痕/日报缓冲/设置真相 行
|
|
816
|
+
h("div", { style: { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }, title: panelStatusLine(view).join(" | ") },
|
|
817
|
+
panelStatusLine(view).map((seg, i, arr) => h("span", { key: i, style: B.sub }, seg + (i < arr.length - 1 ? " | " : "")))),
|
|
818
|
+
view?.notify ? h("div", { style: B.sub }, `通知 ${view.notify.enabled ? "开" : "关"}(${view.notify.channel}${view.notify.targetReady ? "" : ",通道未就绪"})`) : null,
|
|
819
|
+
view?.warnings?.length ? h("div", { style: B.err }, view.warnings.join(" / ")) : null),
|
|
820
|
+
// 多账户:分账户明细行(单账户时不渲染)
|
|
821
|
+
accountsRows(view).length ? h("div", { style: { ...B.sub, marginTop: "4px" } },
|
|
822
|
+
accountsRows(view).map((line) => h("div", { key: line }, line))) : null,
|
|
823
|
+
(view?.recent?.length ?? 0) === 0
|
|
824
|
+
? h("div", { style: B.sub },
|
|
825
|
+
view?.recentUnavailable
|
|
826
|
+
? "online 模式不落库:无本地邮件明细(上方计数为服务器实时)"
|
|
827
|
+
: "还没有归档的邮件")
|
|
828
|
+
: view.recent.map((m) => h("div", {
|
|
829
|
+
style: B.row, key: `${m.account}/${m.folder}/${m.uid}`,
|
|
830
|
+
title: `${mailRefText(m)}\n${m.snippet ?? ""}\n点 📋 复制坐标,粘到对话即可让 AI 读/回这封`,
|
|
831
|
+
},
|
|
832
|
+
h("div", null, m.seen ? "" : "● ", m.subject || "(无主题)"),
|
|
833
|
+
h("div", { style: B.sub },
|
|
834
|
+
`${(Array.isArray(view?.accounts) && view.accounts.length > 1) ? `[${m.alias || m.account}] ` : ""}${m.from || "(未知发件人)"} · ${m.dateTs ? new Date(m.dateTs).toLocaleString() : "(无日期)"}`
|
|
835
|
+
+ `${m.hasAttachment ? " · 📎" : ""}${m.importance != null ? ` · 重要度 ${m.importance}` : ""}`),
|
|
836
|
+
h("button", {
|
|
837
|
+
type: "button", style: { ...B.btn, padding: "0 6px", float: "right", marginLeft: "6px" },
|
|
838
|
+
title: "复制坐标(账户/文件夹/uid),粘贴到对话即可让 AI 读这封",
|
|
839
|
+
onClick: () => { if (navigator.clipboard?.writeText) void navigator.clipboard.writeText(mailRefText(m)).catch(() => {}); },
|
|
840
|
+
}, "📋"))),
|
|
841
|
+
// 未看通知留痕块(与 dock 面板同源):online 模式下徽标上的新邮件在这里逐条列出。
|
|
842
|
+
// 浮层没有输入框动作面,选中 = 复制坐标(粘到对话即可让 AI 读这封)
|
|
843
|
+
noticesBlock(view, async (id) => {
|
|
844
|
+
await bridgeCall("/ack", { ids: [id] });
|
|
845
|
+
const after = await bridgeCall("/status", { limit: 5 });
|
|
846
|
+
if (after.ok) setView(after.value ?? null);
|
|
847
|
+
}, (m) => { clipboardCopy(mailInsertText(m)); }),
|
|
848
|
+
error && !error.silent ? h("div", { style: B.err }, String(error.message ?? error.code ?? "读取失败")) : null)
|
|
849
|
+
: null;
|
|
850
|
+
|
|
851
|
+
return h("div", { style: { ...B.wrap, position: "relative", padding: "0 8px 4px" } },
|
|
852
|
+
h("button", {
|
|
853
|
+
type: "button", style: B.pill, title: s.title,
|
|
854
|
+
"aria-expanded": open, onClick: () => setOpen((v) => !v),
|
|
855
|
+
},
|
|
856
|
+
h("span", { style: { ...B.dot, background: TONE[s.tone] ?? TONE.idle } }),
|
|
857
|
+
h("span", null, s.text || tt("bar_title", "邮箱"))),
|
|
858
|
+
panel);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// ── M6.6:对话框上方的邮件提示栏(conversation.input.dock) ──────────────────
|
|
862
|
+
//
|
|
863
|
+
// 为什么从「输入框里的浮层」升级到「输入框上方的整条」:
|
|
864
|
+
// ① `conversation.input.overlay`(M6.4 用的那个)是**输入框卡片内部的浮层** ——
|
|
865
|
+
// 展开的浮板是绝对定位 + z-index,会**盖住上方的历史对话**:用户想回头看
|
|
866
|
+
// 刚才 AI 说了什么,得先收起浮板,两边只能二选一。
|
|
867
|
+
// ② `conversation.input.dock` 是**输入框卡片上方的全宽带**(官方队列栏 QueueDock
|
|
868
|
+
// 就挂在这里)。展开时它**不覆盖任何东西**,只是把聊天区**压矮** ——
|
|
869
|
+
// 聊天区本身是 flex:1 + 独立滚动,历史记录照样能滚到、能看完。
|
|
870
|
+
// 所以:提示栏挂 dock;展开面板**限高**(min(38vh, 320px))并内部滚动,永不吃掉整屏。
|
|
871
|
+
//
|
|
872
|
+
// 账号切换:桥的 `/status` 支持 `account` 过滤(见 lib/bridge.js),切账号 = 重拉
|
|
873
|
+
// 该账号的最近邮件;顶栏的汇总数字取 `view.accounts` 里的分账户合计。
|
|
874
|
+
//
|
|
875
|
+
// 点选邮件 = 把**邮件坐标**插进输入框(`inputActions.captureInsertion` +
|
|
876
|
+
// `insertText`;由 dsh-client-ui-conversation 以会话级 prop 提供),用户不用复制
|
|
877
|
+
// 粘贴;坐标里直接写明参数名,模型一看就知道该调 mailbox_read(account, folder, uid)。
|
|
878
|
+
const DOCK_SLOT = "conversation.input.dock";
|
|
879
|
+
const DOCK_ID = `${ID}#mail-dock`;
|
|
880
|
+
// 15:避开内建 goal dock 的 order 10(list 槽位按 order 升序,同序不保证相对位置)。
|
|
881
|
+
const DOCK_ORDER = 15;
|
|
882
|
+
const DOCK_RECENT_LIMIT = 20;
|
|
883
|
+
/** "全部"账号的哨兵值(空串 = 不按账号过滤)。 */
|
|
884
|
+
const ALL_ACCOUNTS = "";
|
|
885
|
+
|
|
886
|
+
const D = {
|
|
887
|
+
// 几何对齐官方 QueueDock(dock 条与输入框卡片同宽、同居中)
|
|
888
|
+
wrap: {
|
|
889
|
+
boxSizing: "border-box",
|
|
890
|
+
width: "calc(100% - var(--dsh-composer-side-clearance, 16px) - var(--dsh-composer-side-clearance, 16px) - var(--dsh-composer-dock-inset, 8px) - var(--dsh-composer-dock-inset, 8px))",
|
|
891
|
+
maxWidth: "calc(var(--dsh-composer-card-max-width, 760px) - var(--dsh-composer-dock-inset, 8px) - var(--dsh-composer-dock-inset, 8px))",
|
|
892
|
+
margin: "0 auto",
|
|
893
|
+
padding: "0 var(--dsh-composer-dock-inset, 8px)",
|
|
894
|
+
flex: "none",
|
|
895
|
+
},
|
|
896
|
+
card: {
|
|
897
|
+
border: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,0.25))",
|
|
898
|
+
borderRadius: "10px",
|
|
899
|
+
background: "var(--dsw-alias-bg-layer-1, transparent)",
|
|
900
|
+
overflow: "hidden",
|
|
901
|
+
},
|
|
902
|
+
// 顶行 = 严格单行流(需求 5):flex 横排、禁止换行、两端对齐;
|
|
903
|
+
// 左侧「状态块组」可在窄窗口下压缩(账号块省略号),右侧「提示 + 操作」不换行。
|
|
904
|
+
row: {
|
|
905
|
+
display: "flex", alignItems: "center", gap: "8px", padding: "5px 8px", fontSize: "12px", minHeight: "30px",
|
|
906
|
+
flexWrap: "nowrap", justifyContent: "space-between",
|
|
907
|
+
},
|
|
908
|
+
// 左侧状态块组(🔄 监控 | ⏱️ 同步 | 📧 账户):整体可收缩,块内禁止换行
|
|
909
|
+
flow: { display: "flex", alignItems: "center", gap: "8px", flex: "1 1 auto", minWidth: "0px", overflow: "hidden" },
|
|
910
|
+
// 右侧(💡 提示 + 同步/展开按钮):不参与换行;提示条在极窄时可省略号
|
|
911
|
+
flowRight: { display: "flex", alignItems: "center", gap: "4px", flex: "0 1 auto", minWidth: "0px", overflow: "hidden" },
|
|
912
|
+
blk: {
|
|
913
|
+
whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", flex: "0 1 auto",
|
|
914
|
+
color: "var(--dsw-alias-label-secondary, inherit)", fontVariantNumeric: "tabular-nums", fontFeatureSettings: '"tnum" 1',
|
|
915
|
+
},
|
|
916
|
+
blkHot: { color: "var(--dsw-alias-brand-primary, #3b82f6)", fontWeight: "600" },
|
|
917
|
+
blkDim: { color: "var(--dsw-alias-label-secondary, inherit)", opacity: 0.75 },
|
|
918
|
+
// 状态点按钮:里面只有一颗圆点(文字已移出),所以收成正方形热区,
|
|
919
|
+
// 不再撑成一颗带内边距的"药丸",免得左侧看起来像少画了字。
|
|
920
|
+
pill: {
|
|
921
|
+
display: "inline-flex", alignItems: "center", justifyContent: "center",
|
|
922
|
+
width: "18px", height: "18px", padding: 0, flex: "0 0 auto",
|
|
923
|
+
border: "none", borderRadius: "999px", background: "transparent",
|
|
924
|
+
color: "inherit", cursor: "pointer", font: "inherit", lineHeight: 0,
|
|
925
|
+
},
|
|
926
|
+
dot: { width: "8px", height: "8px", borderRadius: "50%", flex: "0 0 auto" },
|
|
927
|
+
// 左侧"汇总"区(2026-10-27 重做):不再写成「3 封未读 · 共 12」这种句子 ——
|
|
928
|
+
// 句子宽度随位数抖动(jitter),还和页签徽标、右侧 meta 三处重复同一件事。
|
|
929
|
+
// 现在拆成**对齐的指标块**:数字用 tabular-nums 固定字宽,单位弱化,靠 gap 分列。
|
|
930
|
+
stats: { display: "inline-flex", alignItems: "center", gap: "10px", flex: "0 0 auto", whiteSpace: "nowrap" },
|
|
931
|
+
stat: { display: "inline-flex", alignItems: "baseline", gap: "3px", lineHeight: "1.5" },
|
|
932
|
+
statNum: {
|
|
933
|
+
fontSize: "12.5px", fontWeight: "600", letterSpacing: "0.2px",
|
|
934
|
+
fontVariantNumeric: "tabular-nums", fontFeatureSettings: '"tnum" 1',
|
|
935
|
+
color: "var(--dsw-alias-label-primary, inherit)",
|
|
936
|
+
},
|
|
937
|
+
statNumHot: { color: "var(--dsw-alias-brand-primary, #3b82f6)" },
|
|
938
|
+
statUnit: { fontSize: "11px", color: "var(--dsw-alias-label-secondary, inherit)" },
|
|
939
|
+
// 「N 新」是 channel=local 时**唯一**的提醒面,单独给个实底药丸,不能被数字流淹掉
|
|
940
|
+
statNew: {
|
|
941
|
+
display: "inline-flex", alignItems: "baseline", gap: "3px", padding: "0 6px",
|
|
942
|
+
borderRadius: "999px", background: "var(--dsw-alias-state-warn-primary, #b7791f)", color: "#fff",
|
|
943
|
+
},
|
|
944
|
+
statNewNum: {
|
|
945
|
+
fontSize: "12px", fontWeight: "700", fontVariantNumeric: "tabular-nums",
|
|
946
|
+
fontFeatureSettings: '"tnum" 1',
|
|
947
|
+
},
|
|
948
|
+
statNewUnit: { fontSize: "10.5px", opacity: 0.92 },
|
|
949
|
+
sep: { width: "1px", height: "11px", background: "var(--dsw-alias-border-l1, rgba(128,128,128,0.3))", flex: "0 0 auto" },
|
|
950
|
+
tabs: { display: "flex", alignItems: "center", gap: "2px", flex: "0 1 auto", overflow: "hidden", minWidth: 0 },
|
|
951
|
+
// ⚠️ 2026-10-27 修「选中的没高亮、没选中的反而被框住」:
|
|
952
|
+
// 旧写法让**每个**页签都带 `border:1px solid transparent`,再给选中的那个补 `borderColor`
|
|
953
|
+
// —— 于是"有没有边框"被当成选中态,而点击后**焦点环**留在旧页签上,看起来就是"没选中的
|
|
954
|
+
// 那个被框住了"。现在改成**用填充色区分**、所有页签都不画边框(只保留 outline:none
|
|
955
|
+
// 消掉浏览器默认焦点环),选中 = 实心填充 + 主色文字 + 加粗。
|
|
956
|
+
tab: {
|
|
957
|
+
display: "inline-flex", alignItems: "center", gap: "4px", padding: "2px 9px", borderRadius: "999px",
|
|
958
|
+
border: "none", background: "transparent", outline: "none",
|
|
959
|
+
color: "var(--dsw-alias-label-secondary, inherit)", cursor: "pointer", font: "inherit",
|
|
960
|
+
fontSize: "12px", lineHeight: "1.6", whiteSpace: "nowrap", opacity: 0.85,
|
|
961
|
+
},
|
|
962
|
+
tabOn: {
|
|
963
|
+
background: "var(--dsw-alias-bg-layer-2, rgba(128,128,128,0.18))",
|
|
964
|
+
color: "var(--dsw-alias-label-primary, inherit)", fontWeight: "600", opacity: 1,
|
|
965
|
+
},
|
|
966
|
+
// 未读数用中性强调色而不是报错红:每一封未读都标红会让人以为出错了
|
|
967
|
+
badge: {
|
|
968
|
+
minWidth: "16px", padding: "0 4px", borderRadius: "999px",
|
|
969
|
+
background: "var(--dsw-alias-brand-primary, #3b82f6)", color: "#fff",
|
|
970
|
+
fontSize: "10px", lineHeight: "16px", textAlign: "center", fontWeight: "600",
|
|
971
|
+
},
|
|
972
|
+
spacer: { flex: "1 1 auto" },
|
|
973
|
+
meta: {
|
|
974
|
+
color: "var(--dsw-alias-label-secondary, inherit)", whiteSpace: "nowrap",
|
|
975
|
+
overflow: "hidden", textOverflow: "ellipsis",
|
|
976
|
+
},
|
|
977
|
+
btn: {
|
|
978
|
+
font: "inherit", fontSize: "11px", padding: "1px 8px", cursor: "pointer", borderRadius: "5px",
|
|
979
|
+
border: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,0.3))",
|
|
980
|
+
background: "var(--dsw-alias-bg-layer-2, transparent)", color: "inherit", whiteSpace: "nowrap",
|
|
981
|
+
},
|
|
982
|
+
// 图标按钮:方块热区 + 只画图标(展开/收起、立刻同步)
|
|
983
|
+
iconBtn: {
|
|
984
|
+
display: "inline-flex", alignItems: "center", justifyContent: "center",
|
|
985
|
+
width: "22px", height: "22px", padding: 0, cursor: "pointer", borderRadius: "6px",
|
|
986
|
+
border: "none", background: "transparent",
|
|
987
|
+
color: "var(--dsw-alias-label-secondary, inherit)", flex: "0 0 auto",
|
|
988
|
+
},
|
|
989
|
+
// ⚠️ 限高 + 内部滚动 = 展开时**只压矮聊天区**,绝不覆盖历史对话。
|
|
990
|
+
// 需求 5(2026-10-30):面板做成**动画包装**(maxHeight 0⇄min(38vh,320px) + 淡入),
|
|
991
|
+
// 点[展开]时平滑拉出;内容只在展开时挂载,收起零 DOM。动画层只管高度/透明度,
|
|
992
|
+
// padding/边框放内层,避免 padding 撑住 max-height:0 导致收不干净。
|
|
993
|
+
panelAnim: { overflow: "hidden", transition: "max-height 0.22s ease, opacity 0.18s ease" },
|
|
994
|
+
panelOpen: { maxHeight: "min(38vh, 320px)", opacity: 1, overflowY: "auto" },
|
|
995
|
+
panelClosed: { maxHeight: "0px", opacity: 0, overflowY: "hidden" },
|
|
996
|
+
panelInner: {
|
|
997
|
+
borderTop: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,0.25))",
|
|
998
|
+
padding: "6px 8px 8px",
|
|
999
|
+
},
|
|
1000
|
+
// (2026-11-29)网格相关的样式(grid/gridCell/gridHead/gridRow/acctRow/tag/tagHot/tagDim)
|
|
1001
|
+
// 随"Accounts Monitor"网格一起删除 —— 账号维度只由页签承担,别留没人用的死样式。
|
|
1002
|
+
mailRow: {
|
|
1003
|
+
display: "block", width: "100%", textAlign: "left", padding: "4px 6px", borderRadius: "6px",
|
|
1004
|
+
border: "1px solid transparent", background: "transparent", color: "inherit",
|
|
1005
|
+
font: "inherit", fontSize: "12px", cursor: "pointer",
|
|
1006
|
+
},
|
|
1007
|
+
mailRowHover: { background: "var(--dsw-alias-bg-layer-2, rgba(128,128,128,0.12))" },
|
|
1008
|
+
subject: { fontWeight: "600", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
|
|
1009
|
+
sub: { fontSize: "11px", color: "var(--dsw-alias-label-secondary, inherit)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
|
|
1010
|
+
// 需求 6(2026-10-30):展开面板去日志化的一组样式
|
|
1011
|
+
// 2026-10-30 需求:摘要拉平成横向单行 —— nowrap,每段独立省略号,悬停 title 看全文
|
|
1012
|
+
statusLine: { display: "flex", flexWrap: "nowrap", alignItems: "center", gap: "0 8px", fontSize: "11px", color: "var(--dsw-alias-label-secondary, inherit)", marginBottom: "6px", overflow: "hidden" },
|
|
1013
|
+
statusSeg: { whiteSpace: "nowrap", minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", flexShrink: 1, flexBasis: "auto" },
|
|
1014
|
+
metaLine: { display: "flex", flexWrap: "wrap", fontSize: "11px", color: "var(--dsw-alias-label-secondary, inherit)", overflow: "hidden", whiteSpace: "nowrap" },
|
|
1015
|
+
// 账户色点(需求 2026-11-29):每个账户一个稳定色,页签/邮件行共用同一个颜色,
|
|
1016
|
+
// 用户在混排列表里一眼就能分出"这封是哪个邮箱的",不用去读小字。
|
|
1017
|
+
acctDot: { width: "7px", height: "7px", borderRadius: "50%", flex: "0 0 auto", display: "inline-block" },
|
|
1018
|
+
// 未读/已读的视觉分层(需求 2026-11-29):未读 = 账户色左侧竖条 + 主色文字 + 加粗;
|
|
1019
|
+
// 已读 = 整体降透明度、不加竖条。**只用颜色深浅区分,不靠"●"符号**(符号在等宽字体下很脏)。
|
|
1020
|
+
mailRowUnread: { borderLeft: "3px solid currentColor", paddingLeft: "5px" },
|
|
1021
|
+
mailRowRead: { borderLeft: "3px solid transparent", paddingLeft: "5px", opacity: 0.55 },
|
|
1022
|
+
markBtn: {
|
|
1023
|
+
font: "inherit", fontSize: "10.5px", padding: "0 6px", borderRadius: "999px", cursor: "pointer",
|
|
1024
|
+
border: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,0.35))",
|
|
1025
|
+
background: "transparent", color: "var(--dsw-alias-label-secondary, inherit)",
|
|
1026
|
+
whiteSpace: "nowrap", flex: "0 0 auto",
|
|
1027
|
+
},
|
|
1028
|
+
hint: { fontSize: "11px", marginTop: "4px", color: "var(--dsw-alias-label-secondary, inherit)" },
|
|
1029
|
+
err: { color: "var(--dsw-alias-state-error-primary, #c0392b)", fontSize: "11px", marginTop: "4px" },
|
|
1030
|
+
// 2026-11-29 需求:带附件的邮件行出现 📎 徽标,点开即看(多个附件时展开一行名字)。
|
|
1031
|
+
attachBadge: {
|
|
1032
|
+
font: "inherit", fontSize: "11px", padding: "0 5px", borderRadius: "999px", cursor: "pointer",
|
|
1033
|
+
border: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,0.35))",
|
|
1034
|
+
background: "transparent", color: "var(--dsw-alias-label-secondary, inherit)",
|
|
1035
|
+
whiteSpace: "nowrap", flex: "0 0 auto",
|
|
1036
|
+
},
|
|
1037
|
+
attachStrip: { display: "flex", flexWrap: "wrap", gap: "4px", marginTop: "3px", paddingLeft: "2px" },
|
|
1038
|
+
attachItem: {
|
|
1039
|
+
font: "inherit", fontSize: "10.5px", padding: "0 6px", borderRadius: "999px", cursor: "pointer",
|
|
1040
|
+
border: "1px dashed var(--dsw-alias-border-l1, rgba(128,128,128,0.35))",
|
|
1041
|
+
background: "transparent", color: "var(--dsw-alias-label-secondary, inherit)",
|
|
1042
|
+
maxWidth: "180px", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap",
|
|
1043
|
+
},
|
|
1044
|
+
attachItemOn: {
|
|
1045
|
+
borderStyle: "solid",
|
|
1046
|
+
borderColor: "var(--dsw-alias-brand-primary, rgba(80,120,255,0.65))",
|
|
1047
|
+
color: "var(--dsw-alias-label-primary, inherit)",
|
|
1048
|
+
},
|
|
1049
|
+
// 2026-11-30 真机反馈:点 📎 变成"另存为"、多附件来回开关窗口很烦
|
|
1050
|
+
// → 改成面板内嵌预览(图片 <img>、PDF/文本/HTML <iframe>,其它类型只给下载)。
|
|
1051
|
+
previewBox: {
|
|
1052
|
+
marginTop: "6px", padding: "6px",
|
|
1053
|
+
border: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,0.35))",
|
|
1054
|
+
borderRadius: "8px",
|
|
1055
|
+
background: "var(--dsw-alias-bg-layer-2, rgba(128,128,128,0.06))",
|
|
1056
|
+
},
|
|
1057
|
+
previewHead: {
|
|
1058
|
+
display: "flex", alignItems: "center", gap: "6px", minWidth: 0,
|
|
1059
|
+
fontSize: "11px", marginBottom: "4px",
|
|
1060
|
+
},
|
|
1061
|
+
previewName: {
|
|
1062
|
+
flex: "1 1 auto", minWidth: 0,
|
|
1063
|
+
overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap",
|
|
1064
|
+
fontWeight: 600,
|
|
1065
|
+
},
|
|
1066
|
+
previewImg: {
|
|
1067
|
+
display: "block", maxWidth: "100%", maxHeight: "260px", margin: "0 auto",
|
|
1068
|
+
borderRadius: "6px", objectFit: "contain",
|
|
1069
|
+
},
|
|
1070
|
+
previewFrame: {
|
|
1071
|
+
width: "100%", height: "260px", border: "0", borderRadius: "6px",
|
|
1072
|
+
background: "#fff",
|
|
1073
|
+
},
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
/**
|
|
1077
|
+
* 一个 12×12 的线性图标(手写 SVG,不引第三方图标包 —— 客户端半边只能 require
|
|
1078
|
+
* 外壳冻结平台表里的模块,图标包不在表里)。
|
|
1079
|
+
* @param {"chevronDown"|"chevronUp"|"refresh"} name - 图标名。
|
|
1080
|
+
*/
|
|
1081
|
+
function icon(name) {
|
|
1082
|
+
const common = {
|
|
1083
|
+
width: 12, height: 12, viewBox: "0 0 16 16", fill: "none",
|
|
1084
|
+
stroke: "currentColor", strokeWidth: 1.6, strokeLinecap: "round", strokeLinejoin: "round",
|
|
1085
|
+
"aria-hidden": "true", focusable: "false", style: { flex: "0 0 auto", display: "block" },
|
|
1086
|
+
};
|
|
1087
|
+
const paths = name === "chevronUp" ? [["path", { d: "M4 10l4-4 4 4" }]]
|
|
1088
|
+
: name === "refresh" ? [["path", { d: "M13.5 8a5.5 5.5 0 1 1-1.6-3.9" }], ["path", { d: "M13.5 2.5V5H11" }]]
|
|
1089
|
+
: [["path", { d: "M4 6l4 4 4-4" }]];
|
|
1090
|
+
return h("svg", common, paths.map(([tag, attrs], i) => h(tag, { key: i, ...attrs })));
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
/**
|
|
1094
|
+
* 顶栏左侧的**指标块**(纯函数):把汇总拆成"数字 + 单位"的对齐小块,而不是一句话。
|
|
1095
|
+
* 为什么要拆:`3 封未读 · 共 12` 这种句子,① 位数一变整行就跟着挪;② 单位和数字同权重,
|
|
1096
|
+
* 扫读时抓不到重点;③ 和页签徽标、右侧 meta 三处重复。
|
|
1097
|
+
* 规则:未读 > 0 才出未读(为 0 时数字没有信息量,只留"共 N");有新留痕出最显眼的"新"块。
|
|
1098
|
+
* @param {object} view - /status 视图。
|
|
1099
|
+
* @param {object} sel - summaryFor() 的结果(选中账号或全局)。
|
|
1100
|
+
* @param {number} [unseen] - 未看留痕数。
|
|
1101
|
+
*/
|
|
1102
|
+
function summaryParts(view, sel, unseen = 0) {
|
|
1103
|
+
const parts = [];
|
|
1104
|
+
const news = Number(unseen ?? 0);
|
|
1105
|
+
if (news > 0) parts.push({ kind: "new", num: String(news), unit: "新" });
|
|
1106
|
+
const unread = Number(sel?.unread ?? 0);
|
|
1107
|
+
if (unread > 0) parts.push({ kind: "unread", num: String(unread), unit: "未读" });
|
|
1108
|
+
parts.push({ kind: "total", num: String(Number(sel?.messages ?? 0)), unit: "共" });
|
|
1109
|
+
return parts;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/** 汇总口径:选中某个账号 → 该账号的合计;否则 → 全局合计(纯函数)。 */
|
|
1113
|
+
function summaryFor(view, account) {
|
|
1114
|
+
const c = view?.counts ?? {};
|
|
1115
|
+
const accounts = Array.isArray(view?.accounts) ? view.accounts : [];
|
|
1116
|
+
const key = String(account ?? "");
|
|
1117
|
+
if (key) {
|
|
1118
|
+
const row = accounts.find((a) => String(a?.account ?? "") === key);
|
|
1119
|
+
return {
|
|
1120
|
+
account: key, alias: row?.alias || key,
|
|
1121
|
+
unread: Number(row?.unread ?? 0), messages: Number(row?.messages ?? 0), scoped: true,
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
return {
|
|
1125
|
+
account: null, alias: "", unread: Number(c.unread ?? 0),
|
|
1126
|
+
messages: Number(c.messages ?? 0), scoped: false,
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/** 账户配色(需求 2026-11-29):按 `view.accounts` 的**固定顺序**取色,同一个账户在
|
|
1131
|
+
* 页签与每一封邮件行上始终是同一个颜色(顺序不变 ⇒ 颜色不会跳动)。 */
|
|
1132
|
+
const ACCOUNT_ACCENTS = ["#3b82f6", "#10b981", "#f59e0b", "#a855f7", "#ec4899", "#0891b2"];
|
|
1133
|
+
function accountAccent(view, account) {
|
|
1134
|
+
const key = String(account ?? "");
|
|
1135
|
+
if (!key) return "";
|
|
1136
|
+
const accounts = Array.isArray(view?.accounts) ? view.accounts : [];
|
|
1137
|
+
const i = accounts.findIndex((a) => String(a?.account ?? "") === key);
|
|
1138
|
+
if (i < 0) return "";
|
|
1139
|
+
return ACCOUNT_ACCENTS[i % ACCOUNT_ACCENTS.length];
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
/** 账号页签(纯函数)。**单账号不返回页签** —— 聚合行已够用,不加噪音。 */
|
|
1143
|
+
function accountTabs(view, selected) {
|
|
1144
|
+
const accounts = Array.isArray(view?.accounts) ? view.accounts : [];
|
|
1145
|
+
if (accounts.length < 2) return [];
|
|
1146
|
+
const all = summaryFor(view, ALL_ACCOUNTS);
|
|
1147
|
+
const tabs = [{
|
|
1148
|
+
key: ALL_ACCOUNTS, label: "全部", alias: "", account: null,
|
|
1149
|
+
unread: all.unread, messages: all.messages, active: !selected, accent: "",
|
|
1150
|
+
}];
|
|
1151
|
+
for (const a of accounts) {
|
|
1152
|
+
const key = String(a?.account ?? "");
|
|
1153
|
+
if (!key) continue;
|
|
1154
|
+
const s = summaryFor(view, key);
|
|
1155
|
+
tabs.push({ key, label: a?.alias || key, alias: a?.alias || key, account: key, unread: s.unread, messages: s.messages, active: key === selected, accent: accountAccent(view, key) });
|
|
1156
|
+
}
|
|
1157
|
+
return tabs;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/** 插进输入框的坐标文本:参数名直写,模型一看就知道该调 mailbox_read(account, folder, uid)。 */
|
|
1161
|
+
function mailInsertText(m) {
|
|
1162
|
+
const base = `【邮件】account=${m?.account ?? "?"} folder=${m?.folder ?? "?"} uid=${m?.uid ?? "?"}`;
|
|
1163
|
+
const subject = String(m?.subject ?? "").trim();
|
|
1164
|
+
return subject ? `${base} — ${subject}` : base;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
/** 剪贴板复制(浏览器里才有)。返回是否真的写进去了。 */
|
|
1168
|
+
function clipboardCopy(text) {
|
|
1169
|
+
try {
|
|
1170
|
+
const clip = typeof navigator !== "undefined" ? navigator.clipboard : null;
|
|
1171
|
+
if (!clip || typeof clip.writeText !== "function") return false;
|
|
1172
|
+
const p = clip.writeText(text);
|
|
1173
|
+
if (p && typeof p.catch === "function") p.catch(() => {});
|
|
1174
|
+
return true;
|
|
1175
|
+
} catch { return false; }
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
1179
|
+
* 把"这一轮同步到底抓到了什么"说成人话(纯函数,好测)。
|
|
1180
|
+
* 0 封也要明说"同步过了",否则用户分不清"同步了没新邮件"和"按钮没生效"。
|
|
1181
|
+
* @param {{fetched?:number, failures?:number}} [after] - 宿主 /check 回传的 after。
|
|
1182
|
+
*/
|
|
1183
|
+
function checkHint(after) {
|
|
1184
|
+
const fetched = Number(after?.fetched ?? 0);
|
|
1185
|
+
const failures = Number(after?.failures ?? 0);
|
|
1186
|
+
const head = fetched > 0 ? `已同步:${fetched} 封新邮件` : "已同步:没有新邮件";
|
|
1187
|
+
return failures > 0 ? `${head} · ${failures} 个文件夹失败` : head;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* 把邮件坐标送进输入框:优先走输入框动作面(captureInsertion + insertText),
|
|
1192
|
+
* 拿不到就退回复制。返回 {ok, mode:"insert"|"copy"|"fail", text}(纯函数,好测)。
|
|
1193
|
+
*/
|
|
1194
|
+
function insertMailRef(actions, m, copy) {
|
|
1195
|
+
const text = mailInsertText(m);
|
|
1196
|
+
try {
|
|
1197
|
+
if (actions && typeof actions.captureInsertion === "function" && typeof actions.insertText === "function") {
|
|
1198
|
+
const span = actions.captureInsertion();
|
|
1199
|
+
if (span && typeof span === "object" && actions.insertText(text, span) !== false) {
|
|
1200
|
+
return { ok: true, mode: "insert", text };
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
} catch { /* 落到复制 */ }
|
|
1204
|
+
try {
|
|
1205
|
+
if (typeof copy === "function" && copy(text) !== false) return { ok: true, mode: "copy", text };
|
|
1206
|
+
} catch { /* ignore */ }
|
|
1207
|
+
return { ok: false, mode: "fail", text };
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
/** 对话框上方的邮件提示栏。 */
|
|
1211
|
+
function MailboxDockBar(props) {
|
|
1212
|
+
const tt = (key, fallback) => {
|
|
1213
|
+
try { return props?.t ? props.t(key) : (DICT.zh[key] ?? fallback ?? key); } catch { return fallback ?? key; }
|
|
1214
|
+
};
|
|
1215
|
+
const actions = props?.inputActions ?? null;
|
|
1216
|
+
// hook 顺序固定(离线测试按这个顺序预置):view / error / account / expanded / busy / hint / hover
|
|
1217
|
+
const [view, setView] = React.useState(null);
|
|
1218
|
+
const [error, setError] = React.useState(null);
|
|
1219
|
+
const [account, setAccount] = React.useState(ALL_ACCOUNTS);
|
|
1220
|
+
const [expanded, setExpanded] = React.useState(false);
|
|
1221
|
+
const [busy, setBusy] = React.useState(false);
|
|
1222
|
+
const [hint, setHint] = React.useState("");
|
|
1223
|
+
const [hover, setHover] = React.useState("");
|
|
1224
|
+
// 未看提示「已看」的淡出动画状态(需求 6):Set<rowKey>,行在集合里 = 正在淡出
|
|
1225
|
+
const [acking, setAcking] = React.useState(null);
|
|
1226
|
+
// (2026-11-29 追加,只在上面这些之后 —— 离线测试按前 8 个 hook 预置 seed)
|
|
1227
|
+
// 附件:attachFor = 当前展开附件清单的行键,attachList = 那一行的附件元数据
|
|
1228
|
+
const [attachFor, setAttachFor] = React.useState("");
|
|
1229
|
+
const [attachList, setAttachList] = React.useState([]);
|
|
1230
|
+
|
|
1231
|
+
// (2026-11-30 再追加)附件内嵌预览:不再开新窗口(那样 PDF 往往直接变"另存为",
|
|
1232
|
+
// 多附件还得来回开关窗口)。preview = { mail, list, index, name, contentType, size, kind, url, busy, error }
|
|
1233
|
+
const [preview, setPreview] = React.useState(null);
|
|
1234
|
+
|
|
1235
|
+
/**
|
|
1236
|
+
* 判断怎么预览。浏览器只有少数类型肯内嵌显示,其余(office/zip/eml…)一律只给下载,
|
|
1237
|
+
* 否则用户看到的还是"另存为"——这正是 2026-11-30 反馈的现象。
|
|
1238
|
+
* @param {string} contentType - 服务器给的 MIME(可能为空/ octet-stream)。
|
|
1239
|
+
* @param {string} name - 文件名,用于按扩展名兜底。
|
|
1240
|
+
* @returns {"image"|"pdf"|"text"|"html"|"other"}
|
|
1241
|
+
*/
|
|
1242
|
+
const previewKindOf = (contentType, name) => {
|
|
1243
|
+
const ct = String(contentType ?? "").toLowerCase().split(";")[0].trim();
|
|
1244
|
+
const ext = String(name ?? "").toLowerCase().match(/\.([a-z0-9]+)$/)?.[1] ?? "";
|
|
1245
|
+
if (ct.startsWith("image/")) return "image";
|
|
1246
|
+
if (ct === "application/pdf") return "pdf";
|
|
1247
|
+
if (ct === "text/html" || ct === "application/xhtml+xml") return "html";
|
|
1248
|
+
if (ct.startsWith("text/")) return "text";
|
|
1249
|
+
if (ct === "application/json" || ct === "application/xml" || ct === "text/xml") return "text";
|
|
1250
|
+
if (["png", "jpg", "jpeg", "gif", "webp", "bmp", "avif", "svg"].includes(ext)) return "image";
|
|
1251
|
+
if (ext === "pdf") return "pdf";
|
|
1252
|
+
if (["html", "htm"].includes(ext)) return "html";
|
|
1253
|
+
if (["txt", "log", "csv", "md", "json", "xml", "yaml", "yml", "ini", "ics"].includes(ext)) return "text";
|
|
1254
|
+
return "other";
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1257
|
+
const freePreviewUrl = (p) => {
|
|
1258
|
+
if (p?.url) { try { URL.revokeObjectURL(p.url); } catch { /* 忽略 */ } }
|
|
1259
|
+
};
|
|
1260
|
+
|
|
1261
|
+
/** 关掉预览(顺手回收 blob URL,否则整个会话都在泄漏内存)。 */
|
|
1262
|
+
const closePreview = () => {
|
|
1263
|
+
setPreview((prev) => { freePreviewUrl(prev); return null; });
|
|
1264
|
+
setAttachFor("");
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
/** 把字节塞进 `<a download>`:唯一可靠的"存到本地",不依赖弹窗权限。 */
|
|
1268
|
+
const downloadAttachment = (p) => {
|
|
1269
|
+
if (!p?.url) { setHint("还没取到文件内容,稍等或重试"); return; }
|
|
1270
|
+
try {
|
|
1271
|
+
const a = document.createElement("a");
|
|
1272
|
+
a.href = p.url;
|
|
1273
|
+
a.download = String(p.name || `attachment-${p.index ?? 1}`);
|
|
1274
|
+
a.rel = "noopener";
|
|
1275
|
+
a.style.display = "none";
|
|
1276
|
+
document.body?.appendChild?.(a);
|
|
1277
|
+
a.click();
|
|
1278
|
+
a.remove?.();
|
|
1279
|
+
setHint(`已下载 ${a.download}(在下载目录里找)`);
|
|
1280
|
+
} catch (e) { setHint(`下载失败:${e?.message ?? e}`); }
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
/**
|
|
1284
|
+
* 取一封邮件的某个附件并在面板里预览。
|
|
1285
|
+
* @param {object} m - 邮件行(recent 项)。
|
|
1286
|
+
* @param {Array} list - 该邮件的附件清单(用于切换)。
|
|
1287
|
+
* @param {number} index - 附件序号(1 起)。
|
|
1288
|
+
*/
|
|
1289
|
+
const showAttachment = async (m, list, index) => {
|
|
1290
|
+
const meta = (Array.isArray(list) ? list : []).find((a) => Number(a?.index) === Number(index)) ?? {};
|
|
1291
|
+
setHint("");
|
|
1292
|
+
setPreview((prev) => {
|
|
1293
|
+
freePreviewUrl(prev);
|
|
1294
|
+
return {
|
|
1295
|
+
mail: m, list: Array.isArray(list) ? list : [], index,
|
|
1296
|
+
name: String(meta.name ?? ""), size: Number(meta.size ?? 0) || 0,
|
|
1297
|
+
contentType: String(meta.contentType ?? ""),
|
|
1298
|
+
kind: previewKindOf(meta.contentType, meta.name),
|
|
1299
|
+
url: "", busy: true, error: "",
|
|
1300
|
+
};
|
|
1301
|
+
});
|
|
1302
|
+
const r = await bridgeCall("/attachment", { account: m.account, folder: m.folder, uid: m.uid, index });
|
|
1303
|
+
if (!r?.ok) {
|
|
1304
|
+
setPreview((prev) => (prev ? {
|
|
1305
|
+
...prev, busy: false,
|
|
1306
|
+
error: r?.code === "attachment-too-large"
|
|
1307
|
+
? (r.message || "附件超过预览上限,点「下载」或先 mailbox_read saveAttachments=true 落盘")
|
|
1308
|
+
: (r?.message || "读不到附件内容"),
|
|
1309
|
+
} : prev));
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
const v = r.value ?? {};
|
|
1313
|
+
let url = "";
|
|
1314
|
+
let err = "";
|
|
1315
|
+
try {
|
|
1316
|
+
const bin = atob(String(v.base64 ?? ""));
|
|
1317
|
+
const bytes = new Uint8Array(bin.length);
|
|
1318
|
+
for (let i = 0; i < bin.length; i += 1) bytes[i] = bin.charCodeAt(i);
|
|
1319
|
+
const ct = String(v.contentType || meta.contentType || "application/octet-stream");
|
|
1320
|
+
url = URL.createObjectURL(new Blob([bytes], { type: ct }));
|
|
1321
|
+
} catch (e) {
|
|
1322
|
+
err = `附件解码失败:${e?.message ?? e}`;
|
|
1323
|
+
}
|
|
1324
|
+
setPreview((prev) => {
|
|
1325
|
+
if (!prev || Number(prev.index) !== Number(index)) { if (url) { try { URL.revokeObjectURL(url); } catch { /* 忽略 */ } } return prev; }
|
|
1326
|
+
freePreviewUrl(prev);
|
|
1327
|
+
const name = String(v.name ?? prev.name ?? "");
|
|
1328
|
+
const ct = String(v.contentType ?? prev.contentType ?? "");
|
|
1329
|
+
return {
|
|
1330
|
+
...prev, busy: false, url, error: err, name, contentType: ct,
|
|
1331
|
+
size: Number(v.size ?? prev.size) || 0,
|
|
1332
|
+
kind: previewKindOf(ct, name),
|
|
1333
|
+
};
|
|
1334
|
+
});
|
|
1335
|
+
};
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* 📎 徽标:拉清单 → 展开该行的附件名字条 → 立刻预览第一个。
|
|
1339
|
+
* 不再开新窗口;多附件时点名字条切换,单附件也能直接看到内容。
|
|
1340
|
+
*/
|
|
1341
|
+
const openAttachments = async (m, ev) => {
|
|
1342
|
+
ev?.stopPropagation?.();
|
|
1343
|
+
const key = `${m.account}/${m.folder}/${m.uid}`;
|
|
1344
|
+
if (attachFor === key) { closePreview(); return; }
|
|
1345
|
+
setHint("");
|
|
1346
|
+
setPreview((prev) => { freePreviewUrl(prev); return null; });
|
|
1347
|
+
const r = await bridgeCall("/attachments", { account: m.account, folder: m.folder, uid: m.uid });
|
|
1348
|
+
if (!r?.ok) { setHint(r?.message || "读不到附件清单"); return; }
|
|
1349
|
+
const list = Array.isArray(r.value?.attachments) ? r.value.attachments : [];
|
|
1350
|
+
if (!list.length) { setHint("这封邮件没有附件"); return; }
|
|
1351
|
+
setAttachFor(key);
|
|
1352
|
+
setAttachList(list);
|
|
1353
|
+
await showAttachment(m, list, list[0].index);
|
|
1354
|
+
};
|
|
1355
|
+
|
|
1356
|
+
React.useEffect(() => {
|
|
1357
|
+
let alive = true;
|
|
1358
|
+
const load = async () => {
|
|
1359
|
+
const r = await bridgeCall("/status", { limit: DOCK_RECENT_LIMIT, account });
|
|
1360
|
+
if (!alive) return;
|
|
1361
|
+
if (r.ok) {
|
|
1362
|
+
const v = r.value ?? null;
|
|
1363
|
+
setView(v);
|
|
1364
|
+
setError(null);
|
|
1365
|
+
// 选中的账号被删了 → 回到"全部"(否则面板一直空着,用户以为坏了)
|
|
1366
|
+
if (account && !(Array.isArray(v?.accounts) ? v.accounts : []).some((a) => String(a?.account ?? "") === account)) {
|
|
1367
|
+
setAccount(ALL_ACCOUNTS);
|
|
1368
|
+
}
|
|
1369
|
+
} else setError(r);
|
|
1370
|
+
};
|
|
1371
|
+
const poller = makeBarPoller({ load });
|
|
1372
|
+
poller.attach(); // 隐藏态启动则只挂监听,不轮询;变可见时自己补一次
|
|
1373
|
+
void load();
|
|
1374
|
+
return () => { alive = false; poller.detach(); };
|
|
1375
|
+
}, [account]);
|
|
1376
|
+
|
|
1377
|
+
const s = barSummary(view, error);
|
|
1378
|
+
if (s.silent && !view) return null; // 这个 profile 没有 mailbox:不画任何东西
|
|
1379
|
+
|
|
1380
|
+
const accounts = Array.isArray(view?.accounts) ? view.accounts : [];
|
|
1381
|
+
const active = account && accounts.some((a) => String(a?.account ?? "") === account) ? account : ALL_ACCOUNTS;
|
|
1382
|
+
const tabs = accountTabs(view, active);
|
|
1383
|
+
const sel = summaryFor(view, active);
|
|
1384
|
+
// 双保险:宿主新版本会按 account 过滤 recent;旧宿主忽略过滤、返回全局列表 ——
|
|
1385
|
+
// 这里再按账号筛一次,切账号在任何宿主版本上都显示对的那一批。
|
|
1386
|
+
const rows = (Array.isArray(view?.recent) ? view.recent : [])
|
|
1387
|
+
.filter((m) => !active || String(m?.account ?? "") === active);
|
|
1388
|
+
const c = view?.counts ?? {};
|
|
1389
|
+
// (2026-11-29)原先这里算 accountGridCells(view) 画「多账户 × 多文件夹」网格,
|
|
1390
|
+
// 与账号页签信息重复且整块不可操作,已删。accountGridCells 仍保留为纯函数
|
|
1391
|
+
// (__test 里有断言、也留给将来的"账号详情"复用),只是不再参与渲染。
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* 立刻检查 = **真的同步一轮**(宿主一侧走 watcher.tick(),与定时轮次同一条路径),
|
|
1395
|
+
* 然后把"这一轮到底抓到了什么"如实说出来:
|
|
1396
|
+
* · 成功 → 「已同步:N 封新邮件 · M 个文件夹」(0 封也说清楚是同步过了)
|
|
1397
|
+
* · 失败 → 「同步失败:<宿主给的原因>」(watcher 没运行/已暂停/抓取报错)
|
|
1398
|
+
* ⚠️ 旧实现把失败吞掉了:失败时 setError(r),紧接着的 /status 成功又 setError(null),
|
|
1399
|
+
* 于是点了按钮**什么都不显示**,看起来像"只是刷新了历史状态"。
|
|
1400
|
+
*/
|
|
1401
|
+
const doCheck = async () => {
|
|
1402
|
+
setBusy(true);
|
|
1403
|
+
setHint("");
|
|
1404
|
+
try {
|
|
1405
|
+
const r = await bridgeCall("/check", {});
|
|
1406
|
+
if (!r.ok) {
|
|
1407
|
+
setError(r);
|
|
1408
|
+
setHint(`${tt("dock_check_failed", "同步失败:")} ${r.message ?? r.code ?? "未知原因"}`);
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
if (r.value?.status) setView(r.value.status);
|
|
1412
|
+
setError(null);
|
|
1413
|
+
// 本轮过滤后的账号再拉一次,保证列表与当前页签一致
|
|
1414
|
+
const after = await bridgeCall("/status", { limit: DOCK_RECENT_LIMIT, account: active });
|
|
1415
|
+
if (after.ok) setView(after.value ?? null);
|
|
1416
|
+
setHint(checkHint(r.value?.after));
|
|
1417
|
+
} catch (e) {
|
|
1418
|
+
setHint(`${tt("dock_check_failed", "同步失败:")} ${String(e?.message ?? e)}`);
|
|
1419
|
+
} finally {
|
|
1420
|
+
setBusy(false);
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
|
|
1424
|
+
const pickMail = (m) => {
|
|
1425
|
+
const res = insertMailRef(actions, m, (text) => clipboardCopy(text));
|
|
1426
|
+
setHint(res.mode === "insert" ? tt("dock_inserted", "已插进输入框")
|
|
1427
|
+
: res.mode === "copy" ? tt("dock_copied", "已复制坐标(请粘贴到输入框)")
|
|
1428
|
+
: tt("dock_failed", "插入失败,请手动复制坐标"));
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
// 需求 5(2026-10-30):收起态 = 严格单行流。右侧只放「提示 + 双图标按钮」;
|
|
1432
|
+
// 未读/合计/页签/Scope 全部退到展开面板,顶行不再复述数字。
|
|
1433
|
+
const blocks = collapsedBlocks(view);
|
|
1434
|
+
const lc2 = view?.lastCheck ?? null;
|
|
1435
|
+
const syncTitle = lc2
|
|
1436
|
+
? `上次同步:${formatAgo(lc2.agoSeconds)} · 抓到 ${lc2.fetched ?? 0} 封${(lc2.failures?.length ?? 0) ? `,${lc2.failures.length} 个文件夹失败` : ""}`
|
|
1437
|
+
: "还没跑过第一轮";
|
|
1438
|
+
// 悬停账号块 = 分文件夹明细(accountsRows 的多行文本),收起时不必占宽度
|
|
1439
|
+
const accountsTitle = accountsRows(view).join("\n") || "全部账户的未读/合计在展开面板里";
|
|
1440
|
+
|
|
1441
|
+
return h("div", { style: D.wrap, "data-mailbox-dock": "" },
|
|
1442
|
+
h("div", { style: D.card },
|
|
1443
|
+
// 顶行(始终可见,严格单行):状态点 + 三块状态 + 提示块 + 双图标按钮
|
|
1444
|
+
h("div", { style: D.row },
|
|
1445
|
+
// ① 状态点(可点开合):只承担"健康度 + 开合"
|
|
1446
|
+
h("button", {
|
|
1447
|
+
type: "button", style: D.pill, title: s.title, "aria-expanded": expanded,
|
|
1448
|
+
"aria-label": `${s.text || tt("dock_title", "邮箱")} — ${expanded ? tt("dock_collapse", "收起") : tt("dock_expand", "展开")}`,
|
|
1449
|
+
onClick: () => setExpanded((v) => !v),
|
|
1450
|
+
},
|
|
1451
|
+
h("span", { style: { ...D.dot, background: TONE[s.tone] ?? TONE.idle } })),
|
|
1452
|
+
// ②③④ 单行状态块组:🔄 监控 | ⏱️ 上次同步 | 📧 分账户未读
|
|
1453
|
+
h("div", { style: D.flow },
|
|
1454
|
+
h("span", { style: { ...D.blk, ...(blocks.running ? {} : D.blkDim) }, title: "后台自动检测状态" }, blocks.monitor),
|
|
1455
|
+
h("span", { style: D.sep }),
|
|
1456
|
+
h("span", { style: D.blk, title: syncTitle }, blocks.sync),
|
|
1457
|
+
blocks.accounts.length ? [
|
|
1458
|
+
h("span", { key: "sep-acc", style: D.sep }),
|
|
1459
|
+
h("span", { key: "acc", style: D.blk, title: accountsTitle },
|
|
1460
|
+
"📧 账户: ",
|
|
1461
|
+
...blocks.accounts.flatMap((a, i) => {
|
|
1462
|
+
const seg = h("span", {
|
|
1463
|
+
key: `acc-${a.label}`, style: a.unread > 0 ? D.blkHot : D.blkDim,
|
|
1464
|
+
}, `${a.label} (${a.unread == null ? "?" : a.unread})`);
|
|
1465
|
+
return i === 0 ? [seg] : [h("span", { key: `adot-${i}`, style: D.blkDim }, " · "), seg];
|
|
1466
|
+
})),
|
|
1467
|
+
] : null),
|
|
1468
|
+
// 右侧:提示块(有未看 → 高亮) + 同步/展开
|
|
1469
|
+
h("div", { style: D.flowRight },
|
|
1470
|
+
h("span", {
|
|
1471
|
+
style: { ...D.blk, ...(blocks.hint.unseen > 0 ? D.blkHot : D.blkDim) },
|
|
1472
|
+
title: blocks.hint.unseen > 0 ? "展开面板查看逐封可点选的未看提示" : "展开查看最近邮件/账户明细/未看提示",
|
|
1473
|
+
}, blocks.hint.text),
|
|
1474
|
+
h("button", {
|
|
1475
|
+
type: "button", style: D.iconBtn, disabled: busy,
|
|
1476
|
+
title: busy ? tt("bar_checking", "检查中…") : tt("dock_check_title", "立刻同步邮箱(真的去连服务器抓一轮)"),
|
|
1477
|
+
"aria-label": busy ? tt("bar_checking", "检查中…") : tt("bar_check", "立刻检查"),
|
|
1478
|
+
onClick: () => { void doCheck(); },
|
|
1479
|
+
}, icon("refresh")),
|
|
1480
|
+
h("button", {
|
|
1481
|
+
type: "button", style: D.iconBtn, "aria-expanded": expanded,
|
|
1482
|
+
title: expanded ? tt("dock_collapse", "收起") : tt("dock_expand", "展开"),
|
|
1483
|
+
"aria-label": expanded ? tt("dock_collapse", "收起") : tt("dock_expand", "展开"),
|
|
1484
|
+
onClick: () => setExpanded((v) => !v),
|
|
1485
|
+
}, icon(expanded ? "chevronDown" : "chevronUp")))),
|
|
1486
|
+
// 展开面板:动画包装(maxHeight 0⇄min(38vh,320px)),内容展开才挂载 → 平滑拉出
|
|
1487
|
+
h("div", {
|
|
1488
|
+
style: { ...D.panelAnim, ...(expanded ? D.panelOpen : D.panelClosed) },
|
|
1489
|
+
"aria-hidden": !expanded,
|
|
1490
|
+
},
|
|
1491
|
+
expanded ? h("div", { style: D.panelInner },
|
|
1492
|
+
// ① 面板独有信息(2026-10-31 去重):仅纯在线模式给归档说明;
|
|
1493
|
+
// 监控状态/上次同步收起态单行已有,面板不再重复(dockPanelStatusLine 为空数组时不渲染)
|
|
1494
|
+
dockPanelStatusLine(view).length
|
|
1495
|
+
? h("div", { style: D.statusLine, title: dockPanelStatusLine(view).join(" | ") }, dockPanelStatusLine(view).map((seg, i, arr) =>
|
|
1496
|
+
h("span", { key: i, style: D.statusSeg }, seg + (i < arr.length - 1 ? " | " : ""))))
|
|
1497
|
+
: null,
|
|
1498
|
+
// ② 账号过滤页签(按账号看最近邮件)
|
|
1499
|
+
tabs.length ? h("div", { style: D.tabs, role: "tablist" }, tabs.map((tab) => h("button", {
|
|
1500
|
+
type: "button", role: "tab", "aria-selected": tab.active, key: tab.key || "all",
|
|
1501
|
+
style: { ...D.tab, ...(tab.active ? D.tabOn : {}) },
|
|
1502
|
+
title: `${tab.label}:未读 ${tab.unread} · 共 ${tab.messages}`,
|
|
1503
|
+
onClick: () => { setAccount(tab.key); setHint(""); },
|
|
1504
|
+
},
|
|
1505
|
+
h("span", { key: "dot", style: { ...D.acctDot, ...(tab.accent ? { background: tab.accent } : { background: "var(--dsw-alias-label-secondary, #9aa4b2)" }) } }),
|
|
1506
|
+
h("span", null, tab.label),
|
|
1507
|
+
tab.unread > 0 ? h("span", { style: D.badge }, String(tab.unread)) : null))) : null,
|
|
1508
|
+
|
|
1509
|
+
// ③ (已移除,2026-11-29)这里原有一张「多账户 × 多文件夹」网格:与上面的账号页签
|
|
1510
|
+
// 信息重复,而且整块不可操作(既不切号也不跳转),用户反馈"红框内容重复却没操控"。
|
|
1511
|
+
// 账号维度统一交给 ② 的页签(色点 + 未读徽标),邮件维度交给 ④ 的行。
|
|
1512
|
+
rows.length === 0
|
|
1513
|
+
? h("div", { style: { ...D.sub, marginTop: "6px" } },
|
|
1514
|
+
view?.recentUnavailable
|
|
1515
|
+
? "online 模式不落库:无本地邮件明细(下方「未看提示」即徽标上的新邮件)"
|
|
1516
|
+
: tt("dock_empty", "这个邮箱还没有归档邮件"))
|
|
1517
|
+
: h("div", { style: { marginTop: "6px" } }, rows.map((m) => {
|
|
1518
|
+
const key = `${m.account}/${m.folder}/${m.uid}`;
|
|
1519
|
+
const text = mailInsertText(m);
|
|
1520
|
+
const unread = !m.seen;
|
|
1521
|
+
const accent = accountAccent(view, m.account);
|
|
1522
|
+
// 需求 2026-11-29:标为已读要真的写服务器(handler /mark-seen → ImapClient.setSeen),
|
|
1523
|
+
// 成功后就地重拉 /status,徽标、页签数字、行的深浅一起变。
|
|
1524
|
+
const markRead = async (ev) => {
|
|
1525
|
+
ev?.stopPropagation?.();
|
|
1526
|
+
const r = await bridgeCall("/mark-seen", { account: m.account, folder: m.folder, uid: m.uid, seen: true });
|
|
1527
|
+
if (!r?.ok) { setHint(r?.message || "标为已读失败"); return; }
|
|
1528
|
+
const after = await bridgeCall("/status", { limit: DOCK_RECENT_LIMIT, account });
|
|
1529
|
+
if (after.ok) setView(after.value ?? null);
|
|
1530
|
+
};
|
|
1531
|
+
return h("button", {
|
|
1532
|
+
type: "button", key,
|
|
1533
|
+
style: {
|
|
1534
|
+
...D.mailRow,
|
|
1535
|
+
...(unread ? D.mailRowUnread : D.mailRowRead),
|
|
1536
|
+
...(hover === key ? D.mailRowHover : {}),
|
|
1537
|
+
...(unread && accent ? { color: accent } : {}),
|
|
1538
|
+
},
|
|
1539
|
+
title: `${text}\n${m.snippet ?? ""}\n${tt("dock_insert", "点击把邮件坐标插进输入框")}`,
|
|
1540
|
+
onMouseEnter: () => setHover(key),
|
|
1541
|
+
onMouseLeave: () => setHover((v) => (v === key ? "" : v)),
|
|
1542
|
+
onClick: () => pickMail(m),
|
|
1543
|
+
},
|
|
1544
|
+
h("div", { style: { display: "flex", alignItems: "center", gap: "6px", minWidth: 0 } },
|
|
1545
|
+
h("div", { style: { ...D.subject, flex: "1 1 auto", minWidth: 0, ...(unread ? {} : { fontWeight: "500" }) } }, m.subject || "(无主题)"),
|
|
1546
|
+
// 2026-11-29 需求:带附件的邮件行给一个可点的 📎 —— 单个附件直接打开,
|
|
1547
|
+
// 多个展开一行名字(见下方 attachStrip)。行本身是 <button>,所以用 span+role。
|
|
1548
|
+
m.hasAttachment ? h("span", {
|
|
1549
|
+
role: "button", tabIndex: 0, style: D.attachBadge,
|
|
1550
|
+
title: attachFor === key ? "收起附件与预览" : "展开附件并在面板内预览",
|
|
1551
|
+
onClick: (ev) => void openAttachments(m, ev),
|
|
1552
|
+
onKeyDown: (ev) => { if (ev?.key === "Enter" || ev?.key === " ") { ev.preventDefault?.(); void openAttachments(m, ev); } },
|
|
1553
|
+
}, "📎") : null,
|
|
1554
|
+
// 未读行右侧给一个"标为已读":面板里不点进详情也能把状态写回服务器。
|
|
1555
|
+
// (行本身是 <button>,所以这里用 span + role="button",避免按钮套按钮)
|
|
1556
|
+
unread ? h("span", {
|
|
1557
|
+
role: "button", tabIndex: 0, style: D.markBtn,
|
|
1558
|
+
title: "在服务器上标记为已读(会同步到其他客户端)",
|
|
1559
|
+
onClick: markRead,
|
|
1560
|
+
onKeyDown: (ev) => { if (ev?.key === "Enter" || ev?.key === " ") { ev.preventDefault?.(); void markRead(ev); } },
|
|
1561
|
+
}, "标为已读") : null),
|
|
1562
|
+
attachFor === key && attachList.length
|
|
1563
|
+
? h("div", { style: D.attachStrip }, attachList.map((a) => h("span", {
|
|
1564
|
+
key: `att-${a.index}`, role: "button", tabIndex: 0,
|
|
1565
|
+
style: { ...D.attachItem, ...(preview && attachFor === key && Number(preview.index) === Number(a.index) ? D.attachItemOn : {}) },
|
|
1566
|
+
title: `${a.name} · ${a.size ? `${(a.size / 1024).toFixed(1)} KB` : "大小未知"} · ${a.contentType ?? ""}`,
|
|
1567
|
+
onClick: (ev) => { ev?.stopPropagation?.(); void showAttachment(m, attachList, a.index); },
|
|
1568
|
+
onKeyDown: (ev) => {
|
|
1569
|
+
if (ev?.key === "Enter" || ev?.key === " ") { ev.preventDefault?.(); ev?.stopPropagation?.(); void showAttachment(m, attachList, a.index); }
|
|
1570
|
+
},
|
|
1571
|
+
}, `📄 ${a.name}`)))
|
|
1572
|
+
: null,
|
|
1573
|
+
h("div", { style: D.sub },
|
|
1574
|
+
`${m.from || "(未知发件人)"} · ${m.dateTs ? new Date(m.dateTs).toLocaleString() : "(无日期)"}`
|
|
1575
|
+
+ `${m.hasAttachment ? " · 📎" : ""}${m.importance != null ? ` · 重要度 ${m.importance}` : ""}`,
|
|
1576
|
+
tabs.length
|
|
1577
|
+
? h("span", { style: { color: accent || "inherit", fontWeight: unread ? 600 : 500 } }, ` · ${m.alias || m.account}`)
|
|
1578
|
+
: null),
|
|
1579
|
+
);
|
|
1580
|
+
})),
|
|
1581
|
+
noticesBlock(view,
|
|
1582
|
+
null, // onAckOne 由 onConsume 接管(带淡出动画);浮层才走直呼路径
|
|
1583
|
+
// 选中某封 = 把坐标插进输入框(和 recent 行同一个 pickMail:插入失败自动退回复制)
|
|
1584
|
+
(m) => pickMail(m),
|
|
1585
|
+
{
|
|
1586
|
+
hover, setHover, acking,
|
|
1587
|
+
// 单条已看(带淡出):先标消费中(行 opacity→0),180ms 后 ack 并重拉 /status,
|
|
1588
|
+
// 徽标/网格/列表一起响应式递减;完成后移出消费集合(失败也移,防卡死)
|
|
1589
|
+
onConsume: (key, id) => {
|
|
1590
|
+
setAcking((prev) => { const next = new Set(prev ?? []); next.add(key); return next; });
|
|
1591
|
+
setTimeout(() => {
|
|
1592
|
+
void (async () => {
|
|
1593
|
+
try {
|
|
1594
|
+
await bridgeCall("/ack", { ids: [id] });
|
|
1595
|
+
const after = await bridgeCall("/status", { limit: DOCK_RECENT_LIMIT, account });
|
|
1596
|
+
if (after.ok) setView(after.value ?? null);
|
|
1597
|
+
} finally {
|
|
1598
|
+
setAcking((prev) => { const next = new Set(prev ?? []); next.delete(key); return next.size ? next : null; });
|
|
1599
|
+
}
|
|
1600
|
+
})();
|
|
1601
|
+
}, 180);
|
|
1602
|
+
},
|
|
1603
|
+
// 全部标记为已看(列表底部右侧按钮)
|
|
1604
|
+
onAckAll: async () => {
|
|
1605
|
+
await bridgeCall("/ack", {});
|
|
1606
|
+
const after = await bridgeCall("/status", { limit: DOCK_RECENT_LIMIT, account });
|
|
1607
|
+
if (after.ok) setView(after.value ?? null);
|
|
1608
|
+
},
|
|
1609
|
+
}),
|
|
1610
|
+
// 附件内嵌预览(2026-11-30):图片 <img>、PDF/文本/HTML <iframe>,其它类型只给下载。
|
|
1611
|
+
preview
|
|
1612
|
+
? h("div", { style: D.previewBox },
|
|
1613
|
+
h("div", { style: D.previewHead },
|
|
1614
|
+
h("span", { style: D.previewName, title: preview.name }, `📄 ${preview.name || "附件"}`),
|
|
1615
|
+
h("span", { style: D.sub }, `${preview.size ? `${(preview.size / 1024).toFixed(1)} KB` : ""}${preview.contentType ? ` · ${preview.contentType}` : ""}`),
|
|
1616
|
+
h("span", {
|
|
1617
|
+
role: "button", tabIndex: 0, style: D.markBtn, title: "下载到本地(浏览器下载目录)",
|
|
1618
|
+
onClick: () => downloadAttachment(preview),
|
|
1619
|
+
onKeyDown: (ev) => { if (ev?.key === "Enter" || ev?.key === " ") { ev.preventDefault?.(); downloadAttachment(preview); } },
|
|
1620
|
+
}, "下载"),
|
|
1621
|
+
h("span", {
|
|
1622
|
+
role: "button", tabIndex: 0, style: D.markBtn, title: "关闭预览",
|
|
1623
|
+
onClick: closePreview,
|
|
1624
|
+
onKeyDown: (ev) => { if (ev?.key === "Enter" || ev?.key === " ") { ev.preventDefault?.(); closePreview(); } },
|
|
1625
|
+
}, "关闭")),
|
|
1626
|
+
preview.busy ? h("div", { style: D.sub }, "读取附件内容…")
|
|
1627
|
+
: preview.error ? h("div", { style: D.err }, preview.error)
|
|
1628
|
+
: preview.kind === "image" ? h("img", { src: preview.url, alt: preview.name || "附件图片", style: D.previewImg })
|
|
1629
|
+
: preview.kind === "other"
|
|
1630
|
+
? h("div", { style: D.sub }, "这个类型浏览器不能内嵌显示,点上面的「下载」保存后用本地程序打开。")
|
|
1631
|
+
: h("iframe", {
|
|
1632
|
+
src: preview.url, style: D.previewFrame, title: preview.name || "附件预览",
|
|
1633
|
+
// HTML 附件当文档看,不给脚本权限(下载下来的邮件附件不该跑 JS)
|
|
1634
|
+
sandbox: preview.kind === "html" ? "" : undefined,
|
|
1635
|
+
}))
|
|
1636
|
+
: null,
|
|
1637
|
+
hint ? h("div", { style: D.hint }, hint) : null,
|
|
1638
|
+
error && !error.silent ? h("div", { style: D.err }, String(error.message ?? error.code ?? "读取失败")) : null)
|
|
1639
|
+
: null)));
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
function MailboxSettingsCard(props) {
|
|
1643
|
+
const { t, view, form } = props;
|
|
1644
|
+
const tt = (key, fallback) => {
|
|
1645
|
+
try { return t ? t(key) : (DICT.zh[key] ?? fallback ?? key); } catch { return fallback ?? key; }
|
|
1646
|
+
};
|
|
1647
|
+
if (view === "summary") return h("span", null, tt("summary", "Mailbox runtime settings"));
|
|
1648
|
+
|
|
1649
|
+
const pageState = form?.state ?? {};
|
|
1650
|
+
const [live, setLive] = React.useState(null); // 自己读到的权威视图
|
|
1651
|
+
const [draft, setDraft] = React.useState({});
|
|
1652
|
+
const [message, setMessage] = React.useState("");
|
|
1653
|
+
const [error, setError] = React.useState("");
|
|
1654
|
+
const [busy, setBusy] = React.useState(false);
|
|
1655
|
+
const [showRaw, setShowRaw] = React.useState(false);
|
|
1656
|
+
// 账号管理:列表 / 添加表单 / 认证进行中
|
|
1657
|
+
const [accountsList, setAccountsList] = React.useState([]);
|
|
1658
|
+
const [accountDraft, setAccountDraft] = React.useState({});
|
|
1659
|
+
const [authPending, setAuthPending] = React.useState(null); // {email, alias} 正在等待完成认证
|
|
1660
|
+
const [accountBusy, setAccountBusy] = React.useState(false);
|
|
1661
|
+
const [accountMessage, setAccountMessage] = React.useState("");
|
|
1662
|
+
const [accountError, setAccountError] = React.useState("");
|
|
1663
|
+
// 添加表单的高级选项(IMAP/SMTP 端点):默认收起 —— 授权走设备码流,端点保持默认即可
|
|
1664
|
+
const [showAdvanced, setShowAdvanced] = React.useState(false);
|
|
1665
|
+
// 连接与同步状态(2026-11-30):/status 的快照,配置卡顶部那块"链路健康"用它
|
|
1666
|
+
const [statusView, setStatusView] = React.useState(null);
|
|
1667
|
+
// 通道自测(2026-11-30):「发测试消息」的结果就地显示,不弹窗、不写进 save 状态
|
|
1668
|
+
const [testResult, setTestResult] = React.useState(null);
|
|
1669
|
+
// 移植(ui-design/MailboxSettings.jsx):高级策略折叠 / 添加·编辑 Modal / Tag 输入草稿
|
|
1670
|
+
const [advOpen, setAdvOpen] = React.useState(false); // ▶ 展开高级策略配置
|
|
1671
|
+
const [modal, setModal] = React.useState(null); // null | {editing, needAuth}
|
|
1672
|
+
const [tagText, setTagText] = React.useState({}); // 关键词 Tag 输入框的临时文本
|
|
1673
|
+
const [folderZoneOpen, setFolderZoneOpen] = React.useState(true); // 自定义同步文件夹展开区
|
|
1674
|
+
// dsh-im 的真实候选(走 /api/mailbox/targets 回环桥)—— botId/targetId 改成可选,堵住"填错字段"
|
|
1675
|
+
const [cand, setCand] = React.useState(null);
|
|
1676
|
+
const [candNote, setCandNote] = React.useState("");
|
|
1677
|
+
// 监控文件夹多选(2026-10-30):「从服务器读取」真连 IMAP 拉文件夹名(/folders 桥)。
|
|
1678
|
+
// 形如 {email, folders: string[]|null, note} —— folders=null 表示没读到(退回手输文本框)。
|
|
1679
|
+
const [folderOpts, setFolderOpts] = React.useState(null);
|
|
1680
|
+
const [folderLoading, setFolderLoading] = React.useState(false);
|
|
1681
|
+
const loadFolderOpts = React.useCallback(async (email) => {
|
|
1682
|
+
const acct = String(email ?? "").trim();
|
|
1683
|
+
if (!acct) { setFolderOpts({ email: "", folders: null, note: "先填邮箱地址" }); return; }
|
|
1684
|
+
setFolderLoading(true);
|
|
1685
|
+
try {
|
|
1686
|
+
const r = await bridgeCall("/folders", { account: acct });
|
|
1687
|
+
if (r?.ok && Array.isArray(r.value?.folders)) {
|
|
1688
|
+
setFolderOpts({ email: acct, folders: dedupeFoldersCase(r.value.folders), note: "" });
|
|
1689
|
+
setFolderZoneOpen(true); // 读到了就原地展开勾选区(参考实现 FolderPicker 的行为)
|
|
1690
|
+
}
|
|
1691
|
+
else setFolderOpts({ email: acct, folders: null, note: r?.silent ? "宿主没挂邮件桥" : (r?.message ?? r?.code ?? "读取失败") });
|
|
1692
|
+
} finally { setFolderLoading(false); }
|
|
1693
|
+
}, []);
|
|
1694
|
+
|
|
1695
|
+
const currentValue = live?.value ?? pageState.value;
|
|
1696
|
+
const runtimeValue = resolveRuntimeSection(currentValue);
|
|
1697
|
+
const revision = live?.revision ?? pageState.revision;
|
|
1698
|
+
const writable = isWritable(live, pageState);
|
|
1699
|
+
|
|
1700
|
+
const refresh = React.useCallback(async () => {
|
|
1701
|
+
if (!remoteSettings) return;
|
|
1702
|
+
const read = await readNamespaceView(remoteSettings, SETTINGS_NAMESPACE);
|
|
1703
|
+
if (read.ok) setLive(read.view);
|
|
1704
|
+
else setError(read.message);
|
|
1705
|
+
}, []);
|
|
1706
|
+
|
|
1707
|
+
React.useEffect(() => { void refresh(); }, [refresh]);
|
|
1708
|
+
React.useEffect(() => { void refresh(); }, [pageState.revision, refresh]);
|
|
1709
|
+
|
|
1710
|
+
/** 拉 dsh-im 候选(机器人与投递目标)。失败时只提示,不影响手填。 */
|
|
1711
|
+
const loadCandidates = React.useCallback(async () => {
|
|
1712
|
+
setCandNote("读取候选…");
|
|
1713
|
+
const r = await bridgeCall("/targets", {});
|
|
1714
|
+
if (r?.ok && r.value) {
|
|
1715
|
+
setCand(r.value);
|
|
1716
|
+
const n = r.value.targets?.length ?? 0;
|
|
1717
|
+
setCandNote(n ? "" : (r.value.bots?.length
|
|
1718
|
+
? "机器人已接入,但**还没有投递目标** —— 到 设置 → IM机器人 → 该机器人 →「投递设置」→「新建目标」,从已聊过的会话里建一个,再点刷新"
|
|
1719
|
+
: "dsh-im 里还没接入机器人(到 设置 → IM机器人 接入)"));
|
|
1720
|
+
} else {
|
|
1721
|
+
setCand(null);
|
|
1722
|
+
setCandNote(r?.silent ? "拿不到候选(宿主没挂邮件桥)" : (r?.message ?? r?.code ?? "读取候选失败"));
|
|
1723
|
+
}
|
|
1724
|
+
}, []);
|
|
1725
|
+
React.useEffect(() => { void loadCandidates(); }, [loadCandidates]);
|
|
1726
|
+
|
|
1727
|
+
// ============== 账号管理:免重启添加/删除账号 + OAuth2 认证 ==============
|
|
1728
|
+
|
|
1729
|
+
/** 拉账号列表(带 token 授权状态)。返回账号数组,供保存后判断"是否已完成授权"。 */
|
|
1730
|
+
const fetchAccounts = React.useCallback(async () => {
|
|
1731
|
+
const r = await bridgeCall("/accounts", {});
|
|
1732
|
+
if (r?.ok && r.value) {
|
|
1733
|
+
const list = r.value.accounts ?? [];
|
|
1734
|
+
setAccountsList(list);
|
|
1735
|
+
setAccountError("");
|
|
1736
|
+
return list;
|
|
1737
|
+
}
|
|
1738
|
+
setAccountsList([]);
|
|
1739
|
+
setAccountError(r?.silent ? tt("account_fetch_failed", "获取账号列表失败:") + " (宿主没挂邮件桥)"
|
|
1740
|
+
: (r?.message ?? r?.code ?? tt("account_fetch_failed", "获取账号列表失败:")));
|
|
1741
|
+
return [];
|
|
1742
|
+
}, []);
|
|
1743
|
+
|
|
1744
|
+
React.useEffect(() => { void fetchAccounts(); }, [fetchAccounts]);
|
|
1745
|
+
|
|
1746
|
+
/** 拉一次桥状态(watcher / 每账户同步健康 / IM 通道)。失败不打扰:状态卡只是辅助信息。 */
|
|
1747
|
+
const fetchStatus = React.useCallback(async () => {
|
|
1748
|
+
try {
|
|
1749
|
+
const r = await bridgeCall("/status", { limit: 0 });
|
|
1750
|
+
setStatusView(r?.ok && r.value ? r.value : null);
|
|
1751
|
+
} catch { setStatusView(null); }
|
|
1752
|
+
}, []);
|
|
1753
|
+
|
|
1754
|
+
React.useEffect(() => { void fetchStatus(); }, [fetchStatus]);
|
|
1755
|
+
|
|
1756
|
+
/** 添加/更新账号:POST /api/mailbox/accounts action=put。 */
|
|
1757
|
+
const handleAddAccount = async () => {
|
|
1758
|
+
if (!writable || accountBusy) return;
|
|
1759
|
+
const email = String(accountDraft.email ?? "").trim();
|
|
1760
|
+
if (!email) { setAccountError(tt("account_add_failed", "添加账号失败:") + " 邮箱地址不能为空"); return; }
|
|
1761
|
+
setAccountBusy(true); setAccountError(""); setAccountMessage("");
|
|
1762
|
+
const body = {
|
|
1763
|
+
action: "put",
|
|
1764
|
+
email,
|
|
1765
|
+
alias: String(accountDraft.alias ?? "").trim() || email,
|
|
1766
|
+
imapHost: String(accountDraft.imapHost ?? "outlook.office365.com").trim() || "outlook.office365.com",
|
|
1767
|
+
imapPort: Number(accountDraft.imapPort ?? 993) || 993,
|
|
1768
|
+
smtpHost: String(accountDraft.smtpHost ?? "smtp-mail.outlook.com").trim() || "smtp-mail.outlook.com",
|
|
1769
|
+
smtpPort: Number(accountDraft.smtpPort ?? 587) || 587,
|
|
1770
|
+
defaultFolder: String(accountDraft.defaultFolder ?? "INBOX").trim() || "INBOX",
|
|
1771
|
+
};
|
|
1772
|
+
// 监控文件夹(2026-10-30):勾选列表模式 = 数组直传(含空数组=明确清空→回默认文件夹);
|
|
1773
|
+
// 文本框模式(没读到列表) = 逗号/中文逗号分隔;留空 = 不传 → 后端沿用该账号已配置的范围
|
|
1774
|
+
if (Array.isArray(accountDraft.folders)) {
|
|
1775
|
+
// 勾选列表模式:数组直传(含空数组=明确清空→回默认文件夹);先按大小写不敏感去重
|
|
1776
|
+
body.folders = dedupeFoldersCase(accountDraft.folders);
|
|
1777
|
+
} else {
|
|
1778
|
+
// 文本框模式(没读到列表) = 逗号/中文逗号分隔;留空 = 不传 → 后端沿用该账号已配置的范围
|
|
1779
|
+
const folders = dedupeFoldersCase(String(accountDraft.folders ?? "").split(/[,,]/));
|
|
1780
|
+
if (folders.length) body.folders = folders; // 非空才放(空 = 沿用/默认,后端语义)
|
|
1781
|
+
}
|
|
1782
|
+
try {
|
|
1783
|
+
const r = await bridgeCall("/accounts", body);
|
|
1784
|
+
if (r?.ok) {
|
|
1785
|
+
// 旧文案 bug:成功分支曾以「添加账号失败:」开头(account_add_failed),
|
|
1786
|
+
// 添加成功也显示成失败 —— 与 DEFAULT_SCOPES 崩溃叠加,用户完全没法判断(2026-10-17 真机反馈)
|
|
1787
|
+
const list = await fetchAccounts();
|
|
1788
|
+
const authorized = !!list.find((a) => a.email === email)?.authorized;
|
|
1789
|
+
setAccountMessage(authorized
|
|
1790
|
+
? tt("account_saved", "已保存(免重启)。")
|
|
1791
|
+
: tt("account_added", "已保存(免重启),请完成 OAuth2 授权。"));
|
|
1792
|
+
if (authorized) {
|
|
1793
|
+
// 已授权:收尾关 Modal(参考实现 onSave → onClose)
|
|
1794
|
+
setAccountDraft({});
|
|
1795
|
+
setModal(null);
|
|
1796
|
+
setFolderOpts(null);
|
|
1797
|
+
setShowAdvanced(false);
|
|
1798
|
+
} else {
|
|
1799
|
+
// 已保存但未授权:Modal 留着,顶部亮横幅 + 「立即授权」呼吸按钮强引导
|
|
1800
|
+
setModal((m) => (m ? { ...m, needAuth: true } : m));
|
|
1801
|
+
}
|
|
1802
|
+
} else {
|
|
1803
|
+
setAccountError(tt("account_add_failed", "添加账号失败:") + " " + (r?.message ?? r?.code ?? "未知错误"));
|
|
1804
|
+
}
|
|
1805
|
+
} catch (e) {
|
|
1806
|
+
setAccountError(tt("account_add_failed", "添加账号失败:") + " " + String(e?.message ?? e));
|
|
1807
|
+
} finally {
|
|
1808
|
+
setAccountBusy(false);
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1811
|
+
|
|
1812
|
+
/** 发起设备码流:POST /api/mailbox/auth/device。 */
|
|
1813
|
+
const handleAuthDevice = async (email) => {
|
|
1814
|
+
setAccountBusy(true); setAccountError(""); setAccountMessage("");
|
|
1815
|
+
try {
|
|
1816
|
+
const r = await bridgeCall("/auth/device", { email });
|
|
1817
|
+
if (r?.ok) {
|
|
1818
|
+
setAuthPending({ email, alias: accountsList.find((a) => a.email === email)?.alias ?? email, userCode: r.userCode, verificationUri: r.verificationUri });
|
|
1819
|
+
setAccountMessage(tt("account_auth_started", "设备码流已启动:")
|
|
1820
|
+
+ `\n1. 打开 ${r.verificationUri}\n2. 输入验证码 ${r.userCode}\n3. 完成后点「完成认证」`);
|
|
1821
|
+
} else {
|
|
1822
|
+
setAccountError(tt("account_auth_failed", "认证失败:") + " " + (r?.message ?? r?.code ?? "未知错误"));
|
|
1823
|
+
}
|
|
1824
|
+
} catch (e) {
|
|
1825
|
+
setAccountError(tt("account_auth_failed", "认证失败:") + " " + String(e?.message ?? e));
|
|
1826
|
+
} finally {
|
|
1827
|
+
setAccountBusy(false);
|
|
1828
|
+
}
|
|
1829
|
+
};
|
|
1830
|
+
|
|
1831
|
+
/** 完成认证:POST /api/mailbox/auth/complete。 */
|
|
1832
|
+
const handleAuthComplete = async (email) => {
|
|
1833
|
+
setAccountBusy(true); setAccountError(""); setAccountMessage("");
|
|
1834
|
+
try {
|
|
1835
|
+
const r = await bridgeCall("/auth/complete", { email });
|
|
1836
|
+
if (r?.ok) {
|
|
1837
|
+
setAccountMessage(tt("account_auth_done", "授权成功,token 已保存。"));
|
|
1838
|
+
setAuthPending(null);
|
|
1839
|
+
await fetchAccounts();
|
|
1840
|
+
} else {
|
|
1841
|
+
setAccountError(tt("account_auth_failed", "认证失败:") + " " + (r?.message ?? r?.code ?? "未知错误"));
|
|
1842
|
+
}
|
|
1843
|
+
} catch (e) {
|
|
1844
|
+
setAccountError(tt("account_auth_failed", "认证失败:") + " " + String(e?.message ?? e));
|
|
1845
|
+
} finally {
|
|
1846
|
+
setAccountBusy(false);
|
|
1847
|
+
}
|
|
1848
|
+
};
|
|
1849
|
+
|
|
1850
|
+
/** 删除账号:DELETE /api/mailbox/accounts。 */
|
|
1851
|
+
const handleDeleteAccount = async (email) => {
|
|
1852
|
+
if (!window.confirm(`${tt("account_confirm_delete", "确定要删除账号")} ${email}?`)) return;
|
|
1853
|
+
setAccountBusy(true); setAccountError(""); setAccountMessage("");
|
|
1854
|
+
try {
|
|
1855
|
+
const r = await bridgeCall("/accounts", { action: "delete", email }, "DELETE");
|
|
1856
|
+
if (r?.ok) {
|
|
1857
|
+
setAccountMessage("已删除(免重启生效)。");
|
|
1858
|
+
await fetchAccounts();
|
|
1859
|
+
} else {
|
|
1860
|
+
setAccountError(tt("account_delete_failed", "删除账号失败:") + " " + (r?.message ?? r?.code ?? "未知错误"));
|
|
1861
|
+
}
|
|
1862
|
+
} catch (e) {
|
|
1863
|
+
setAccountError(tt("account_delete_failed", "删除账号失败:") + " " + String(e?.message ?? e));
|
|
1864
|
+
} finally {
|
|
1865
|
+
setAccountBusy(false);
|
|
1866
|
+
}
|
|
1867
|
+
};
|
|
1868
|
+
|
|
1869
|
+
/** 重置水位回填历史(2026-10-31):POST /api/mailbox/resync。
|
|
1870
|
+
* 让本地归档与邮箱内容保持一致 —— 下一轮轮询起分批抓全部历史(≤重置时刻
|
|
1871
|
+
* 水位的邮件只入库不通知,不会灌爆通知)。幂等,随时可再点。 */
|
|
1872
|
+
const handleResyncAccount = async (email) => {
|
|
1873
|
+
if (!window.confirm(`${tt("account_confirm_resync", "回填该账户监控文件夹的全部历史邮件?(下一轮轮询开始,分多轮补完)")} (${email})`)) return;
|
|
1874
|
+
setAccountBusy(true); setAccountError(""); setAccountMessage("");
|
|
1875
|
+
try {
|
|
1876
|
+
const r = await bridgeCall("/resync", { account: email });
|
|
1877
|
+
if (!r?.ok) throw new Error(r?.message ?? r?.code ?? "未知错误");
|
|
1878
|
+
const n = r.value?.reset?.length ?? 0;
|
|
1879
|
+
setAccountMessage(n > 0
|
|
1880
|
+
? tt("account_resync_done", "已重置水位,下一轮起回填历史(≤重置时刻水位的邮件只入库不通知)…")
|
|
1881
|
+
: "该账户还没有已跟踪的文件夹(watcher 跑过一轮后再来),无需回填。");
|
|
1882
|
+
} catch (e) {
|
|
1883
|
+
setAccountError(tt("account_resync_failed", "重置水位失败:") + " " + String(e?.message ?? e));
|
|
1884
|
+
} finally {
|
|
1885
|
+
setAccountBusy(false);
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
|
|
1889
|
+
// revision 变化 ⇒ 只补"用户没编辑过"的字段,绝不覆盖草稿
|
|
1890
|
+
React.useEffect(() => {
|
|
1891
|
+
const patch = {};
|
|
1892
|
+
for (const field of FIELDS) {
|
|
1893
|
+
const key = keyOf(field);
|
|
1894
|
+
if (Object.hasOwn(draft, key)) continue;
|
|
1895
|
+
const current = getIn(runtimeValue, field.path);
|
|
1896
|
+
if (current !== undefined) patch[key] = Array.isArray(current) ? current.join(", ") : current;
|
|
1897
|
+
}
|
|
1898
|
+
if (Object.keys(patch).length) setDraft((prev) => ({ ...patch, ...prev }));
|
|
1899
|
+
}, [revision, currentValue]);
|
|
1900
|
+
|
|
1901
|
+
const onSave = async () => {
|
|
1902
|
+
if (!writable || busy) return;
|
|
1903
|
+
const ops = buildOps(draft, runtimeValue);
|
|
1904
|
+
if (ops.length === 0) { setMessage(tt("nochange", "no changes")); setError(""); return; }
|
|
1905
|
+
setBusy(true); setError("");
|
|
1906
|
+
try {
|
|
1907
|
+
// 优先直连 RPC(权威 revision + 真实错误);没有该服务时才退回页面的 form
|
|
1908
|
+
const result = remoteSettings
|
|
1909
|
+
? await saveViaRemote(remoteSettings, SETTINGS_NAMESPACE, ops)
|
|
1910
|
+
: await saveWithRetry(form, ops, pageState.revision);
|
|
1911
|
+
if (!result.accepted) {
|
|
1912
|
+
setMessage(tt("conflict", "refused"));
|
|
1913
|
+
setError(`${result.reason}${result.firstReason ? `\n第一次: ${result.firstReason}` : ""}`);
|
|
1914
|
+
} else {
|
|
1915
|
+
setMessage(result.attempts === 2 ? tt("retried", "saved after retry") : tt("saved", "saved"));
|
|
1916
|
+
setDraft({});
|
|
1917
|
+
await refresh();
|
|
1918
|
+
}
|
|
1919
|
+
} catch (e) {
|
|
1920
|
+
setMessage(tt("conflict", "refused"));
|
|
1921
|
+
setError(String((e && e.message) || e));
|
|
1922
|
+
} finally {
|
|
1923
|
+
setBusy(false);
|
|
1924
|
+
}
|
|
1925
|
+
};
|
|
1926
|
+
|
|
1927
|
+
// ── 移植:展示层控件(值全部落在 draft 平键上,buildOps/coerce 语义不变) ──────
|
|
1928
|
+
const disp = (key) => {
|
|
1929
|
+
const field = FIELDS.find((f) => keyOf(f) === key);
|
|
1930
|
+
const raw = Object.hasOwn(draft, key) ? draft[key] : getIn(runtimeValue, key.split("."));
|
|
1931
|
+
return field?.type === "list" && Array.isArray(raw) ? raw.join(", ") : String(raw ?? "");
|
|
1932
|
+
};
|
|
1933
|
+
const gv = (key, fb = "") => (Object.hasOwn(draft, key) ? draft[key] : (getIn(runtimeValue, key.split(".")) ?? fb));
|
|
1934
|
+
const sv = (key, val) => setDraft((prev) => ({ ...prev, [key]: val }));
|
|
1935
|
+
/** ⓘ 技术释义收容所:黑话一律不进常驻 DOM(hover title)。 */
|
|
1936
|
+
const info = (text) => (text ? h("span", { style: M.info, title: text, "aria-label": "说明" }, "i") : null);
|
|
1937
|
+
const boolLabel = (key, text) => h("label", { style: { display: "inline-flex", alignItems: "center", gap: "4px", fontSize: "12px" } },
|
|
1938
|
+
boolCtl(key), text);
|
|
1939
|
+
|
|
1940
|
+
const numCtl = (key, opts = {}) => h("input", {
|
|
1941
|
+
type: "number", disabled: !writable || busy,
|
|
1942
|
+
min: opts.min, max: opts.max, placeholder: opts.placeholder ?? "",
|
|
1943
|
+
value: String(gv(key, "")), style: { width: opts.width ?? "7em" },
|
|
1944
|
+
onChange: (e) => sv(key, e.target.value),
|
|
1945
|
+
});
|
|
1946
|
+
/** 字节字段的 MB 输入(附件上限这类"填字节数"太反人类):显示 MB,回写字节。 */
|
|
1947
|
+
const mbCtl = (key, opts = {}) => {
|
|
1948
|
+
const bytes = Number(gv(key, 0));
|
|
1949
|
+
const mb = Number.isFinite(bytes) && bytes > 0 ? Math.round(bytes / (1024 * 1024)) : 0;
|
|
1950
|
+
return h("input", {
|
|
1951
|
+
type: "number", disabled: !writable || busy, min: 0, max: opts.max ?? 1024,
|
|
1952
|
+
value: String(mb), style: { width: opts.width ?? "7em" },
|
|
1953
|
+
onChange: (e) => sv(key, Math.max(0, Math.round(Number(e.target.value) || 0)) * 1024 * 1024),
|
|
1954
|
+
});
|
|
1955
|
+
};
|
|
1956
|
+
const textCtl = (key, opts = {}) => h("input", {
|
|
1957
|
+
type: "text", disabled: !writable || busy, placeholder: opts.placeholder ?? "",
|
|
1958
|
+
value: disp(key), style: { width: opts.width ?? "16em" },
|
|
1959
|
+
onChange: (e) => sv(key, e.target.value),
|
|
1960
|
+
});
|
|
1961
|
+
const boolCtl = (key) => h("input", {
|
|
1962
|
+
type: "checkbox", disabled: !writable || busy, checked: gv(key) === true,
|
|
1963
|
+
onChange: (e) => sv(key, e.target.checked),
|
|
1964
|
+
});
|
|
1965
|
+
const timeCtl = (key) => h("input", {
|
|
1966
|
+
type: "time", step: 300, disabled: !writable || busy, value: hhmm(disp(key)),
|
|
1967
|
+
onChange: (e) => sv(key, e.target.value),
|
|
1968
|
+
});
|
|
1969
|
+
const selectCtl = (key, options) => h("select", {
|
|
1970
|
+
disabled: !writable || busy, value: String(gv(key, "")),
|
|
1971
|
+
onChange: (e) => sv(key, e.target.value),
|
|
1972
|
+
}, options.map((o) => h("option", { key: o.value, value: o.value }, o.label)));
|
|
1973
|
+
|
|
1974
|
+
/** 关键词 Tag 输入:UI 内是 Tag 数组(回车加/✕删),提交仍是逗号串(list 语义不变)。 */
|
|
1975
|
+
const tagCtl = (key, placeholder) => {
|
|
1976
|
+
const tags = splitKeywords(disp(key));
|
|
1977
|
+
const inputText = tagText[key] ?? "";
|
|
1978
|
+
const commit = () => {
|
|
1979
|
+
const word = inputText.trim().replace(/,/g, "");
|
|
1980
|
+
setTagText((p) => ({ ...p, [key]: "" }));
|
|
1981
|
+
if (!word || tags.includes(word)) return;
|
|
1982
|
+
sv(key, [...tags, word].join(","));
|
|
1983
|
+
};
|
|
1984
|
+
return h("span", { style: { display: "inline-flex", flexWrap: "wrap", gap: "4px", alignItems: "center" } },
|
|
1985
|
+
tags.map((tg) => h("span", { key: tg, style: M.chip }, tg,
|
|
1986
|
+
h("button", {
|
|
1987
|
+
type: "button", style: M.chipX, title: "移除", disabled: !writable || busy,
|
|
1988
|
+
onClick: () => sv(key, tags.filter((x) => x !== tg).join(",")),
|
|
1989
|
+
}, "✕"))),
|
|
1990
|
+
h("input", {
|
|
1991
|
+
type: "text", disabled: !writable || busy, value: inputText,
|
|
1992
|
+
placeholder, style: { width: "12em", fontSize: "12px" },
|
|
1993
|
+
onChange: (e) => setTagText((p) => ({ ...p, [key]: e.target.value })),
|
|
1994
|
+
onKeyDown: (e) => { if (e.key === "Enter") { e.preventDefault(); commit(); } },
|
|
1995
|
+
}),
|
|
1996
|
+
h("button", { type: "button", style: B.btn, disabled: !writable || busy, onClick: commit }, "添加"));
|
|
1997
|
+
};
|
|
1998
|
+
|
|
1999
|
+
/** botId:有候选 → 下拉(代替文本框,不再两套同时出现);没有 → 退回文本框。 */
|
|
2000
|
+
const botCtl = () => {
|
|
2001
|
+
const curBotId = disp("notify.botId");
|
|
2002
|
+
if (!cand?.bots?.length) {
|
|
2003
|
+
return h("input", {
|
|
2004
|
+
type: "text", disabled: !writable || busy, value: curBotId,
|
|
2005
|
+
placeholder: "(留空 = 自动发现)", style: { width: "18em" },
|
|
2006
|
+
onChange: (e) => sv("notify.botId", e.target.value),
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
const matched = cand.bots.some((b) => b.botId === curBotId);
|
|
2010
|
+
return h("select", {
|
|
2011
|
+
disabled: !writable || busy, value: matched ? curBotId : "",
|
|
2012
|
+
onChange: (e) => setDraft((prev) => ({ ...prev, "notify.botId": e.target.value, "notify.targetId": "" })),
|
|
2013
|
+
}, [
|
|
2014
|
+
h("option", { key: "_auto", value: "" }, "(留空 = 自动发现)"),
|
|
2015
|
+
...cand.bots.map((b) => h("option", {
|
|
2016
|
+
key: b.botId, value: b.botId,
|
|
2017
|
+
}, `${b.botId}${b.name ? ` · ${b.name}` : ""}${b.username ? ` (@${String(b.username).replace(/^@/, "")})` : ""}`)),
|
|
2018
|
+
// 当前值不在候选里(可能是手填/旧的):保留为一个选项,用户能看到并改掉
|
|
2019
|
+
...(matched || !curBotId ? [] : [h("option", { key: "_current", value: curBotId }, `${curBotId} (不在候选列表)`)]),
|
|
2020
|
+
]);
|
|
2021
|
+
};
|
|
2022
|
+
/** targetId:同上;候选按当前 botId 过滤。 */
|
|
2023
|
+
const targetCtl = () => {
|
|
2024
|
+
const botIdNow = Object.hasOwn(draft, "notify.botId") ? draft["notify.botId"] : getIn(runtimeValue, ["notify", "botId"]);
|
|
2025
|
+
const forBot = (cand?.targets ?? []).filter((x) => !botIdNow || x.botId === botIdNow);
|
|
2026
|
+
const curTargetId = disp("notify.targetId");
|
|
2027
|
+
if (!(cand?.targets?.length)) {
|
|
2028
|
+
return h("input", {
|
|
2029
|
+
type: "text", disabled: !writable || busy, value: curTargetId,
|
|
2030
|
+
placeholder: "(留空 = 自动发现)", style: { width: "18em" },
|
|
2031
|
+
onChange: (e) => sv("notify.targetId", e.target.value),
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
2034
|
+
const matched = forBot.some((x) => x.targetId === curTargetId);
|
|
2035
|
+
return h("select", {
|
|
2036
|
+
disabled: !writable || busy, value: matched ? curTargetId : "",
|
|
2037
|
+
onChange: (e) => sv("notify.targetId", e.target.value),
|
|
2038
|
+
}, [
|
|
2039
|
+
h("option", { key: "_auto", value: "" }, forBot.length ? "(选择目标)" : "(该机器人还没有投递目标)"),
|
|
2040
|
+
...forBot.map((x) => h("option", {
|
|
2041
|
+
key: `${x.botId}/${x.targetId}`, value: x.targetId,
|
|
2042
|
+
}, `${x.targetId}${x.name ? ` · ${x.name}` : ""}${x.kind ? ` (${x.kind})` : ""}`)),
|
|
2043
|
+
...(matched || !curTargetId ? [] : [h("option", { key: "_current", value: curTargetId }, `${curTargetId} (不在候选列表)`)]),
|
|
2044
|
+
]);
|
|
2045
|
+
};
|
|
2046
|
+
|
|
2047
|
+
/** Modal 开合(添加/编辑账号抽离出主信息流;编辑时邮箱主键只读)。 */
|
|
2048
|
+
const openAdd = () => { setAccountDraft(seedAccountDraft(null)); setModal({ editing: null, needAuth: false }); };
|
|
2049
|
+
const openEdit = (a) => { setAccountDraft(seedAccountDraft(a)); setModal({ editing: a, needAuth: false }); };
|
|
2050
|
+
const closeModal = () => { setModal(null); setAccountDraft({}); setFolderOpts(null); setShowAdvanced(false); };
|
|
2051
|
+
|
|
2052
|
+
/** 设备码流指引横幅:Modal 打开时画在 Modal 里,否则画在账号卡里(同一个节点两处择一)。 */
|
|
2053
|
+
const authBanner = authPending ? h("div", { style: { margin: "8px 0", padding: "8px 10px", background: "rgba(59,130,246,0.1)", borderRadius: "6px" } },
|
|
2054
|
+
h("div", { style: { fontSize: "12px", marginBottom: "4px" } }, `${tt("account_auth_started", "设备码流已启动:")} ${authPending.email}`),
|
|
2055
|
+
// 2026-10-23 修复:横幅此前只写「打开验证链接」却不给链接和验证码。现在链接可点、验证码常显。
|
|
2056
|
+
h("div", { style: { fontSize: "12px", marginBottom: "2px" } },
|
|
2057
|
+
"1. 打开验证链接 ",
|
|
2058
|
+
h("a", {
|
|
2059
|
+
href: authPending.verificationUri ?? "https://www.microsoft.com/link",
|
|
2060
|
+
target: "_blank", rel: "noopener noreferrer",
|
|
2061
|
+
style: { textDecoration: "underline", wordBreak: "break-all" },
|
|
2062
|
+
}, authPending.verificationUri ?? "https://www.microsoft.com/link")),
|
|
2063
|
+
h("div", { style: { fontSize: "12px", marginBottom: "2px" } },
|
|
2064
|
+
"2. 输入微软验证码 ",
|
|
2065
|
+
h("span", { style: { fontFamily: "monospace", fontSize: "13px", fontWeight: 600, letterSpacing: "1px", userSelect: "all" } }, authPending.userCode ?? "?")),
|
|
2066
|
+
h("div", { style: { fontSize: "12px" } }, "3. 完成后点下方「完成认证」"),
|
|
2067
|
+
h("div", { style: S.actions, marginTop: "4px" },
|
|
2068
|
+
h("button", {
|
|
2069
|
+
type: "button",
|
|
2070
|
+
disabled: accountBusy,
|
|
2071
|
+
onClick: () => void handleAuthComplete(authPending.email),
|
|
2072
|
+
}, tt("btn_auth", "完成认证")),
|
|
2073
|
+
h("button", {
|
|
2074
|
+
type: "button",
|
|
2075
|
+
onClick: () => setAuthPending(null),
|
|
2076
|
+
}, tt("revert", "取消")),
|
|
2077
|
+
accountMessage ? h("span", { style: { ...S.msg, marginLeft: "8px" } }, accountMessage) : null
|
|
2078
|
+
)) : null;
|
|
2079
|
+
|
|
2080
|
+
// ============== 移植:卡片化设置树(参考 ui-design/MailboxSettings.jsx,antd → h()) ==============
|
|
2081
|
+
const rowOf = (label, control, key, hint) => h("div", { key, style: M.row },
|
|
2082
|
+
h("label", { style: M.rowLabel }, label), control,
|
|
2083
|
+
hint ? h("div", { style: S.hint }, hint) : null);
|
|
2084
|
+
|
|
2085
|
+
const notifyCard = h("div", { style: M.card },
|
|
2086
|
+
h("div", { style: M.cardHead },
|
|
2087
|
+
h("span", { style: M.cardTitle }, "📬 通知与消息投递"),
|
|
2088
|
+
h("button", { type: "button", style: B.btn, onClick: () => { void loadCandidates(); }, title: "拉取 dsh-im 机器人/投递目标候选" }, "刷新候选")),
|
|
2089
|
+
rowOf("投递机器人", botCtl(), "notify.botId", candNote || undefined),
|
|
2090
|
+
rowOf("投递目标", targetCtl(), "notify.targetId"),
|
|
2091
|
+
rowOf("通知", boolLabel("notify.enabled", "开启邮件通知"), "notify.enabled"),
|
|
2092
|
+
rowOf("重要性阈值", h("span", { style: { display: "inline-flex", alignItems: "center", gap: "6px" } },
|
|
2093
|
+
numCtl("notify.importanceThreshold", { min: 0, max: 100, width: "6em" }),
|
|
2094
|
+
h("span", { style: M.muted }, `${String(gv("notify.importanceThreshold", 0))} / 100`, info("0=全部通知;数字越大,只有越重要的邮件才打扰你"))), "notify.importanceThreshold"),
|
|
2095
|
+
rowOf("节流间隔", h("span", { style: { display: "inline-flex", alignItems: "center", gap: "6px" } },
|
|
2096
|
+
numCtl("notify.batch", { min: 1, max: 50, width: "6em" }),
|
|
2097
|
+
h("span", { style: M.muted }, "分钟内最多提醒一次", info("同一账号短时间来了一堆邮件时,合并成一条提醒"))), "notify.batch"),
|
|
2098
|
+
rowOf("验证码", boolLabel("includeCodes", "推送里直接给出验证码"), "notify.includeCodes", "关掉后推送里不再出现 🔑 验证码(含验证码的邮件仍会马上提醒)"),
|
|
2099
|
+
rowOf("每日汇总", boolLabel("dailyDigest.enabled", "每天早上发一封汇总"), "dailyDigest.enabled"),
|
|
2100
|
+
rowOf("汇总时间", timeCtl("dailyDigest.at"), "dailyDigest.at", "HH:MM(本地时区)"),
|
|
2101
|
+
rowOf("免打扰时段", textCtl("notify.quietHours", { width: "12em", placeholder: "23:00-07:30" }), "notify.quietHours", "该时段只记录不推送(格式 起-止)"));
|
|
2102
|
+
|
|
2103
|
+
const advNotify = h("div", { style: M.subcard },
|
|
2104
|
+
h("div", { style: M.subcardTitle }, "通知策略"),
|
|
2105
|
+
rowOf("通知渠道", selectCtl("notify.channel", [
|
|
2106
|
+
{ value: "auto", label: "自动选择(推荐)" },
|
|
2107
|
+
{ value: "im", label: "仅即时消息" },
|
|
2108
|
+
{ value: "local", label: "仅本地记录" },
|
|
2109
|
+
]), "notify.channel"),
|
|
2110
|
+
rowOf("过滤:跳过关键词", tagCtl("filter.skip", "输入关键词回车添加"), "filter.skip", "标题或正文命中就不提醒"),
|
|
2111
|
+
rowOf("过滤:只看关键词", tagCtl("filter.only", "输入关键词回车添加"), "filter.only", "只提醒命中的邮件(留空=不过滤)"));
|
|
2112
|
+
|
|
2113
|
+
const advWatcher = h("div", { style: M.subcard },
|
|
2114
|
+
h("div", { style: M.subcardTitle }, "后台检测"),
|
|
2115
|
+
rowOf("自动监控", boolLabel("watcher.enabled", "后台定时检查新邮件"), "watcher.enabled"),
|
|
2116
|
+
rowOf("轮询间隔", h("span", { style: { display: "inline-flex", alignItems: "center", gap: "6px" } },
|
|
2117
|
+
numCtl("watcher.pollIntervalSeconds", { min: 5, max: 3600, width: "8em" }),
|
|
2118
|
+
h("span", { style: M.muted }, "秒")), "watcher.pollIntervalSeconds"));
|
|
2119
|
+
|
|
2120
|
+
const advArchive = h("div", { style: M.subcard },
|
|
2121
|
+
h("div", { style: M.subcardTitle }, "归档与保留"),
|
|
2122
|
+
rowOf("归档模式", selectCtl("archive.mode", [
|
|
2123
|
+
{ value: "online", label: "仅计数,不存正文(纯在线)" },
|
|
2124
|
+
{ value: "metadata", label: "存元数据与摘要" },
|
|
2125
|
+
{ value: "full", label: "全量(本地落库)" },
|
|
2126
|
+
]), "archive.mode"),
|
|
2127
|
+
rowOf("正文快照", boolLabel("archive.snippet", "归档时保存正文开头片段"), "archive.snippet", "「存元数据与摘要 / 全量」模式生效"),
|
|
2128
|
+
rowOf("保留天数", numCtl("archive.retentionDays", { min: 1, max: 3650, width: "8em" }), "archive.retentionDays", "0 = 永久保留"),
|
|
2129
|
+
rowOf("库容量上限", h("span", { style: { display: "inline-flex", alignItems: "center", gap: "6px" } },
|
|
2130
|
+
numCtl("archive.maxBytes", { min: 0, max: 1073741824, width: "12em" }),
|
|
2131
|
+
h("span", { style: M.muted }, "字节", info("0 = 不限;非 0 时超过该体积自动清理最旧的原文"))), "archive.maxBytes"),
|
|
2132
|
+
rowOf("元数据维护", numCtl("archive.maintenanceDays", { min: 0, max: 3650, width: "8em" }), "archive.maintenanceDays", "服务器上早已没有的邮件、陈年通知超过这么多天就清掉(连带索引),0 = 不清"));
|
|
2133
|
+
|
|
2134
|
+
// 2026-11-30「可配置参数搬进配置页」:收发与内容(两项热生效)+ 只能重启生效的开关(只读回显)
|
|
2135
|
+
const ro = statusView?.readonly ?? {};
|
|
2136
|
+
const advMail = h("div", { style: M.subcard },
|
|
2137
|
+
h("div", { style: M.subcardTitle }, "收发与内容"),
|
|
2138
|
+
rowOf("正文截断", h("span", { style: { display: "inline-flex", alignItems: "center", gap: "6px" } },
|
|
2139
|
+
numCtl("mail.bodyLimit", { min: 200, max: 20000, width: "8em" }),
|
|
2140
|
+
h("span", { style: M.muted }, "字符", info("读信时正文最多显示多少字符;默认 4000。改完下一次读信就生效"))), "mail.bodyLimit"),
|
|
2141
|
+
rowOf("附件落盘上限", h("span", { style: { display: "inline-flex", alignItems: "center", gap: "6px" } },
|
|
2142
|
+
mbCtl("mail.attachMaxBytes", { max: 1024 }),
|
|
2143
|
+
h("span", { style: M.muted }, "MB", info("单封邮件附件落盘上限(0 = 不限);超出的附件跳过并提示,已在面板预览的 10 MB 上限另算"))), "mail.attachMaxBytes"),
|
|
2144
|
+
rowOf("写工具开关", h("span", { style: M.muted }, ro.writeEnabled
|
|
2145
|
+
? "已开启(只读:改部署层 write.enabled 后重启)"
|
|
2146
|
+
: "未开启(只读:改部署层 write.enabled 后重启)"), "readonly.write"),
|
|
2147
|
+
rowOf("LLM 语义", h("span", { style: M.muted }, (ro.llmSummary || ro.llmSemantic)
|
|
2148
|
+
? `摘要 ${ro.llmSummary ? "开" : "关"} · 语义标签 ${ro.llmSemantic ? "开" : "关"}(宿主配置页改,重启生效)`
|
|
2149
|
+
: "全关(零外送;宿主配置页开启后重启生效)"), "readonly.llm"));
|
|
2150
|
+
|
|
2151
|
+
const advancedCard = h("div", { style: M.card },
|
|
2152
|
+
h("div", { style: { ...M.cardHead, cursor: "pointer" }, onClick: () => setAdvOpen((v) => !v) },
|
|
2153
|
+
h("span", { style: M.cardTitle }, "▶ 高级策略"),
|
|
2154
|
+
h("span", { style: M.muted }, advOpen ? "收起" : "展开")),
|
|
2155
|
+
advOpen ? h("div", null, advNotify, advWatcher, advArchive, advMail) : null);
|
|
2156
|
+
|
|
2157
|
+
// ── 🔗 连接与同步状态(2026-11-30):把"链路到底通不通"搬到配置页,不再只能翻日志 ──
|
|
2158
|
+
const statusHealth = Array.isArray(statusView?.health) ? statusView.health : [];
|
|
2159
|
+
const statusWs = statusView?.watcher ?? null;
|
|
2160
|
+
const authRowOf = (email) => accountsList.find((a) => String(a.email) === String(email)) ?? null;
|
|
2161
|
+
const authText = (a) => {
|
|
2162
|
+
if (!a) return "账号不在配置里";
|
|
2163
|
+
if (!a.authorized) return "未授权(点下方账户卡的「立即授权」)";
|
|
2164
|
+
const m = Math.round(Number(a.remainSeconds ?? 0) / 60);
|
|
2165
|
+
return m > 0 ? `已授权(令牌约剩 ${m} 分钟)` : "已授权";
|
|
2166
|
+
};
|
|
2167
|
+
// 体检清单(2026-11-30):把「为什么收不到信 / 发不出通知」拆成可执行的几条。
|
|
2168
|
+
// 只报能修的问题,并按"修它的地方"给提示 —— 不堆无关信息。
|
|
2169
|
+
const issues = [];
|
|
2170
|
+
if (typeof window !== "undefined") { /* 浏览器侧永远成立,留着给 SSR 兜底 */ }
|
|
2171
|
+
if (!statusView) {
|
|
2172
|
+
issues.push({ key: "no-bridge", text: "宿主没挂邮件桥:面板状态未知(工具面仍可用),重启 DSH 后回来刷新。", fix: "重启 DSH" });
|
|
2173
|
+
} else {
|
|
2174
|
+
if (accountsList.length === 0) issues.push({ key: "no-account", text: "还没有绑定邮箱账户。", fix: "点下方「添加邮箱账户」" });
|
|
2175
|
+
const unauth = accountsList.filter((a) => !a.authorized);
|
|
2176
|
+
if (unauth.length) {
|
|
2177
|
+
issues.push({ key: "unauth", text: `${unauth.length} 个账号未完成授权(${unauth.map((a) => a.alias || a.email).join("、")}),收不到新邮件。`, fix: "点账户卡的「立即授权」" });
|
|
2178
|
+
}
|
|
2179
|
+
const ch = String(gv("notify.channel", "auto") ?? "auto");
|
|
2180
|
+
if (ch !== "local" && statusView.notify && statusView.notify.targetReady === false) {
|
|
2181
|
+
issues.push({ key: "im", text: `通知通道没配好(方式=${ch || "auto"},但没有可投递的 bot/target)。`, fix: "在本卡「通知与消息投递」里选目标,或去 设置 → IM机器人 接入" });
|
|
2182
|
+
}
|
|
2183
|
+
if (statusWs && !statusWs.running) {
|
|
2184
|
+
issues.push({ key: "watcher", text: `后台检查没在跑:${statusWs.reason || "未知原因"}`, fix: statusWs.reason?.includes("开关") ? "把「后台检查」打开并保存" : "重启 DSH,或关掉另一个占着归档的窗口" });
|
|
2185
|
+
}
|
|
2186
|
+
const bad = statusHealth.filter((x) => x.health === "auth-error" || x.health === "error");
|
|
2187
|
+
if (bad.length) {
|
|
2188
|
+
issues.push({ key: "bad", text: `${bad.length} 个文件夹同步失败(最近错误:${String(bad[0].lastError || "未知").slice(0, 80)})。`, fix: bad[0].health === "auth-error" ? "重新授权该账号" : "看一眼「最近一次错误」,按提示处理" });
|
|
2189
|
+
}
|
|
2190
|
+
if (statusView.settingsTarget === "file") {
|
|
2191
|
+
issues.push({ key: "settings", text: "宿主配置页不可写,改动只落在 settings.json(本插件照常生效)。", fix: "如需宿主托管,检查 DSH 版本/权限" });
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
const testChannel = async () => {
|
|
2195
|
+
setTestResult({ ok: null, text: "发送中…" });
|
|
2196
|
+
try {
|
|
2197
|
+
const r = await bridgeCall("/notify-test", {});
|
|
2198
|
+
if (r?.ok && r.value) {
|
|
2199
|
+
setTestResult({ ok: r.value.ok === true, text: r.value.message || (r.value.ok ? "已发送" : "未发送") });
|
|
2200
|
+
} else {
|
|
2201
|
+
setTestResult({ ok: false, text: `${r?.message ?? "测试失败"}${r?.code ? `(${r.code})` : ""}` });
|
|
2202
|
+
}
|
|
2203
|
+
} catch (e) {
|
|
2204
|
+
setTestResult({ ok: false, text: `测试失败:${e?.message ?? e}` });
|
|
2205
|
+
}
|
|
2206
|
+
};
|
|
2207
|
+
const statusCard = h("div", { style: M.card },
|
|
2208
|
+
h("div", { style: M.cardHead },
|
|
2209
|
+
h("span", { style: M.cardTitle }, "🔗 连接与同步状态"),
|
|
2210
|
+
h("button", {
|
|
2211
|
+
type: "button", style: { ...M.chipX, width: "auto", padding: "0 8px" },
|
|
2212
|
+
disabled: busy || accountBusy || testResult?.text === "发送中…",
|
|
2213
|
+
title: "往当前通知渠道发一条测试消息(和 mailbox_notify action=test 同一条路径)",
|
|
2214
|
+
onClick: () => void testChannel(),
|
|
2215
|
+
}, "发测试消息"),
|
|
2216
|
+
h("button", {
|
|
2217
|
+
type: "button", style: { ...M.chipX, width: "auto", padding: "0 8px" },
|
|
2218
|
+
disabled: busy || accountBusy,
|
|
2219
|
+
title: "立刻让后台抓一轮(和浮动栏的「立刻检查」是同一个动作)",
|
|
2220
|
+
onClick: async () => {
|
|
2221
|
+
try { await bridgeCall("/check", {}); } catch { /* 桥没挂就算了,下面重拉会显示状态未知 */ }
|
|
2222
|
+
await fetchStatus(); await fetchAccounts();
|
|
2223
|
+
},
|
|
2224
|
+
}, "立刻检查")),
|
|
2225
|
+
testResult
|
|
2226
|
+
? h("div", {
|
|
2227
|
+
style: {
|
|
2228
|
+
fontSize: "12px", padding: "4px 8px", marginBottom: "6px", borderRadius: "6px",
|
|
2229
|
+
background: testResult.ok === true ? "rgba(34,197,94,0.12)" : testResult.ok === false ? "rgba(192,57,43,0.10)" : "rgba(0,0,0,0.05)",
|
|
2230
|
+
color: testResult.ok === true ? "#15803d" : testResult.ok === false ? "#c0392b" : "inherit",
|
|
2231
|
+
},
|
|
2232
|
+
}, `${testResult.ok === true ? "✅" : testResult.ok === false ? "⚠️" : "…"} ${testResult.text}`)
|
|
2233
|
+
: null,
|
|
2234
|
+
issues.length
|
|
2235
|
+
? h("div", { style: { marginBottom: "8px" } },
|
|
2236
|
+
issues.map((it) => h("div", { key: `is-${it.key}`, style: { fontSize: "12px", padding: "2px 0", display: "flex", gap: "8px" } },
|
|
2237
|
+
h("span", { style: { color: "#c0392b" } }, "⛔"),
|
|
2238
|
+
h("span", { style: { flex: "1", minWidth: "0" } }, it.text),
|
|
2239
|
+
h("span", { style: { opacity: 0.7, whiteSpace: "nowrap" } }, `→ ${it.fix}`))))
|
|
2240
|
+
: h("div", { style: { fontSize: "12px", color: "#15803d", marginBottom: "8px" } }, "✅ 体检通过:账号、通道、后台检查都没发现问题"),
|
|
2241
|
+
!statusView
|
|
2242
|
+
? h("div", { style: M.muted }, "宿主没挂邮件桥或还没起来 —— 状态未知(工具面仍可用)")
|
|
2243
|
+
: h("div", null,
|
|
2244
|
+
h("div", { style: { fontSize: "12px", display: "flex", gap: "10px", flexWrap: "wrap", marginBottom: "6px" } },
|
|
2245
|
+
h("span", null, statusWs
|
|
2246
|
+
? (statusWs.running ? `后台检查:运行中(每 ${statusWs.pollIntervalSeconds ?? "?"} 秒)` : `后台检查:${statusWs.reason || "未运行"}`)
|
|
2247
|
+
: "后台检查:未知"),
|
|
2248
|
+
h("span", null, `通知通道:${statusView.notify?.targetReady ? "就绪" : "未就绪"}`),
|
|
2249
|
+
h("span", null, `归档模式:${statusView.archiveMode ?? "?"}`)),
|
|
2250
|
+
statusHealth.length === 0
|
|
2251
|
+
? h("div", { style: M.muted }, "还没有同步记录(等第一轮抓取,或点上面的「立刻检查」)")
|
|
2252
|
+
: statusHealth.map((x) => {
|
|
2253
|
+
const a = authRowOf(x.account);
|
|
2254
|
+
const bad = x.health === "auth-error" || x.health === "error";
|
|
2255
|
+
return h("div", {
|
|
2256
|
+
key: `h-${x.account}-${x.folder}`,
|
|
2257
|
+
style: { fontSize: "12px", display: "flex", gap: "10px", justifyContent: "space-between", padding: "2px 0", opacity: bad ? 1 : 0.9 },
|
|
2258
|
+
},
|
|
2259
|
+
h("span", null, `${a?.alias || x.alias || x.account} · ${x.folder}`),
|
|
2260
|
+
h("span", { style: { color: bad ? "#c0392b" : "inherit" } },
|
|
2261
|
+
`${healthText(x.health)} · ${authText(a)} · 上次成功 ${agoText(x.lastOkAt)}`));
|
|
2262
|
+
}),
|
|
2263
|
+
statusHealth.some((x) => x.lastError)
|
|
2264
|
+
? h("div", { style: { fontSize: "11.5px", opacity: 0.75, marginTop: "4px" } },
|
|
2265
|
+
`最近一次错误:${String(statusHealth.find((x) => x.lastError)?.lastError ?? "").slice(0, 160)}`)
|
|
2266
|
+
: null,
|
|
2267
|
+
Array.isArray(statusView.warnings) && statusView.warnings.length
|
|
2268
|
+
? h("div", { style: { fontSize: "11.5px", opacity: 0.75, marginTop: "4px" } },
|
|
2269
|
+
statusView.warnings.slice(0, 3).map((w, i) => h("div", { key: `w-${i}` }, `⚠️ ${w}`)))
|
|
2270
|
+
: null));
|
|
2271
|
+
|
|
2272
|
+
const accountsCard = h("div", { style: M.card },
|
|
2273
|
+
h("div", { style: M.cardHead },
|
|
2274
|
+
h("span", { style: M.cardTitle }, "📧 已绑定的邮箱账户")),
|
|
2275
|
+
accountError ? h("div", { style: S.err }, accountError) : null,
|
|
2276
|
+
accountsList.length === 0
|
|
2277
|
+
? h("div", { style: M.muted }, tt("account_no_accounts", "还没有绑定邮箱。点「添加邮箱账户」开始。"))
|
|
2278
|
+
: h("div", null, accountsList.map((a) => {
|
|
2279
|
+
const foldersNow = Array.isArray(a.folders) && a.folders.length ? a.folders : [a.defaultFolder || "INBOX"];
|
|
2280
|
+
return h("div", { key: a.email, style: M.acctRow },
|
|
2281
|
+
h("span", { style: M.badge, title: a.authorized ? "OAuth2 已授权" : "尚未完成授权" },
|
|
2282
|
+
h("span", { style: M.badgeDot(a.authorized ? "#22c55e" : "#f59e0b") }), a.authorized ? "已授权" : "未授权"),
|
|
2283
|
+
h("div", { style: { flex: "1", minWidth: "0" } },
|
|
2284
|
+
h("div", { style: M.acctName }, a.alias && a.alias !== a.email ? a.alias : a.email,
|
|
2285
|
+
a.alias && a.alias !== a.email ? h("span", { style: M.acctSub }, ` ${a.email}`) : null),
|
|
2286
|
+
h("div", { style: M.acctSub },
|
|
2287
|
+
a.source === "deploy" ? h("span", { style: M.tag, title: tt("account_delete_deploy_hint", "部署层账号在宿主配置页管理,这里删不掉") }, "部署配置") : null,
|
|
2288
|
+
`同步 ${foldersNow.length} 个文件夹`, ` · ${foldersNow.join(", ")}`)),
|
|
2289
|
+
!a.authorized
|
|
2290
|
+
? h("button", {
|
|
2291
|
+
type: "button", className: M.breath, disabled: accountBusy || authPending?.email === a.email,
|
|
2292
|
+
onClick: () => void handleAuthDevice(a.email),
|
|
2293
|
+
}, authPending?.email === a.email ? "认证中…" : "立即授权")
|
|
2294
|
+
: null,
|
|
2295
|
+
h("button", {
|
|
2296
|
+
type: "button", title: tt("btn_edit_hint", "修改别名 / 监控文件夹 / 端点"),
|
|
2297
|
+
disabled: accountBusy,
|
|
2298
|
+
onClick: () => openEdit(a),
|
|
2299
|
+
}, "📝"),
|
|
2300
|
+
h("button", {
|
|
2301
|
+
type: "button", title: tt("btn_resync_hint", "重置水位并回填该账户监控文件夹的全部历史邮件(≤重置时刻的邮件只入库不通知)"),
|
|
2302
|
+
disabled: accountBusy,
|
|
2303
|
+
onClick: () => void handleResyncAccount(a.email),
|
|
2304
|
+
}, "🔄"),
|
|
2305
|
+
h("button", {
|
|
2306
|
+
type: "button", style: { opacity: a.source === "deploy" ? 0.35 : 0.6 },
|
|
2307
|
+
disabled: accountBusy || a.source === "deploy",
|
|
2308
|
+
title: a.source === "deploy" ? tt("account_delete_deploy_hint", "部署层账号在宿主配置页管理,这里删不掉") : tt("btn_delete", "删除"),
|
|
2309
|
+
onClick: () => void handleDeleteAccount(a.email),
|
|
2310
|
+
}, "🗑️"));
|
|
2311
|
+
})),
|
|
2312
|
+
// 认证横幅:Modal 没开时画在账号卡里(Modal 开着时画在 Modal 里,同一个节点二选一)
|
|
2313
|
+
(!modal && authBanner) ? authBanner : null,
|
|
2314
|
+
h("div", { style: { marginTop: "10px" } },
|
|
2315
|
+
h("button", { type: "button", style: M.primary, disabled: !writable || accountBusy, onClick: openAdd },
|
|
2316
|
+
tt("btn_add_account", "添加邮箱账户"))));
|
|
2317
|
+
|
|
2318
|
+
return h("div", { style: S.wrap },
|
|
2319
|
+
h("style", null, SETTINGS_CSS),
|
|
2320
|
+
// 状态行只留用户需要关心的:能不能写、当前 revision(有变化时对不上就说明有并发)
|
|
2321
|
+
h("div", { style: S.status },
|
|
2322
|
+
`${writable ? "可编辑" : "只读(远程 Web 不持久化)"} · revision=${String(revision)}`),
|
|
2323
|
+
// 账户卡放最上面(2026-11-30 用户要求):先看"装了谁",再看链路,最后才是策略
|
|
2324
|
+
accountsCard,
|
|
2325
|
+
statusCard,
|
|
2326
|
+
notifyCard,
|
|
2327
|
+
advancedCard,
|
|
2328
|
+
h("div", { style: S.actions },
|
|
2329
|
+
h("button", { type: "button", disabled: !writable || busy, onClick: onSave }, tt("save", "Save")),
|
|
2330
|
+
h("button", { type: "button", onClick: () => { setDraft({}); setMessage(""); setError(""); } }, tt("revert", "Revert")),
|
|
2331
|
+
h("button", { type: "button", onClick: () => { void refresh(); } }, tt("refresh", "Reload")),
|
|
2332
|
+
h("button", {
|
|
2333
|
+
type: "button",
|
|
2334
|
+
title: "把当前生效的运行层设置导成 JSON(账户密码/令牌不在里面)",
|
|
2335
|
+
onClick: () => {
|
|
2336
|
+
// 导出只给"可复制走的一份快照":运行层字段 + 时间戳,不含 token。
|
|
2337
|
+
try {
|
|
2338
|
+
const payload = { exportedAt: new Date().toISOString(), plugin: "mailbox", settings: runtimeValue ?? {} };
|
|
2339
|
+
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: "application/json" });
|
|
2340
|
+
const url = URL.createObjectURL(blob);
|
|
2341
|
+
const a = document.createElement("a");
|
|
2342
|
+
a.href = url;
|
|
2343
|
+
a.download = `mailbox-settings-${new Date().toISOString().slice(0, 10)}.json`;
|
|
2344
|
+
document.body.appendChild(a);
|
|
2345
|
+
a.click();
|
|
2346
|
+
a.remove();
|
|
2347
|
+
setTimeout(() => URL.revokeObjectURL(url), 30_000);
|
|
2348
|
+
setMessage("已导出设置 JSON(不含令牌)");
|
|
2349
|
+
} catch (e) {
|
|
2350
|
+
setError(`导出失败:${e?.message ?? e}`);
|
|
2351
|
+
}
|
|
2352
|
+
},
|
|
2353
|
+
}, "导出设置"),
|
|
2354
|
+
h("button", {
|
|
2355
|
+
type: "button",
|
|
2356
|
+
title: "选一个导出的 JSON:只回填表单,点「Save」才真正生效",
|
|
2357
|
+
onClick: () => {
|
|
2358
|
+
// 导入只回填草稿:认 SETTINGS_FIELDS 里存在的路径(未知键一律忽略,防脏数据),
|
|
2359
|
+
// 不直接写盘 —— 用户还能改、能撤销,点 Save 才落 runtime,避免"一导入就生效"的惊吓。
|
|
2360
|
+
try {
|
|
2361
|
+
const input = document.createElement("input");
|
|
2362
|
+
input.type = "file";
|
|
2363
|
+
input.accept = "application/json,.json";
|
|
2364
|
+
input.onchange = async () => {
|
|
2365
|
+
const file = input.files && input.files[0];
|
|
2366
|
+
if (!file) return;
|
|
2367
|
+
try {
|
|
2368
|
+
const parsed = JSON.parse(await file.text());
|
|
2369
|
+
const src = parsed && typeof parsed === "object" && parsed.settings && typeof parsed.settings === "object"
|
|
2370
|
+
? parsed.settings
|
|
2371
|
+
: null;
|
|
2372
|
+
if (!src) { setError("这个 JSON 里没有 settings 字段,不是本插件导出的格式"); return; }
|
|
2373
|
+
const patch = {};
|
|
2374
|
+
let n = 0;
|
|
2375
|
+
for (const field of FIELDS) {
|
|
2376
|
+
const value = getIn(src, field.path);
|
|
2377
|
+
if (value === undefined || value === null) continue;
|
|
2378
|
+
if (value !== null && typeof value === "object") continue;
|
|
2379
|
+
patch[keyOf(field)] = field.type === "bool" ? Boolean(value) : String(value);
|
|
2380
|
+
n += 1;
|
|
2381
|
+
}
|
|
2382
|
+
if (!n) { setError("导入的文件里没有可识别的设置项"); return; }
|
|
2383
|
+
setDraft((prev) => ({ ...prev, ...patch }));
|
|
2384
|
+
setError("");
|
|
2385
|
+
setMessage(`已读入 ${n} 项设置,点「Save」后生效`);
|
|
2386
|
+
} catch (e) {
|
|
2387
|
+
setError(`导入失败:${e?.message ?? e}`);
|
|
2388
|
+
}
|
|
2389
|
+
};
|
|
2390
|
+
input.click();
|
|
2391
|
+
} catch (e) {
|
|
2392
|
+
setError(`导入失败:${e?.message ?? e}`);
|
|
2393
|
+
}
|
|
2394
|
+
},
|
|
2395
|
+
}, "导入设置"),
|
|
2396
|
+
h("button", { type: "button", onClick: () => setShowRaw((v) => !v) }, tt("state", "raw state")),
|
|
2397
|
+
message ? h("span", { style: S.msg }, message) : null),
|
|
2398
|
+
error ? h("div", { style: S.err }, error) : null,
|
|
2399
|
+
showRaw ? h("pre", { style: S.raw },
|
|
2400
|
+
JSON.stringify({ live, page: { value: pageState.value, user: pageState.user, base: pageState.base, revision: pageState.revision }, draft }, null, 2)) : null,
|
|
2401
|
+
!writable ? h("div", { style: { fontSize: "12px", opacity: 0.8 } }, tt("readonlyRemote", "read-only")) : null,
|
|
2402
|
+
// ============== 添加/编辑账号 Modal(主信息流外;backdrop 点击关闭) ==============
|
|
2403
|
+
modal ? h("div", { style: M.mask, onClick: (e) => { if (e.target === e.currentTarget) closeModal(); } },
|
|
2404
|
+
h("div", { style: M.modal, role: "dialog", "aria-modal": "true" },
|
|
2405
|
+
h("div", { style: M.modalHead },
|
|
2406
|
+
h("span", { style: M.modalTitle },
|
|
2407
|
+
modal.editing ? tt("btn_edit", "编辑账号") : tt("btn_add_account", "添加邮箱账户")),
|
|
2408
|
+
h("button", { type: "button", style: M.chipX, onClick: closeModal }, "✕")),
|
|
2409
|
+
modal.needAuth ? h("div", { style: M.banner },
|
|
2410
|
+
"账号已保存,但还没完成授权 —— 只有授权后才能收新邮件。点下方「立即授权」:") : null,
|
|
2411
|
+
authBanner,
|
|
2412
|
+
h("div", { style: M.row },
|
|
2413
|
+
h("label", { style: M.rowLabel }, tt("label_account_email", "邮箱地址")),
|
|
2414
|
+
modal.editing ? h("span", { style: { display: "inline-flex", alignItems: "center", gap: "8px" } },
|
|
2415
|
+
h("span", { style: { fontWeight: 600 } }, modal.editing.email),
|
|
2416
|
+
h("span", { style: M.muted }, "邮箱是账号主键,编辑时不可改"))
|
|
2417
|
+
: h("input", {
|
|
2418
|
+
type: "text", disabled: !writable || accountBusy,
|
|
2419
|
+
value: accountDraft.email ?? "", style: { width: "240px" },
|
|
2420
|
+
placeholder: tt("placeholder_email", "yourname@outlook.com"),
|
|
2421
|
+
onChange: (e) => setAccountDraft((prev) => ({ ...prev, email: e.target.value })),
|
|
2422
|
+
})),
|
|
2423
|
+
h("div", { style: M.row },
|
|
2424
|
+
h("label", { style: M.rowLabel }, tt("label_account_alias", "别名")),
|
|
2425
|
+
h("input", {
|
|
2426
|
+
type: "text", disabled: !writable || accountBusy,
|
|
2427
|
+
value: accountDraft.alias ?? "", style: { width: "240px" },
|
|
2428
|
+
placeholder: tt("placeholder_alias", "主邮箱"),
|
|
2429
|
+
onChange: (e) => setAccountDraft((prev) => ({ ...prev, alias: e.target.value })),
|
|
2430
|
+
}),
|
|
2431
|
+
h("span", { style: M.muted }, tt("hint_account_alias", "工具中用来指代这个账号,留空则用邮箱地址"))),
|
|
2432
|
+
// ---- 监控文件夹:FolderPicker(参考实现;INBOX 常驻 + 勾选区可折叠) ----
|
|
2433
|
+
h("div", { style: M.row },
|
|
2434
|
+
h("label", { style: M.rowLabel }, tt("label_account_folders", "同步文件夹")),
|
|
2435
|
+
h("button", {
|
|
2436
|
+
type: "button", style: { ...B.btn, opacity: 0.8 },
|
|
2437
|
+
disabled: accountBusy || folderLoading || !String(accountDraft.email ?? "").trim(),
|
|
2438
|
+
title: tt("hint_account_folders_btn", "真连该邮箱列一遍 IMAP 文件夹,勾选要监控的"),
|
|
2439
|
+
onClick: () => void loadFolderOpts(accountDraft.email),
|
|
2440
|
+
}, folderLoading ? "读取中…" : "📁 从服务器读取文件夹")),
|
|
2441
|
+
h("div", { key: "folder-zone", className: M.zone, "data-open": folderZoneOpen ? "true" : "false" },
|
|
2442
|
+
folderOpts?.email === String(accountDraft.email ?? "").trim() && Array.isArray(folderOpts.folders)
|
|
2443
|
+
? h("div", { style: { padding: "6px 2px" } },
|
|
2444
|
+
h("div", { style: { marginBottom: "6px" } },
|
|
2445
|
+
h("label", { style: { display: "inline-flex", alignItems: "center", gap: "6px", fontSize: "12px" } },
|
|
2446
|
+
h("input", { type: "checkbox", checked: true, disabled: true }),
|
|
2447
|
+
"INBOX",
|
|
2448
|
+
h("span", { style: M.muted }, "默认收件箱,始终监控"))),
|
|
2449
|
+
h("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px 12px" } },
|
|
2450
|
+
folderOpts.folders.filter((name) => name !== "INBOX").map((name) => {
|
|
2451
|
+
const cur = Array.isArray(accountDraft.folders) ? accountDraft.folders : [];
|
|
2452
|
+
const checked = cur.includes(name);
|
|
2453
|
+
return h("label", { key: name, style: { display: "flex", alignItems: "center", gap: "4px", fontSize: "12px", cursor: "pointer" } },
|
|
2454
|
+
h("input", {
|
|
2455
|
+
type: "checkbox", disabled: !writable || accountBusy, checked,
|
|
2456
|
+
onChange: () => setAccountDraft((prev) => {
|
|
2457
|
+
const cur2 = Array.isArray(prev.folders) ? prev.folders : [];
|
|
2458
|
+
return { ...prev, folders: cur2.includes(name) ? cur2.filter((f) => f !== name) : [...cur2, name] };
|
|
2459
|
+
}),
|
|
2460
|
+
}),
|
|
2461
|
+
name);
|
|
2462
|
+
})),
|
|
2463
|
+
h("div", { style: S.hint }, tt("hint_account_folders_checks",
|
|
2464
|
+
"全不勾保存 = 清空监控范围(回默认文件夹);保存后下一轮轮询生效,免重启")))
|
|
2465
|
+
: h("div", { style: { padding: "6px 2px" } },
|
|
2466
|
+
h("div", { style: S.row },
|
|
2467
|
+
h("input", {
|
|
2468
|
+
type: "text", disabled: !writable || accountBusy,
|
|
2469
|
+
value: Array.isArray(accountDraft.folders) ? accountDraft.folders.join(", ") : (accountDraft.folders ?? ""),
|
|
2470
|
+
style: { width: "260px" }, placeholder: tt("placeholder_folders", "INBOX, INBOX/Projects"),
|
|
2471
|
+
onChange: (e) => setAccountDraft((prev) => ({ ...prev, folders: e.target.value })),
|
|
2472
|
+
}),
|
|
2473
|
+
h("span", { style: M.muted }, folderOpts?.note
|
|
2474
|
+
? `读取失败(${folderOpts.note}),可手动输入`
|
|
2475
|
+
: "逗号分隔;留空=只监控 INBOX")),
|
|
2476
|
+
h("div", { style: S.hint }, tt("hint_account_folders_form",
|
|
2477
|
+
"名称与 IMAP 一致(子文件夹用 / ,如 INBOX/Projects)。保存后下一轮轮询生效,免重启")))),
|
|
2478
|
+
h("div", { style: M.row },
|
|
2479
|
+
h("button", {
|
|
2480
|
+
type: "button", style: { ...B.btn, opacity: 0.75 },
|
|
2481
|
+
onClick: () => setShowAdvanced((v) => !v),
|
|
2482
|
+
}, tt("account_advanced_toggle", "高级选项:IMAP/SMTP 端点(一般保持默认)") + (showAdvanced ? " ▾" : " ▸"))),
|
|
2483
|
+
...(showAdvanced ? [
|
|
2484
|
+
h("div", { key: "adv-hint", style: S.hint },
|
|
2485
|
+
tt("account_advanced_hint", "授权始终走微软 OAuth2 设备码流(Thunderbird 公共 Client ID,免注册、无需密码);下面的端点只对 Outlook/Hotmail 等 Microsoft 个人邮箱有效,非 Microsoft 邮箱不支持。")),
|
|
2486
|
+
h("div", { key: "adv-imap", style: M.row },
|
|
2487
|
+
h("label", { style: M.rowLabel }, tt("label_account_imap_host", "IMAP 主机")),
|
|
2488
|
+
h("input", {
|
|
2489
|
+
type: "text", disabled: !writable || accountBusy,
|
|
2490
|
+
value: accountDraft.imapHost ?? "outlook.office365.com", style: { width: "150px" },
|
|
2491
|
+
onChange: (e) => setAccountDraft((prev) => ({ ...prev, imapHost: e.target.value })),
|
|
2492
|
+
}),
|
|
2493
|
+
h("label", { style: M.rowLabel }, tt("label_account_imap_port", "端口")),
|
|
2494
|
+
h("input", {
|
|
2495
|
+
type: "number", disabled: !writable || accountBusy,
|
|
2496
|
+
value: accountDraft.imapPort ?? 993, style: { width: "80px" },
|
|
2497
|
+
onChange: (e) => setAccountDraft((prev) => ({ ...prev, imapPort: Number(e.target.value) || 993 })),
|
|
2498
|
+
}),
|
|
2499
|
+
h("span", { style: M.muted }, tt("hint_account_imap", "默认 outlook.office365.com:993"))),
|
|
2500
|
+
h("div", { key: "adv-smtp", style: M.row },
|
|
2501
|
+
h("label", { style: M.rowLabel }, tt("label_account_smtp_host", "SMTP 主机")),
|
|
2502
|
+
h("input", {
|
|
2503
|
+
type: "text", disabled: !writable || accountBusy,
|
|
2504
|
+
value: accountDraft.smtpHost ?? "smtp-mail.outlook.com", style: { width: "150px" },
|
|
2505
|
+
onChange: (e) => setAccountDraft((prev) => ({ ...prev, smtpHost: e.target.value })),
|
|
2506
|
+
}),
|
|
2507
|
+
h("label", { style: M.rowLabel }, tt("label_account_smtp_port", "端口")),
|
|
2508
|
+
h("input", {
|
|
2509
|
+
type: "number", disabled: !writable || accountBusy,
|
|
2510
|
+
value: accountDraft.smtpPort ?? 587, style: { width: "80px" },
|
|
2511
|
+
onChange: (e) => setAccountDraft((prev) => ({ ...prev, smtpPort: Number(e.target.value) || 587 })),
|
|
2512
|
+
}),
|
|
2513
|
+
h("span", { style: M.muted }, tt("hint_account_smtp", "默认 smtp-mail.outlook.com:587"))),
|
|
2514
|
+
h("div", { key: "adv-folder", style: M.row },
|
|
2515
|
+
h("label", { style: M.rowLabel }, tt("label_account_default_folder", "默认文件夹")),
|
|
2516
|
+
h("input", {
|
|
2517
|
+
type: "text", disabled: !writable || accountBusy,
|
|
2518
|
+
value: accountDraft.defaultFolder ?? "INBOX", style: { width: "120px" },
|
|
2519
|
+
onChange: (e) => setAccountDraft((prev) => ({ ...prev, defaultFolder: e.target.value })),
|
|
2520
|
+
}),
|
|
2521
|
+
h("span", { style: M.muted }, tt("hint_account_folder", "默认 INBOX"))),
|
|
2522
|
+
] : []),
|
|
2523
|
+
h("div", { style: M.foot },
|
|
2524
|
+
modal.needAuth
|
|
2525
|
+
? h("button", {
|
|
2526
|
+
type: "button", className: M.breath,
|
|
2527
|
+
disabled: accountBusy || !String(accountDraft.email ?? "").trim(),
|
|
2528
|
+
onClick: () => void handleAuthDevice(String(accountDraft.email ?? "").trim()),
|
|
2529
|
+
}, "立即授权")
|
|
2530
|
+
: null,
|
|
2531
|
+
h("button", { type: "button", onClick: closeModal }, tt("revert", "取消")),
|
|
2532
|
+
h("button", {
|
|
2533
|
+
type: "button", style: M.primary,
|
|
2534
|
+
disabled: !writable || accountBusy || !accountDraft.email,
|
|
2535
|
+
onClick: () => void handleAddAccount(),
|
|
2536
|
+
}, accountBusy ? tt("account_adding", "添加中...")
|
|
2537
|
+
: (modal.editing || (accountDraft.email && accountsList.some((a) => a.email === String(accountDraft.email).trim()))
|
|
2538
|
+
? tt("btn_save_account", "保存修改")
|
|
2539
|
+
: tt("btn_add_account", "添加账号"))),
|
|
2540
|
+
accountMessage ? h("span", { style: S.msg }, accountMessage) : null),
|
|
2541
|
+
accountError ? h("div", { style: S.err }, accountError) : null))
|
|
2542
|
+
: null);
|
|
2543
|
+
}
|
|
2544
|
+
|
|
2545
|
+
const inject = ["slots", "locale"];
|
|
2546
|
+
|
|
2547
|
+
function apply(ctx) {
|
|
2548
|
+
// ⚠️ 浏览器半边唯一的诊断出口是 console:`apply` 里任何静默失败都会表现为
|
|
2549
|
+
// "提示栏凭空消失",而宿主侧日志完全看不到。所以这里起一条 **[mailbox-client]**
|
|
2550
|
+
// 面包屑线,把"走到哪一步、看到什么、注册结果如何"全部打出来 —— 下次再出现
|
|
2551
|
+
// 「插件在但提示栏不在」时,先看 console 就能一句话定位,不必再反推槽位树。
|
|
2552
|
+
// ⚠️ 必须**先声明再使用**(const 有 TDZ)—— 这里踩过一次,由 client-bar 的
|
|
2553
|
+
// 「未抛异常」护栏逮住。
|
|
2554
|
+
const trace = (step, detail) => {
|
|
2555
|
+
try { console.info(`[mailbox-client] ${step}`, detail === undefined ? "" : detail); } catch { /* console 不可用(极少数宿主) */ }
|
|
2556
|
+
};
|
|
2557
|
+
|
|
2558
|
+
try { if (ctx.locale && typeof ctx.locale.register === "function") ctx.locale.register(NS, DICT); } catch { /* 可选 */ }
|
|
2559
|
+
trace("apply: 已进入", "");
|
|
2560
|
+
|
|
2561
|
+
const slots = ctx.slots;
|
|
2562
|
+
if (!slots || typeof slots.register !== "function") {
|
|
2563
|
+
// 这里曾经是静默 return —— 正是「插件加载了但什么都不显示」最难查的一种形态。
|
|
2564
|
+
trace("apply: ctx.slots 不可用,放弃注册", { slots: typeof slots, register: typeof slots?.register });
|
|
2565
|
+
return;
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
// M6.6:邮件提示栏。**优先挂 `conversation.input.dock`**(输入框卡片上方的全宽带):
|
|
2569
|
+
// 展开时不覆盖历史对话,只把聊天区压矮(聊天区自己滚动)。
|
|
2570
|
+
// 老外壳没有 dock 槽位 → 退回 M6.4 的 `conversation.input.overlay` 浮层
|
|
2571
|
+
// (浮层会盖住历史,这是老版本的行为;新外壳一律走 dock)。
|
|
2572
|
+
// ⚠️ 2026-10-27 修「提示栏整个不见了」(真机实测:设置里的配置卡在、提示栏没了):
|
|
2573
|
+
// 此前拿 `slots.spec(DOCK_SLOT) !== undefined` 当"外壳有没有这个槽位"的守卫,结果是
|
|
2574
|
+
// **两条分支都不成立、什么都不注册**。根因:renderer 里 `slots.spec(key)` 只查
|
|
2575
|
+
// **register 声明过**的 spec(`SlotRegistry.spec` → `_core.spec`),而
|
|
2576
|
+
// `conversation.input.dock` 是由 **factory**(`conversation.content`)动态声明的 ——
|
|
2577
|
+
// 渲染期走的是 `specDynamic`,所以 `spec()` 对它返回 undefined。
|
|
2578
|
+
// 同一时刻 `plugins.row.config`(register 声明)却能通过,于是表现为"卡片在、提示栏没了"。
|
|
2579
|
+
// 补充实测:两个槽位**都是动态声明**的 —— `conversation.input.overlay` 的 declaredBy 是
|
|
2580
|
+
// "an entry in \"conversation.composer.bar\"" ⇒ 真机里 spec() 对**两者都**返回 undefined,
|
|
2581
|
+
// 所以"两者都查不到"必须押 dock,否则又是什么都不注册。
|
|
2582
|
+
// 官方 QueueDock 的写法就是**不加守卫**直接
|
|
2583
|
+
// `slots.inject(dock, () => slots.register({...}))`;注册本身也不要求槽位先被声明。
|
|
2584
|
+
// 现在:只有当 spec 明说"没有 dock 但有 overlay"(= 老外壳)时才走浮层,其余一律押 dock。
|
|
2585
|
+
//
|
|
2586
|
+
// ⚠️ 2026-10-30 修「apply: ✘ 槽位注册整体失败」(真机 console 实证,提示栏又没了):
|
|
2587
|
+
// 之前这里用 `ctx.effect(reg, ...)` 包注册。但 cordis 插件 fiber 的 apply 是在
|
|
2588
|
+
// **构造完成后的下一个 microtask** 才执行(`_reload`:await Promise.resolve() →
|
|
2589
|
+
// `_execute`),这中间宿主随时可能把 fiber 卸载(dispose 把 uid 置 null / state=5)。
|
|
2590
|
+
// apply 真跑起来时 `ctx.effect` 第一行 `assertActive()` 就同步抛
|
|
2591
|
+
// `INACTIVE_EFFECT: cannot create effect on inactive context`,被下面 catch 吃掉 →
|
|
2592
|
+
// 什么都不注册 → 提示栏消失,console 只剩这一条 ✘。
|
|
2593
|
+
// 修法:**不走 ctx.effect,apply 里直接调 `slots.inject(...)`** ——
|
|
2594
|
+
// renderer 的 inject 内部用的是 **renderer 自己的 ctx**(页面存活期间永活),
|
|
2595
|
+
// 完全不依赖本插件 fiber 的生死;插件卸载的清理改由 **apply 的返回值**承担
|
|
2596
|
+
// (cordis `_execute` 会把 apply 返回的函数收集为 unload disposer)。
|
|
2597
|
+
// 这正是官方 QueueDock 的写法 —— 它也在 apply 里直接 inject。
|
|
2598
|
+
const disposers = [];
|
|
2599
|
+
/** 直接建立 inject 控制器;绝不向上抛,失败返回 undefined。 */
|
|
2600
|
+
const safeInject = (slot, id, order, Comp, label) => {
|
|
2601
|
+
trace(`apply: 调用 slots.inject(${label})`, { slot, id });
|
|
2602
|
+
try {
|
|
2603
|
+
const dispose = slots.inject(slot, () => {
|
|
2604
|
+
trace(`apply: 槽位已声明,执行 register(${label})`, { slot, id, order });
|
|
2605
|
+
return slots.register({ name: slot, id, order, locale: NS }, Comp);
|
|
2606
|
+
});
|
|
2607
|
+
trace(`apply: ✔ inject 控制器已建立(${label})`, { slot, id, order, dispose: typeof dispose });
|
|
2608
|
+
return dispose;
|
|
2609
|
+
} catch (e) {
|
|
2610
|
+
trace(`apply: ✘ inject/register 抛异常(${label})`, { slot, error: String(e && e.message || e) });
|
|
2611
|
+
return undefined;
|
|
2612
|
+
}
|
|
2613
|
+
};
|
|
2614
|
+
// ⚠️ 2026-10-30 二修(用户重启后回贴的完整 TypeError 实锤):
|
|
2615
|
+
// `TypeError: Cannot read properties of undefined (reading '_core') at spec (...)`
|
|
2616
|
+
// 旧代码 `const spec = slots.spec; spec(DOCK_SLOT)` 把方法**从对象上摘下来裸调用** ——
|
|
2617
|
+
// 但 cordis 给服务方法套了一层"自引用代理"(`Nb`:`new Proxy(t,{apply:(n,s,l)=>
|
|
2618
|
+
// (s===r&&(s=i),Reflect.apply(n,s,l))})`):方法调用时它会把接收者换成真实服务对象;
|
|
2619
|
+
// **裸调用时接收者是 undefined,替换逻辑跳过**,`spec` 里 `this._core` 直接炸。
|
|
2620
|
+
// (V8 把代理 apply 陷阱标成 `Object.apply`,正好是堆栈里 dist:2:8554 那一帧。)
|
|
2621
|
+
// 修法:① 永远以 `slots.spec(...)` 方法形式调用,不摘下来;② 即便如此仍包 try/catch ——
|
|
2622
|
+
// 探测只是优化,押 dock 兜底永远成立,绝不能让探测失败再次挡住注册。
|
|
2623
|
+
const hasSpec = typeof slots.spec === "function";
|
|
2624
|
+
let dockKnown = false;
|
|
2625
|
+
let overlayKnown = false;
|
|
2626
|
+
try {
|
|
2627
|
+
dockKnown = hasSpec ? slots.spec(DOCK_SLOT) !== undefined : false;
|
|
2628
|
+
overlayKnown = hasSpec ? slots.spec(BAR_SLOT) !== undefined : false;
|
|
2629
|
+
} catch (e) {
|
|
2630
|
+
trace("apply: spec() 探测抛异常(忽略,押 dock)", { error: String(e && e.message || e) });
|
|
2631
|
+
}
|
|
2632
|
+
try {
|
|
2633
|
+
// 判据(不能只看 spec,原因见上):spec 说"有 dock" ⇒ 一定是新外壳;
|
|
2634
|
+
// spec 说"没有 dock,但有 overlay" ⇒ 一定是老外壳,走浮层;
|
|
2635
|
+
// 两者都查不到 ⇒ **说不准**(新外壳的 factory 槽位就是查不到),押 dock —— inject 在
|
|
2636
|
+
// 槽位真不存在时不会回调,所以押错只是"什么都不显示",不会画错地方。
|
|
2637
|
+
const useDock = dockKnown || !overlayKnown;
|
|
2638
|
+
trace("apply: 槽位判据", {
|
|
2639
|
+
hasSpec, dockKnown, overlayKnown, useDock,
|
|
2640
|
+
picked: useDock ? DOCK_SLOT : BAR_SLOT, order: useDock ? DOCK_ORDER : 60,
|
|
2641
|
+
});
|
|
2642
|
+
if (useDock) disposers.push(safeInject(DOCK_SLOT, DOCK_ID, DOCK_ORDER, MailboxDockBar, "dock"));
|
|
2643
|
+
else disposers.push(safeInject(BAR_SLOT, BAR_ID, 60, MailboxFloatingBar, "overlay"));
|
|
2644
|
+
} catch (e) {
|
|
2645
|
+
// 槽位注册失败绝不影响其余功能,但**必须留下痕迹** —— 静默 catch 会让
|
|
2646
|
+
// "提示栏没显示"变成一条没有任何线索的谜题。
|
|
2647
|
+
trace("apply: ✘ 槽位注册整体失败", { error: String(e && e.stack || e) });
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
// remote.settings:权威 revision 与真实失败原因都从这里来(缺了也不影响渲染,只是退回 form)
|
|
2651
|
+
// ⚠️ ctx.inject 内部走 `registry.plugin(...)` → `assertActive()`:ctx 失活时同样会
|
|
2652
|
+
// **同步抛 INACTIVE_EFFECT** 并直接把异常甩出 apply(被 cordis _reload 记成插件错误)。
|
|
2653
|
+
// 这两段是可选增强,失败只 trace,绝不让它们把 apply 炸掉。
|
|
2654
|
+
if (typeof ctx.inject === "function") {
|
|
2655
|
+
try {
|
|
2656
|
+
ctx.inject(["remote", "remote.settings"], (rc) => {
|
|
2657
|
+
remoteSettings = rc.remote?.settings ?? null;
|
|
2658
|
+
});
|
|
2659
|
+
} catch (e) {
|
|
2660
|
+
trace("apply: ✘ ctx.inject(remote.settings) 抛异常", { error: String(e && e.message || e) });
|
|
2661
|
+
}
|
|
2662
|
+
try {
|
|
2663
|
+
ctx.inject(["configForms"], (formCtx) => {
|
|
2664
|
+
try {
|
|
2665
|
+
const register = () => formCtx.configForms.whileServed([SETTINGS_NAMESPACE], () => {
|
|
2666
|
+
const dispose = slots.inject("plugins.row.config", () => slots.register({
|
|
2667
|
+
name: "plugins.row.config",
|
|
2668
|
+
key: ROW_KEY,
|
|
2669
|
+
locale: NS,
|
|
2670
|
+
}, MailboxSettingsCard));
|
|
2671
|
+
const legacy = slots.spec && slots.spec("plugins.row.config") === undefined
|
|
2672
|
+
? slots.inject("plugins.item", () => slots.register({ name: "plugins.item", id: SETTINGS_NAMESPACE, order: 30, locale: NS }, MailboxSettingsCard))
|
|
2673
|
+
: () => {};
|
|
2674
|
+
return () => { dispose(); legacy(); };
|
|
2675
|
+
});
|
|
2676
|
+
if (typeof formCtx.effect === "function") formCtx.effect(register, "mailbox: settings card");
|
|
2677
|
+
else register();
|
|
2678
|
+
} catch (e) {
|
|
2679
|
+
trace("apply: ✘ 设置卡注册抛异常", { error: String(e && e.message || e) });
|
|
2680
|
+
}
|
|
2681
|
+
});
|
|
2682
|
+
} catch (e) {
|
|
2683
|
+
trace("apply: ✘ ctx.inject(configForms) 抛异常", { error: String(e && e.message || e) });
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
// 插件卸载时统一撤销上面所有 inject 控制器 —— cordis `_execute` 会把 apply 返回的
|
|
2688
|
+
// 函数收集为 unload disposer(`_unload` 时逐个调用),与 ctx.effect 时代的清理语义等价。
|
|
2689
|
+
return () => {
|
|
2690
|
+
for (const d of disposers) { try { d?.(); } catch { /* 单个清理失败不拖累其余 */ } }
|
|
2691
|
+
};
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
return {
|
|
2695
|
+
inject, apply, NS, ID, ROW_KEY, VOLATILE_KEY,
|
|
2696
|
+
__test: {
|
|
2697
|
+
GROUPS, FIELDS, buildOps, coerce, getIn, resolveRuntimeSection, isWritable, saveWithRetry, saveViaRemote, describeRefusal, readNamespaceView,
|
|
2698
|
+
looksLikeTelegramToken, candidateOptions,
|
|
2699
|
+
// 2026-10-30 设置卡移植:参考实现的纯函数(标签/时间/关键词/账号草稿种子)
|
|
2700
|
+
friendlyLabel, hhmm, splitKeywords, seedAccountDraft,
|
|
2701
|
+
// M6.4 浮动栏的纯逻辑 + 常量(渲染之外的全部判断都在这几个函数里)
|
|
2702
|
+
barSummary, formatAgo, bridgeCall, MailboxFloatingBar, makeBarPoller, accountsRows, mailRefText,
|
|
2703
|
+
// 需求 5(2026-10-30):收起态单行流的块构造 + 展开面板网格数据
|
|
2704
|
+
collapsedBlocks, accountGridCells, panelStatusLine, dockPanelStatusLine,
|
|
2705
|
+
// 2026-10-30 需求:监控文件夹大小写不敏感去重(与 lib/config.js dedupeFolders 同口径)
|
|
2706
|
+
dedupeFoldersCase,
|
|
2707
|
+
BAR_SLOT, BAR_ID, BAR_PREFIX, BAR_POLL_MS,
|
|
2708
|
+
// M6.6 对话框上方邮件提示栏:纯逻辑 + 常量(账号页签/汇总口径/插入坐标)
|
|
2709
|
+
MailboxDockBar, accountTabs, summaryFor, summaryParts, mailInsertText, insertMailRef, clipboardCopy, checkHint, icon,
|
|
2710
|
+
DOCK_SLOT, DOCK_ID, DOCK_ORDER, DOCK_RECENT_LIMIT, ALL_ACCOUNTS,
|
|
2711
|
+
// 2026-10-30 未看通知留痕块(徽标上的新邮件在面板里逐条列出,online 模式尤其需要)
|
|
2712
|
+
noticesBlock,
|
|
2713
|
+
},
|
|
2714
|
+
};
|
|
2715
|
+
},
|
|
2716
|
+
});
|
|
2717
|
+
})();
|