@kangyishuai/dsh-session-delete 0.4.8 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -15
- package/README.zh-CN.md +16 -10
- package/lib/client.js +1575 -789
- package/lib/operations.js +231 -7
- package/lib/plan.js +24 -0
- package/lib/preferences.js +90 -0
- package/lib/service.js +60 -0
- package/locale/en.json +70 -44
- package/locale/zh.json +71 -45
- package/package.json +4 -2
package/lib/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
// client 半:classic script,以 __ModuleLoader__.load 注册 factory,不能使用 import。
|
|
3
|
-
//
|
|
3
|
+
// 注册面:会话「…」菜单项 + 侧栏页脚回收站入口 + shell.overlay(确认框 / 回收站面板 / toast)
|
|
4
|
+
// + 设置页「会话回收站」分节。
|
|
4
5
|
// 宿主调用走 ctx.connection.rpc.call("/api", ...) —— 无构建插件没有 typert 生成的客户端产物,
|
|
5
6
|
// 因此不能用 ctx.reflect.get("remote.xxx")(见 docs/runtime/0.2.1-rc.5.md §6.10)。
|
|
6
7
|
window.__ModuleLoader__.load({
|
|
@@ -24,6 +25,8 @@ window.__ModuleLoader__.load({
|
|
|
24
25
|
var MenuItemButton = primitives.MenuItemButton;
|
|
25
26
|
var Modal = primitives.Modal;
|
|
26
27
|
var IconTrash = primitives.IconTrashOutlineRegular;
|
|
28
|
+
var PrimitiveCheckbox = primitives.Checkbox;
|
|
29
|
+
var PrimitiveSwitch = primitives.Switch;
|
|
27
30
|
|
|
28
31
|
/** 设计变量(宿主主题 token):深色/浅色自动跟随。 */
|
|
29
32
|
var T = {
|
|
@@ -34,74 +37,108 @@ window.__ModuleLoader__.load({
|
|
|
34
37
|
faint: "var(--dsw-alias-label-tertiary, GrayText)",
|
|
35
38
|
border: "var(--dsw-alias-border-l2, rgba(128,128,128,0.35))",
|
|
36
39
|
hover: "var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,0.12))",
|
|
40
|
+
hoverDanger: "var(--dsw-alias-interactive-bg-hover-danger, rgba(217,83,79,0.16))",
|
|
37
41
|
danger: "var(--dsw-alias-state-error-primary, #d9534f)",
|
|
42
|
+
// 与 danger 成对:反色实心填充必须配宿主的前景色 token,不能写死白。
|
|
43
|
+
// 深色主题下宿主 error 是浅红 #f25a5a,白字只有 3.29:1;配 label-primary-foreground 是 5.75:1。
|
|
44
|
+
dangerText: "var(--dsw-alias-label-primary-foreground, #fff)",
|
|
38
45
|
mask: "var(--dsw-alias-bg-mask-1, rgba(0,0,0,0.45))",
|
|
39
46
|
toastBg: "var(--dsw-alias-toast-bg, Canvas)",
|
|
40
47
|
toastText: "var(--dsw-alias-toast-label, CanvasText)",
|
|
48
|
+
brand: "var(--dsw-alias-brand-primary, #4f7cff)",
|
|
41
49
|
radius: "10px",
|
|
42
50
|
};
|
|
43
51
|
|
|
44
52
|
/** locale 命名空间;必须与 locale/*.json 顶层键一致。 */
|
|
45
53
|
var NS = "sessionDelete";
|
|
46
54
|
|
|
47
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* 简体中文词典(键集的事实来源)。
|
|
57
|
+
* 精简原则:确认框正文只讲「删什么、多大、能不能恢复」,
|
|
58
|
+
* 技术细节(引用清单、回收站路径、子会话标题)一律进「详情」。
|
|
59
|
+
*/
|
|
48
60
|
var zh = {
|
|
49
61
|
"menu.delete": "删除会话…",
|
|
50
62
|
"menu.trash": "回收站…",
|
|
51
63
|
"footer.trash": "回收站",
|
|
52
|
-
"confirm.title": "
|
|
64
|
+
"confirm.title": "删除会话?",
|
|
65
|
+
"confirm.desc": "移入本机回收站,可以恢复。",
|
|
53
66
|
"confirm.loading": "正在读取影响面…",
|
|
54
|
-
"confirm.
|
|
55
|
-
"confirm.
|
|
56
|
-
"confirm.
|
|
57
|
-
"confirm.
|
|
58
|
-
"confirm.
|
|
59
|
-
"confirm.
|
|
60
|
-
"confirm.
|
|
67
|
+
"confirm.size": "约 {size}",
|
|
68
|
+
"confirm.live": "正在运行,会先停止",
|
|
69
|
+
"confirm.children": "{n} 个子会话",
|
|
70
|
+
"confirm.cascade": "同时删除这 {n} 个子会话(各自进回收站,需分别恢复)",
|
|
71
|
+
"confirm.refs": "将清理 {n} 处引用",
|
|
72
|
+
"confirm.details": "详情",
|
|
73
|
+
"confirm.detail.refs": "引用:{list}",
|
|
74
|
+
"confirm.detail.children": "子会话:{list}",
|
|
75
|
+
"confirm.detail.trashPath": "回收站:{path}",
|
|
76
|
+
"confirm.detail.recoverable": "可恢复:删除后从回收站还原到原位置",
|
|
61
77
|
"confirm.blocked": "暂时无法删除:{reason}",
|
|
62
78
|
"confirm.cancel": "取消",
|
|
63
79
|
"confirm.confirm": "移入回收站",
|
|
64
80
|
"confirm.pending": "正在移入回收站…",
|
|
65
81
|
"confirm.done": "已移入回收站",
|
|
66
82
|
"confirm.undo": "撤销",
|
|
67
|
-
"confirm.failed": "删除失败",
|
|
68
83
|
"panel.title": "会话回收站",
|
|
69
|
-
"panel.tabTrash": "回收站",
|
|
70
|
-
"panel.tabAudit": "审计",
|
|
71
|
-
"panel.tabHealth": "体检",
|
|
72
|
-
"panel.tabReceipts": "回执",
|
|
73
|
-
"trash.selectAll": "全选",
|
|
74
|
-
"trash.clear": "清空",
|
|
75
|
-
"trash.restoreMany": "批量恢复({n})",
|
|
76
|
-
"trash.purgeMany": "批量彻底删除({n})",
|
|
77
|
-
"trash.purgeManyConfirm": "确认彻底删除 {n} 个?不可恢复",
|
|
78
|
-
"batch.done": "完成:{ok}/{total} 成功",
|
|
79
|
-
"receipts.empty": "还没有操作回执。",
|
|
80
|
-
"receipts.restored": "已移回原位置",
|
|
81
|
-
"health.loading": "正在检查…",
|
|
82
|
-
"health.inventory":
|
|
83
|
-
"已存 {stored} · live {live} · 归档 {archived} · 回收站 {trash} · 待处理 {pending}",
|
|
84
|
-
"health.ok": "未发现失效引用。",
|
|
85
|
-
"health.items": "{n} 条",
|
|
86
|
-
"health.agentTool": "模型工具 session_delete:{state}",
|
|
87
|
-
"health.agentToolOn": "已注册",
|
|
88
|
-
"health.agentToolOff": "未注册(宿主未提供 tools 运行时)",
|
|
89
|
-
"health.unavailable": "无法体检:{reason}",
|
|
90
|
-
"health.clean": "清理失效引用({n})",
|
|
91
|
-
"health.cleanConfirm": "确认清理 {n} 条?只动登记表,不碰会话文件",
|
|
92
|
-
"health.cleanDone": "已清理 {n} 条",
|
|
93
84
|
"panel.empty": "回收站是空的。",
|
|
94
|
-
"panel.auditEmpty": "还没有审计记录。",
|
|
95
85
|
"panel.restore": "恢复",
|
|
96
86
|
"panel.purge": "彻底删除",
|
|
97
|
-
"panel.purgeConfirm": "
|
|
98
|
-
"panel.
|
|
99
|
-
"panel.
|
|
87
|
+
"panel.purgeConfirm": "不可恢复,确认",
|
|
88
|
+
"panel.cancelConfirm": "取消",
|
|
89
|
+
"panel.size": "{size}",
|
|
90
|
+
"panel.trashedAt": "{time}",
|
|
100
91
|
"panel.unknown": "{n} 个无法识别的目录已保留",
|
|
101
92
|
"panel.pending": "{n} 个未完成的操作",
|
|
102
93
|
"panel.readOnly": "只读模式:当前 DSH 版本缺少依赖接口,删除功能已禁用。",
|
|
103
94
|
"panel.close": "关闭",
|
|
95
|
+
"trash.selectAll": "全选",
|
|
96
|
+
"trash.selectCount": "已选 {n}/{total}",
|
|
97
|
+
"trash.restoreMany": "恢复({n})",
|
|
98
|
+
"trash.purgeMany": "彻底删除({n})",
|
|
99
|
+
"trash.purgeManyConfirm": "彻底删除 {n} 个?不可恢复",
|
|
100
|
+
"batch.progress": "处理中 {done}/{total}",
|
|
101
|
+
"batch.stop": "停止",
|
|
102
|
+
"batch.done": "完成:{ok}/{total} 成功",
|
|
103
|
+
"batch.failed": "{n} 个失败,已保留选中",
|
|
104
104
|
"toast.failed": "操作失败:{message}",
|
|
105
|
+
"settings.nav": "会话回收站",
|
|
106
|
+
"settings.group.delete": "删除偏好",
|
|
107
|
+
"settings.cascade.title": "记住「同时删除子会话」",
|
|
108
|
+
"settings.cascade.desc": "下次打开删除确认框时沿用上次的勾选状态。",
|
|
109
|
+
"settings.cascade.reset": "重置为默认(不勾选)",
|
|
110
|
+
"settings.cascade.resetDone": "已重置",
|
|
111
|
+
"settings.group.trash": "回收站",
|
|
112
|
+
"settings.trash.summary": "{n} 个会话 · 占用 {size}",
|
|
113
|
+
"settings.trash.open": "打开回收站",
|
|
114
|
+
"settings.group.maintenance": "维护",
|
|
115
|
+
"settings.health.title": "体检",
|
|
116
|
+
"settings.health.desc": "检查指向已不存在会话的登记条目(只读)。",
|
|
117
|
+
"settings.health.ok": "未发现失效引用。",
|
|
118
|
+
"settings.health.items": "{n} 条待清理",
|
|
119
|
+
"settings.health.unavailable": "无法体检:{reason}",
|
|
120
|
+
"settings.health.clean": "清理 {n} 条",
|
|
121
|
+
"settings.health.cleanConfirm": "确认清理 {n} 条?只动登记表,不碰会话文件",
|
|
122
|
+
"settings.health.cleaned": "已清理 {n} 条",
|
|
123
|
+
"settings.receipts.title": "操作回执",
|
|
124
|
+
"settings.receipts.empty": "还没有操作回执。",
|
|
125
|
+
"settings.audit.title": "审计日志",
|
|
126
|
+
"settings.audit.empty": "还没有审计记录。",
|
|
127
|
+
"settings.audit.path": "日志文件:{path}",
|
|
128
|
+
"settings.loading": "读取中…",
|
|
129
|
+
"confirm.workspace.title": "删除「{name}」里的全部会话?",
|
|
130
|
+
"confirm.workspace.summary": "{n} 个会话 · 约 {size}",
|
|
131
|
+
"confirm.workspace.live": "{n} 个正在运行,会先停止",
|
|
132
|
+
"confirm.workspace.blocked": "{n} 个暂时无法删除,会逐条报出来",
|
|
133
|
+
"confirm.workspace.missing": "{n} 个登记条目已失效,已忽略",
|
|
134
|
+
"confirm.workspace.confirm": "移入回收站({n})",
|
|
135
|
+
"confirm.detail.workspaceSessions": "会话:{list}",
|
|
136
|
+
"menu.workspaceTrash": "删除此工作区的全部会话…",
|
|
137
|
+
"toast.workspace.done": "已移入回收站 {ok}/{total} 个会话",
|
|
138
|
+
"shortcut.delete": "删除当前会话…",
|
|
139
|
+
"shortcut.workspace": "删除当前工作区的全部会话…",
|
|
140
|
+
"shortcut.noSession": "没有可以删除的当前会话",
|
|
141
|
+
"shortcut.busy": "删除确认框已经打开",
|
|
105
142
|
};
|
|
106
143
|
|
|
107
144
|
/** English dictionary(键集与 zh 完全一致)。 */
|
|
@@ -109,60 +146,87 @@ window.__ModuleLoader__.load({
|
|
|
109
146
|
"menu.delete": "Delete session…",
|
|
110
147
|
"menu.trash": "Trash…",
|
|
111
148
|
"footer.trash": "Trash",
|
|
112
|
-
"confirm.title": "Delete
|
|
149
|
+
"confirm.title": "Delete session?",
|
|
150
|
+
"confirm.desc": "Moves to the local trash and can be restored.",
|
|
113
151
|
"confirm.loading": "Reading what will be removed…",
|
|
114
|
-
"confirm.
|
|
115
|
-
"confirm.
|
|
116
|
-
"confirm.
|
|
117
|
-
"confirm.children": "{n} subagent session(s) come along",
|
|
152
|
+
"confirm.size": "about {size}",
|
|
153
|
+
"confirm.live": "running; its work stops first",
|
|
154
|
+
"confirm.children": "{n} subagent session(s)",
|
|
118
155
|
"confirm.cascade": "Also delete these {n} child session(s) (each goes to trash separately)",
|
|
119
|
-
"confirm.refs": "
|
|
120
|
-
"confirm.
|
|
156
|
+
"confirm.refs": "Cleans {n} reference(s)",
|
|
157
|
+
"confirm.details": "Details",
|
|
158
|
+
"confirm.detail.refs": "References: {list}",
|
|
159
|
+
"confirm.detail.children": "Child sessions: {list}",
|
|
160
|
+
"confirm.detail.trashPath": "Trash: {path}",
|
|
161
|
+
"confirm.detail.recoverable":
|
|
162
|
+
"Recoverable: restore from the trash back to its original place",
|
|
121
163
|
"confirm.blocked": "Cannot delete right now: {reason}",
|
|
122
164
|
"confirm.cancel": "Cancel",
|
|
123
165
|
"confirm.confirm": "Move to trash",
|
|
124
166
|
"confirm.pending": "Moving to trash…",
|
|
125
167
|
"confirm.done": "Moved to trash",
|
|
126
168
|
"confirm.undo": "Undo",
|
|
127
|
-
"confirm.failed": "Deletion failed",
|
|
128
169
|
"panel.title": "Session trash",
|
|
129
|
-
"panel.tabTrash": "Trash",
|
|
130
|
-
"panel.tabAudit": "Audit",
|
|
131
|
-
"panel.tabHealth": "Health",
|
|
132
|
-
"panel.tabReceipts": "Receipts",
|
|
133
|
-
"trash.selectAll": "Select all",
|
|
134
|
-
"trash.clear": "Clear",
|
|
135
|
-
"trash.restoreMany": "Restore {n}",
|
|
136
|
-
"trash.purgeMany": "Delete {n} permanently",
|
|
137
|
-
"trash.purgeManyConfirm": "Permanently delete {n}? This cannot be undone",
|
|
138
|
-
"batch.done": "Done: {ok}/{total} succeeded",
|
|
139
|
-
"receipts.empty": "No operation receipts yet.",
|
|
140
|
-
"receipts.restored": "restored",
|
|
141
|
-
"health.loading": "Checking…",
|
|
142
|
-
"health.inventory":
|
|
143
|
-
"stored {stored} · live {live} · archived {archived} · trash {trash} · pending {pending}",
|
|
144
|
-
"health.ok": "No dangling references found.",
|
|
145
|
-
"health.items": "{n} item(s)",
|
|
146
|
-
"health.agentTool": "Agent tool session_delete: {state}",
|
|
147
|
-
"health.agentToolOn": "registered",
|
|
148
|
-
"health.agentToolOff": "not registered (host has no tools runtime)",
|
|
149
|
-
"health.unavailable": "Cannot run the check: {reason}",
|
|
150
|
-
"health.clean": "Clean dangling references ({n})",
|
|
151
|
-
"health.cleanConfirm": "Clean {n} dangling reference(s)? Bookkeeping only, no session files.",
|
|
152
|
-
"health.cleanDone": "Cleaned {n}",
|
|
153
170
|
"panel.empty": "The trash is empty.",
|
|
154
|
-
"panel.auditEmpty": "No audit entries yet.",
|
|
155
171
|
"panel.restore": "Restore",
|
|
156
172
|
"panel.purge": "Delete for good",
|
|
157
|
-
"panel.purgeConfirm": "
|
|
173
|
+
"panel.purgeConfirm": "Cannot be undone — confirm",
|
|
174
|
+
"panel.cancelConfirm": "Cancel",
|
|
158
175
|
"panel.size": "{size}",
|
|
159
|
-
"panel.trashedAt": "
|
|
176
|
+
"panel.trashedAt": "{time}",
|
|
160
177
|
"panel.unknown": "{n} unrecognized director(ies) kept",
|
|
161
178
|
"panel.pending": "{n} unfinished operation(s)",
|
|
162
179
|
"panel.readOnly":
|
|
163
180
|
"Read-only: this DSH version is missing required APIs; deletion is disabled.",
|
|
164
181
|
"panel.close": "Close",
|
|
182
|
+
"trash.selectAll": "Select all",
|
|
183
|
+
"trash.selectCount": "{n}/{total} selected",
|
|
184
|
+
"trash.restoreMany": "Restore ({n})",
|
|
185
|
+
"trash.purgeMany": "Delete {n} permanently",
|
|
186
|
+
"trash.purgeManyConfirm": "Permanently delete {n}? This cannot be undone",
|
|
187
|
+
"batch.progress": "{done}/{total} done",
|
|
188
|
+
"batch.stop": "Stop",
|
|
189
|
+
"batch.done": "Done: {ok}/{total} succeeded",
|
|
190
|
+
"batch.failed": "{n} failed; kept selected",
|
|
165
191
|
"toast.failed": "Operation failed: {message}",
|
|
192
|
+
"settings.nav": "Session trash",
|
|
193
|
+
"settings.group.delete": "Deletion preferences",
|
|
194
|
+
"settings.cascade.title": 'Remember "also delete child sessions"',
|
|
195
|
+
"settings.cascade.desc": "The next delete confirmation starts from your last choice.",
|
|
196
|
+
"settings.cascade.reset": "Reset to default (unchecked)",
|
|
197
|
+
"settings.cascade.resetDone": "Reset",
|
|
198
|
+
"settings.group.trash": "Trash",
|
|
199
|
+
"settings.trash.summary": "{n} session(s) · {size}",
|
|
200
|
+
"settings.trash.open": "Open trash",
|
|
201
|
+
"settings.group.maintenance": "Maintenance",
|
|
202
|
+
"settings.health.title": "Health",
|
|
203
|
+
"settings.health.desc":
|
|
204
|
+
"Checks bookkeeping that points at sessions that no longer exist (read-only).",
|
|
205
|
+
"settings.health.ok": "No dangling references found.",
|
|
206
|
+
"settings.health.items": "{n} to clean",
|
|
207
|
+
"settings.health.unavailable": "Cannot run the check: {reason}",
|
|
208
|
+
"settings.health.clean": "Clean {n}",
|
|
209
|
+
"settings.health.cleanConfirm": "Clean {n} dangling reference(s)? Bookkeeping only.",
|
|
210
|
+
"settings.health.cleaned": "Cleaned {n}",
|
|
211
|
+
"settings.receipts.title": "Receipts",
|
|
212
|
+
"settings.receipts.empty": "No operation receipts yet.",
|
|
213
|
+
"settings.audit.title": "Audit log",
|
|
214
|
+
"settings.audit.empty": "No audit entries yet.",
|
|
215
|
+
"settings.audit.path": "Log file: {path}",
|
|
216
|
+
"settings.loading": "Loading…",
|
|
217
|
+
"confirm.workspace.title": 'Delete every session in "{name}"?',
|
|
218
|
+
"confirm.workspace.summary": "{n} session(s) · about {size}",
|
|
219
|
+
"confirm.workspace.live": "{n} running; their work stops first",
|
|
220
|
+
"confirm.workspace.blocked": "{n} cannot be deleted right now and will be reported",
|
|
221
|
+
"confirm.workspace.missing": "{n} stale bookkeeping entr(ies) ignored",
|
|
222
|
+
"confirm.workspace.confirm": "Move {n} to trash",
|
|
223
|
+
"confirm.detail.workspaceSessions": "Sessions: {list}",
|
|
224
|
+
"menu.workspaceTrash": "Delete all sessions in this workspace…",
|
|
225
|
+
"toast.workspace.done": "Moved {ok}/{total} session(s) to the trash",
|
|
226
|
+
"shortcut.delete": "Delete current session…",
|
|
227
|
+
"shortcut.workspace": "Delete every session in the current workspace…",
|
|
228
|
+
"shortcut.noSession": "No current session to delete",
|
|
229
|
+
"shortcut.busy": "A delete confirmation is already open",
|
|
166
230
|
};
|
|
167
231
|
|
|
168
232
|
/** @param {any} initial @returns {any} */
|
|
@@ -190,21 +254,26 @@ window.__ModuleLoader__.load({
|
|
|
190
254
|
return [React.useSyncExternalStore(store.subscribe, store.getSnapshot), store.set];
|
|
191
255
|
}
|
|
192
256
|
|
|
193
|
-
/**
|
|
257
|
+
/** 主题化按钮:hover / active / focus-visible 由注入的 CSS 类提供,不依赖合成事件。 */
|
|
194
258
|
/** 主题化按钮:hover / active / focus-visible 由注入的 CSS 类提供,不依赖合成事件。 */
|
|
195
259
|
function Btn(/** @type {any} */ props) {
|
|
260
|
+
var variant = props.variant === "danger" ? " dsh-sdel-btn--danger" : "";
|
|
261
|
+
var quiet = props.variant === "quiet" ? " dsh-sdel-btn--quiet" : "";
|
|
196
262
|
return h(
|
|
197
263
|
"button",
|
|
198
264
|
{
|
|
199
265
|
type: "button",
|
|
200
|
-
|
|
266
|
+
ref: props.innerRef,
|
|
201
267
|
disabled: props.disabled,
|
|
268
|
+
title: props.title,
|
|
269
|
+
"aria-label": props.ariaLabel,
|
|
270
|
+
"data-modal-autofocus": props.modalAutofocus ? "" : undefined,
|
|
202
271
|
onClick: props.onClick,
|
|
203
|
-
className: `dsh-sdel-btn${props.
|
|
272
|
+
className: `dsh-sdel-btn${variant}${quiet}${props.tight ? " dsh-sdel-btn--tight" : ""}`,
|
|
204
273
|
style: {
|
|
205
|
-
padding: "6px 14px",
|
|
274
|
+
padding: props.tight ? "2px 8px" : "6px 14px",
|
|
206
275
|
borderRadius: "8px",
|
|
207
|
-
fontSize: "13px",
|
|
276
|
+
fontSize: props.tight ? "12px" : "13px",
|
|
208
277
|
cursor: props.disabled ? "not-allowed" : "pointer",
|
|
209
278
|
opacity: props.disabled ? 0.45 : 1,
|
|
210
279
|
},
|
|
@@ -213,6 +282,118 @@ window.__ModuleLoader__.load({
|
|
|
213
282
|
);
|
|
214
283
|
}
|
|
215
284
|
|
|
285
|
+
/** 复选框:优先宿主原语(尺寸/焦点环与设置页一致),缺失时回退到原生 input。 */
|
|
286
|
+
function Check(/** @type {any} */ props) {
|
|
287
|
+
if (typeof PrimitiveCheckbox === "function") {
|
|
288
|
+
return h(PrimitiveCheckbox, {
|
|
289
|
+
checked: props.checked === true,
|
|
290
|
+
disabled: props.disabled === true,
|
|
291
|
+
label: props.label,
|
|
292
|
+
onChange: props.onChange,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return h(
|
|
296
|
+
"label",
|
|
297
|
+
{ style: { display: "inline-flex", alignItems: "center", gap: "6px", cursor: "pointer" } },
|
|
298
|
+
h("input", {
|
|
299
|
+
type: "checkbox",
|
|
300
|
+
checked: props.checked === true,
|
|
301
|
+
disabled: props.disabled === true,
|
|
302
|
+
onChange: (/** @type {any} */ event) => props.onChange?.(event.target.checked),
|
|
303
|
+
}),
|
|
304
|
+
props.label ? h("span", null, props.label) : null,
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** 开关:优先宿主原语,缺失时回退到复选框。 */
|
|
309
|
+
function Toggle(/** @type {any} */ props) {
|
|
310
|
+
if (typeof PrimitiveSwitch === "function") {
|
|
311
|
+
return h(PrimitiveSwitch, {
|
|
312
|
+
checked: props.checked === true,
|
|
313
|
+
disabled: props.disabled === true,
|
|
314
|
+
label: props.label,
|
|
315
|
+
onChange: props.onChange,
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
return h(Check, props);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** 折叠三角:纯文本字形,避免依赖宿主图标名(缺失时不会变成空白)。 */
|
|
322
|
+
function Caret(/** @type {any} */ props) {
|
|
323
|
+
return h(
|
|
324
|
+
"span",
|
|
325
|
+
{
|
|
326
|
+
"aria-hidden": "true",
|
|
327
|
+
style: {
|
|
328
|
+
display: "inline-block",
|
|
329
|
+
width: "10px",
|
|
330
|
+
color: T.faint,
|
|
331
|
+
transform: props.open ? "rotate(90deg)" : "none",
|
|
332
|
+
transition: "transform 120ms ease",
|
|
333
|
+
fontSize: "10px",
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
"▶",
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** 一行可折叠的「标题 + 说明 + 右侧控件」。 */
|
|
341
|
+
function SettingRow(/** @type {any} */ props) {
|
|
342
|
+
return h(
|
|
343
|
+
"div",
|
|
344
|
+
{ className: "dsh-sdel-setting-row" },
|
|
345
|
+
h(
|
|
346
|
+
"div",
|
|
347
|
+
{ className: "dsh-sdel-setting-text" },
|
|
348
|
+
h("div", { className: "dsh-sdel-setting-title" }, props.title),
|
|
349
|
+
props.description
|
|
350
|
+
? h("div", { className: "dsh-sdel-setting-desc" }, props.description)
|
|
351
|
+
: null,
|
|
352
|
+
props.children,
|
|
353
|
+
),
|
|
354
|
+
props.action ? h("div", { className: "dsh-sdel-setting-action" }, props.action) : null,
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** 折叠区:默认关闭,展开后限高滚动 —— 长列表不会把弹窗/设置页撑长。 */
|
|
359
|
+
function Disclosure(/** @type {any} */ props) {
|
|
360
|
+
var state = React.useState(false);
|
|
361
|
+
var open = state[0];
|
|
362
|
+
var setOpen = state[1];
|
|
363
|
+
return h(
|
|
364
|
+
React.Fragment,
|
|
365
|
+
null,
|
|
366
|
+
h(
|
|
367
|
+
"button",
|
|
368
|
+
{
|
|
369
|
+
type: "button",
|
|
370
|
+
className: "dsh-sdel-disclosure",
|
|
371
|
+
"aria-expanded": open ? "true" : "false",
|
|
372
|
+
onClick: () => setOpen(!open),
|
|
373
|
+
},
|
|
374
|
+
h(Caret, { open: open }),
|
|
375
|
+
h("span", null, props.label),
|
|
376
|
+
props.meta ? h("span", { className: "dsh-sdel-disclosure-meta" }, props.meta) : null,
|
|
377
|
+
),
|
|
378
|
+
open
|
|
379
|
+
? h(
|
|
380
|
+
"div",
|
|
381
|
+
{
|
|
382
|
+
style: {
|
|
383
|
+
maxHeight: props.maxHeight || "220px",
|
|
384
|
+
overflowY: "auto",
|
|
385
|
+
padding: "2px 0 8px 16px",
|
|
386
|
+
color: T.dim,
|
|
387
|
+
fontSize: "12px",
|
|
388
|
+
lineHeight: 1.7,
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
props.children,
|
|
392
|
+
)
|
|
393
|
+
: null,
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
216
397
|
/** 挂载时淡入的容器:官方 Modal 没有明确的入场过渡时,用它补齐。 */
|
|
217
398
|
function Reveal(/** @type {any} */ props) {
|
|
218
399
|
const state = React.useState(false);
|
|
@@ -255,11 +436,7 @@ window.__ModuleLoader__.load({
|
|
|
255
436
|
description: props.description,
|
|
256
437
|
footer: props.footer,
|
|
257
438
|
},
|
|
258
|
-
h(
|
|
259
|
-
Reveal,
|
|
260
|
-
{ style: { maxHeight: "60vh", overflowY: "auto", paddingRight: "4px" } },
|
|
261
|
-
props.children,
|
|
262
|
-
),
|
|
439
|
+
h(Reveal, null, props.children),
|
|
263
440
|
);
|
|
264
441
|
}
|
|
265
442
|
return h(
|
|
@@ -280,7 +457,7 @@ window.__ModuleLoader__.load({
|
|
|
280
457
|
},
|
|
281
458
|
h(
|
|
282
459
|
Reveal,
|
|
283
|
-
{ style: { width: "min(
|
|
460
|
+
{ style: { width: "min(480px, 92vw)" } },
|
|
284
461
|
h(
|
|
285
462
|
"div",
|
|
286
463
|
{
|
|
@@ -331,6 +508,58 @@ window.__ModuleLoader__.load({
|
|
|
331
508
|
);
|
|
332
509
|
}
|
|
333
510
|
|
|
511
|
+
/**
|
|
512
|
+
* 中文/英文共用的列表连接符:把数组拼成一行,超过 max 条时补省略号。
|
|
513
|
+
* @param {any[]} items
|
|
514
|
+
* @param {number} [max]
|
|
515
|
+
* @returns {string}
|
|
516
|
+
*/
|
|
517
|
+
function joinList(items, max = 6) {
|
|
518
|
+
var list = (Array.isArray(items) ? items : []).map((/** @type {any} */ item) =>
|
|
519
|
+
String(
|
|
520
|
+
item && typeof item === "object" ? (item.label ?? item.title ?? item.id ?? "") : item,
|
|
521
|
+
),
|
|
522
|
+
);
|
|
523
|
+
var shown = list.slice(0, max);
|
|
524
|
+
return shown.join(" · ") + (list.length > max ? " …" : "");
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* 把数组切成固定大小的批次:回收站 80 条时一次 RPC 会被宿主上限拒绝,
|
|
529
|
+
* 界面必须分批并把进度显示出来(0.4.x 的 bug:整单被拒,看起来像没反应)。
|
|
530
|
+
* @param {any[]} items
|
|
531
|
+
* @param {number} size
|
|
532
|
+
* @returns {any[][]}
|
|
533
|
+
*/
|
|
534
|
+
function chunk(items, size) {
|
|
535
|
+
var step = Math.max(1, Math.floor(size) || 1);
|
|
536
|
+
/** @type {any[][]} */
|
|
537
|
+
var out = [];
|
|
538
|
+
for (let index = 0; index < (items || []).length; index += step) {
|
|
539
|
+
out.push(items.slice(index, index + step));
|
|
540
|
+
}
|
|
541
|
+
return out;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* 确认框正文的一行影响面:只拼成立的事实,用 `·` 分隔。
|
|
546
|
+
* 空值不进数组 —— 这是「不显示占位行」这条规则的单点实现。
|
|
547
|
+
* @param {{ sizeBytes?: number, live?: boolean, children?: any[] }} plan
|
|
548
|
+
* @param {(key: string, values?: any) => string} t
|
|
549
|
+
* @returns {string}
|
|
550
|
+
*/
|
|
551
|
+
function impactLine(plan, t) {
|
|
552
|
+
/** @type {string[]} */
|
|
553
|
+
var facts = [];
|
|
554
|
+
if (plan && typeof plan.sizeBytes === "number") {
|
|
555
|
+
facts.push(t("confirm.size", { size: formatBytes(plan.sizeBytes) }));
|
|
556
|
+
}
|
|
557
|
+
var children = Array.isArray(plan?.children) ? plan.children.length : 0;
|
|
558
|
+
if (children > 0) facts.push(t("confirm.children", { n: children }));
|
|
559
|
+
if (plan?.live) facts.push(t("confirm.live"));
|
|
560
|
+
return facts.join(" · ");
|
|
561
|
+
}
|
|
562
|
+
|
|
334
563
|
function formatBytes(/** @type {any} */ bytes) {
|
|
335
564
|
if (typeof bytes !== "number" || bytes < 0) return "?";
|
|
336
565
|
if (bytes < 1024) return `${Math.round(bytes)} B`;
|
|
@@ -389,19 +618,8 @@ window.__ModuleLoader__.load({
|
|
|
389
618
|
{
|
|
390
619
|
type: "button",
|
|
391
620
|
onClick: onSelect,
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
width: "100%",
|
|
395
|
-
textAlign: "left",
|
|
396
|
-
padding: "6px 12px",
|
|
397
|
-
border: "none",
|
|
398
|
-
borderRadius: "6px",
|
|
399
|
-
background: "transparent",
|
|
400
|
-
color: T.danger,
|
|
401
|
-
cursor: "pointer",
|
|
402
|
-
fontSize: "13px",
|
|
403
|
-
transition: "background-color .15s ease",
|
|
404
|
-
},
|
|
621
|
+
className: "dsh-sdel-btn dsh-sdel-btn--danger",
|
|
622
|
+
style: { display: "block", width: "100%", textAlign: "left", padding: "6px 12px" },
|
|
405
623
|
},
|
|
406
624
|
props.t("menu.delete"),
|
|
407
625
|
);
|
|
@@ -420,7 +638,10 @@ window.__ModuleLoader__.load({
|
|
|
420
638
|
.then((/** @type {any} */ value) => {
|
|
421
639
|
setCount(value?.entries ? value.entries.length : 0);
|
|
422
640
|
})
|
|
423
|
-
.catch(() =>
|
|
641
|
+
.catch(() => {
|
|
642
|
+
// 计数拿不到就退回不带数字的入口,但别让 rejection 无声无息。
|
|
643
|
+
setCount(null);
|
|
644
|
+
});
|
|
424
645
|
};
|
|
425
646
|
React.useEffect(() => {
|
|
426
647
|
fetchCount();
|
|
@@ -467,7 +688,7 @@ window.__ModuleLoader__.load({
|
|
|
467
688
|
padding: "0 4px",
|
|
468
689
|
borderRadius: "8px",
|
|
469
690
|
background: T.danger,
|
|
470
|
-
color:
|
|
691
|
+
color: T.dangerText,
|
|
471
692
|
fontSize: "10px",
|
|
472
693
|
lineHeight: "16px",
|
|
473
694
|
textAlign: "center",
|
|
@@ -479,6 +700,11 @@ window.__ModuleLoader__.load({
|
|
|
479
700
|
);
|
|
480
701
|
}
|
|
481
702
|
|
|
703
|
+
/**
|
|
704
|
+
* 删除确认框:会话与「整个工作区」共用一套。
|
|
705
|
+
* 正文三行(标题 / 影响面 / 需要留意的一行)+ 一行级联勾选 + 折叠详情;
|
|
706
|
+
* 默认焦点在「移入回收站」上(回车即生效),Esc 取消,不可删除时焦点回落到「取消」。
|
|
707
|
+
*/
|
|
482
708
|
function DeleteConfirm(/** @type {any} */ props) {
|
|
483
709
|
var requestState = useStore(props.requestStore);
|
|
484
710
|
var request = requestState[0];
|
|
@@ -491,24 +717,41 @@ window.__ModuleLoader__.load({
|
|
|
491
717
|
var busyState = React.useState(false);
|
|
492
718
|
var busy = busyState[0];
|
|
493
719
|
var setBusy = busyState[1];
|
|
494
|
-
var requestId = request ? request.sessionId : null;
|
|
495
720
|
var cascadeState = React.useState(false);
|
|
496
721
|
var cascade = cascadeState[0];
|
|
497
722
|
var setCascade = cascadeState[1];
|
|
723
|
+
var confirmRef = React.useRef(null);
|
|
724
|
+
var cancelRef = React.useRef(null);
|
|
725
|
+
var workspaceId = request?.workspaceId ? String(request.workspaceId) : null;
|
|
726
|
+
var isWorkspace = workspaceId !== null;
|
|
727
|
+
var requestKey = request
|
|
728
|
+
? isWorkspace
|
|
729
|
+
? `workspace:${workspaceId}`
|
|
730
|
+
: `session:${request.sessionId}`
|
|
731
|
+
: null;
|
|
732
|
+
|
|
733
|
+
/** 偏好只决定「初值」:用户这次勾了什么,下次就带过来。 */
|
|
734
|
+
var rememberCascade = (/** @type {any} */ next) => {
|
|
735
|
+
setCascade(next);
|
|
736
|
+
props.prefsStore.set({ cascadeChildren: next });
|
|
737
|
+
props.call("setPrefs", { cascadeChildren: next }).catch(() => {});
|
|
738
|
+
};
|
|
498
739
|
|
|
499
740
|
React.useEffect(() => {
|
|
500
|
-
if (!
|
|
741
|
+
if (!requestKey) {
|
|
501
742
|
setPlan(null);
|
|
502
743
|
setError(null);
|
|
503
744
|
setBusy(false);
|
|
504
|
-
setCascade(false);
|
|
505
745
|
return undefined;
|
|
506
746
|
}
|
|
507
747
|
var alive = true;
|
|
508
748
|
setPlan(null);
|
|
509
749
|
setError(null);
|
|
510
|
-
props
|
|
511
|
-
|
|
750
|
+
setCascade(props.prefsStore.getSnapshot()?.cascadeChildren === true);
|
|
751
|
+
var pending = workspaceId
|
|
752
|
+
? props.call("planWorkspace", { workspaceId: workspaceId })
|
|
753
|
+
: props.call("plan", { sessionId: request.sessionId });
|
|
754
|
+
pending
|
|
512
755
|
.then((/** @type {any} */ value) => {
|
|
513
756
|
if (alive) setPlan(value);
|
|
514
757
|
})
|
|
@@ -518,7 +761,24 @@ window.__ModuleLoader__.load({
|
|
|
518
761
|
return () => {
|
|
519
762
|
alive = false;
|
|
520
763
|
};
|
|
521
|
-
}, [
|
|
764
|
+
}, [requestKey]);
|
|
765
|
+
|
|
766
|
+
// hooks 必须在任何 return 之前:确认框组件常驻挂载,提前 return 会让 hook 数量在
|
|
767
|
+
// 「有请求 / 无请求」两种渲染之间变化,React 会直接抛 rendered more hooks 错误。
|
|
768
|
+
var blocked = isWorkspace ? false : (plan?.blockers?.length ?? 0) > 0;
|
|
769
|
+
var children = isWorkspace || !plan ? [] : Array.isArray(plan.children) ? plan.children : [];
|
|
770
|
+
var removes = isWorkspace || !plan ? [] : Array.isArray(plan.removes) ? plan.removes : [];
|
|
771
|
+
// 工作区预览里的 children 是**汇总数字**,会话计划里是数组,这里统一成数量。
|
|
772
|
+
var childCount = isWorkspace ? Number(plan?.children ?? 0) : children.length;
|
|
773
|
+
var sessionTotal = isWorkspace ? Number(plan?.total ?? 0) : 0;
|
|
774
|
+
var canConfirm = !!plan && !blocked && !busy && (!isWorkspace || sessionTotal > 0);
|
|
775
|
+
|
|
776
|
+
/** 焦点策略:可确认时落在破坏性按钮(回车即删),否则落在「取消」。 */
|
|
777
|
+
React.useEffect(() => {
|
|
778
|
+
if (!request) return;
|
|
779
|
+
var target = canConfirm ? confirmRef.current : cancelRef.current;
|
|
780
|
+
if (target && typeof target.focus === "function") target.focus();
|
|
781
|
+
}, [canConfirm, plan, request]);
|
|
522
782
|
|
|
523
783
|
if (!request) return null;
|
|
524
784
|
|
|
@@ -529,16 +789,23 @@ window.__ModuleLoader__.load({
|
|
|
529
789
|
var confirm = () => {
|
|
530
790
|
if (!plan || busy) return;
|
|
531
791
|
setBusy(true);
|
|
532
|
-
|
|
533
|
-
.call("
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
792
|
+
var pending = isWorkspace
|
|
793
|
+
? props.call("trashWorkspace", {
|
|
794
|
+
workspaceId: workspaceId,
|
|
795
|
+
digest: plan.digest,
|
|
796
|
+
cascade: cascade && childCount > 0,
|
|
797
|
+
})
|
|
798
|
+
: props.call("trash", {
|
|
799
|
+
sessionId: request.sessionId,
|
|
800
|
+
digest: plan.digest,
|
|
801
|
+
title: request.title || null,
|
|
802
|
+
cascade: cascade && children.length > 0,
|
|
803
|
+
});
|
|
804
|
+
pending
|
|
539
805
|
.then((/** @type {any} */ result) => {
|
|
540
806
|
props.requestStore.set(null);
|
|
541
|
-
props.
|
|
807
|
+
if (isWorkspace) props.onTrashedMany?.(result);
|
|
808
|
+
else props.onTrashed?.(result);
|
|
542
809
|
})
|
|
543
810
|
.catch((/** @type {any} */ reason) => {
|
|
544
811
|
setBusy(false);
|
|
@@ -546,72 +813,131 @@ window.__ModuleLoader__.load({
|
|
|
546
813
|
});
|
|
547
814
|
};
|
|
548
815
|
|
|
549
|
-
var
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
list: plan.removes.map((/** @type {any} */ item) => item.label).join(" · "),
|
|
560
|
-
}),
|
|
561
|
-
);
|
|
562
|
-
}
|
|
563
|
-
if (plan.blockers && plan.blockers.length > 0)
|
|
564
|
-
lines.push(props.t("confirm.blocked", { reason: plan.blockers[0].message }));
|
|
565
|
-
}
|
|
566
|
-
var blocked = !!(plan?.blockers && plan.blockers.length > 0);
|
|
816
|
+
var impact = isWorkspace
|
|
817
|
+
? plan
|
|
818
|
+
? props.t("confirm.workspace.summary", {
|
|
819
|
+
n: sessionTotal,
|
|
820
|
+
size: formatBytes(plan.sizeBytes),
|
|
821
|
+
})
|
|
822
|
+
: props.t("confirm.loading")
|
|
823
|
+
: plan
|
|
824
|
+
? impactLine(plan, props.t) || props.t("confirm.size", { size: "?" })
|
|
825
|
+
: props.t("confirm.loading");
|
|
567
826
|
|
|
568
827
|
var body = h(
|
|
569
828
|
React.Fragment,
|
|
570
829
|
null,
|
|
571
|
-
request.title
|
|
572
|
-
? h("div", { style: { fontWeight: 600, marginBottom: "10px" } }, request.title)
|
|
573
|
-
: null,
|
|
574
|
-
plan && plan.children.length > 0
|
|
830
|
+
!isWorkspace && request.title
|
|
575
831
|
? h(
|
|
576
|
-
"
|
|
832
|
+
"div",
|
|
577
833
|
{
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
gap: "8px",
|
|
582
|
-
margin: "8px 0 4px",
|
|
583
|
-
cursor: "pointer",
|
|
584
|
-
},
|
|
834
|
+
className: "dsh-sdel-truncate",
|
|
835
|
+
style: { fontWeight: 600, marginBottom: "4px" },
|
|
836
|
+
title: request.title,
|
|
585
837
|
},
|
|
586
|
-
|
|
587
|
-
|
|
838
|
+
request.title,
|
|
839
|
+
)
|
|
840
|
+
: null,
|
|
841
|
+
h("div", { style: { color: T.dim } }, impact),
|
|
842
|
+
!isWorkspace && removes.length > 0
|
|
843
|
+
? h(
|
|
844
|
+
"div",
|
|
845
|
+
{ style: { color: T.faint, fontSize: "12px", marginTop: "2px" } },
|
|
846
|
+
props.t("confirm.refs", { n: removes.length }),
|
|
847
|
+
)
|
|
848
|
+
: null,
|
|
849
|
+
isWorkspace && plan && plan.live > 0
|
|
850
|
+
? h(
|
|
851
|
+
"div",
|
|
852
|
+
{ style: { color: T.faint, fontSize: "12px", marginTop: "2px" } },
|
|
853
|
+
props.t("confirm.workspace.live", { n: plan.live }),
|
|
854
|
+
)
|
|
855
|
+
: null,
|
|
856
|
+
isWorkspace && plan && plan.blocked > 0
|
|
857
|
+
? h(
|
|
858
|
+
"div",
|
|
859
|
+
{ style: { color: T.danger, fontSize: "12px", marginTop: "2px" } },
|
|
860
|
+
props.t("confirm.workspace.blocked", { n: plan.blocked }),
|
|
861
|
+
)
|
|
862
|
+
: null,
|
|
863
|
+
childCount > 0
|
|
864
|
+
? h(
|
|
865
|
+
"div",
|
|
866
|
+
{ style: { marginTop: "10px" } },
|
|
867
|
+
h(Check, {
|
|
588
868
|
checked: cascade,
|
|
589
869
|
disabled: busy,
|
|
590
|
-
|
|
591
|
-
|
|
870
|
+
label: props.t("confirm.cascade", { n: childCount }),
|
|
871
|
+
onChange: rememberCascade,
|
|
592
872
|
}),
|
|
873
|
+
)
|
|
874
|
+
: null,
|
|
875
|
+
blocked
|
|
876
|
+
? h(
|
|
877
|
+
"div",
|
|
878
|
+
{ style: { color: T.danger, marginTop: "10px" }, role: "alert" },
|
|
879
|
+
props.t("confirm.blocked", { reason: plan.blockers[0].message }),
|
|
880
|
+
)
|
|
881
|
+
: null,
|
|
882
|
+
error ? h("div", { style: { color: T.danger, marginTop: "8px" } }, error) : null,
|
|
883
|
+
plan
|
|
884
|
+
? h(
|
|
885
|
+
"div",
|
|
886
|
+
{ style: { marginTop: "10px" } },
|
|
593
887
|
h(
|
|
594
|
-
|
|
595
|
-
null,
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
888
|
+
Disclosure,
|
|
889
|
+
{ label: props.t("confirm.details"), meta: null, maxHeight: "180px" },
|
|
890
|
+
isWorkspace
|
|
891
|
+
? h(
|
|
892
|
+
React.Fragment,
|
|
893
|
+
null,
|
|
894
|
+
sessionTotal > 0
|
|
895
|
+
? h(
|
|
896
|
+
"div",
|
|
897
|
+
null,
|
|
898
|
+
props.t("confirm.detail.workspaceSessions", {
|
|
899
|
+
list: joinList(plan.sessions, 8),
|
|
900
|
+
}),
|
|
901
|
+
)
|
|
902
|
+
: null,
|
|
903
|
+
plan.missing && plan.missing.length > 0
|
|
904
|
+
? h(
|
|
905
|
+
"div",
|
|
906
|
+
null,
|
|
907
|
+
props.t("confirm.workspace.missing", { n: plan.missing.length }),
|
|
908
|
+
)
|
|
909
|
+
: null,
|
|
910
|
+
h("div", null, props.t("confirm.detail.recoverable")),
|
|
911
|
+
)
|
|
912
|
+
: h(
|
|
913
|
+
React.Fragment,
|
|
914
|
+
null,
|
|
915
|
+
removes.length > 0
|
|
916
|
+
? h(
|
|
917
|
+
"div",
|
|
918
|
+
null,
|
|
919
|
+
props.t("confirm.detail.refs", { list: joinList(removes) }),
|
|
920
|
+
)
|
|
921
|
+
: null,
|
|
922
|
+
children.length > 0
|
|
923
|
+
? h(
|
|
924
|
+
"div",
|
|
925
|
+
null,
|
|
926
|
+
props.t("confirm.detail.children", { list: joinList(children) }),
|
|
927
|
+
)
|
|
928
|
+
: null,
|
|
929
|
+
plan.trashPath
|
|
930
|
+
? h(
|
|
931
|
+
"div",
|
|
932
|
+
null,
|
|
933
|
+
props.t("confirm.detail.trashPath", { path: plan.trashPath }),
|
|
934
|
+
)
|
|
935
|
+
: null,
|
|
936
|
+
h("div", null, props.t("confirm.detail.recoverable")),
|
|
937
|
+
),
|
|
607
938
|
),
|
|
608
939
|
)
|
|
609
940
|
: null,
|
|
610
|
-
lines.map((/** @type {any} */ line, /** @type {any} */ index) =>
|
|
611
|
-
h("div", { key: `line-${index}`, style: { marginBottom: "4px" } }, line),
|
|
612
|
-
),
|
|
613
|
-
!plan && !error ? h("div", { style: { color: T.dim } }, props.t("confirm.loading")) : null,
|
|
614
|
-
error ? h("div", { style: { color: T.danger, marginTop: "8px" } }, error) : null,
|
|
615
941
|
);
|
|
616
942
|
|
|
617
943
|
return h(
|
|
@@ -619,16 +945,34 @@ window.__ModuleLoader__.load({
|
|
|
619
945
|
{
|
|
620
946
|
onClose: close,
|
|
621
947
|
closeLabel: props.t("confirm.cancel"),
|
|
622
|
-
title:
|
|
948
|
+
title: isWorkspace
|
|
949
|
+
? props.t("confirm.workspace.title", {
|
|
950
|
+
name: request.title || plan?.title || workspaceId,
|
|
951
|
+
})
|
|
952
|
+
: props.t("confirm.title"),
|
|
623
953
|
description: props.t("confirm.desc"),
|
|
624
954
|
footer: h(
|
|
625
955
|
React.Fragment,
|
|
626
956
|
null,
|
|
627
|
-
h(Btn, { autoFocus: true, onClick: close, disabled: busy }, props.t("confirm.cancel")),
|
|
628
957
|
h(
|
|
629
958
|
Btn,
|
|
630
|
-
{
|
|
631
|
-
|
|
959
|
+
{ innerRef: cancelRef, onClick: close, disabled: busy },
|
|
960
|
+
props.t("confirm.cancel"),
|
|
961
|
+
),
|
|
962
|
+
h(
|
|
963
|
+
Btn,
|
|
964
|
+
{
|
|
965
|
+
innerRef: confirmRef,
|
|
966
|
+
modalAutofocus: true,
|
|
967
|
+
onClick: confirm,
|
|
968
|
+
variant: "danger",
|
|
969
|
+
disabled: !canConfirm,
|
|
970
|
+
},
|
|
971
|
+
busy
|
|
972
|
+
? props.t("confirm.pending")
|
|
973
|
+
: isWorkspace
|
|
974
|
+
? props.t("confirm.workspace.confirm", { n: sessionTotal })
|
|
975
|
+
: props.t("confirm.confirm"),
|
|
632
976
|
),
|
|
633
977
|
),
|
|
634
978
|
},
|
|
@@ -636,111 +980,57 @@ window.__ModuleLoader__.load({
|
|
|
636
980
|
);
|
|
637
981
|
}
|
|
638
982
|
|
|
983
|
+
/**
|
|
984
|
+
* 回收站面板:只有一件事 —— 看列表、选条目、恢复或彻底删除。
|
|
985
|
+
* 批量条固定在列表上方(不随内容滚动),80 条时也不会「找不到按钮」。
|
|
986
|
+
*/
|
|
639
987
|
function TrashPanel(/** @type {any} */ props) {
|
|
640
988
|
var panelState = useStore(props.panelStore);
|
|
641
989
|
var open = panelState[0];
|
|
642
|
-
var tabState = React.useState("trash");
|
|
643
|
-
var tab = tabState[0];
|
|
644
|
-
var setTab = tabState[1];
|
|
645
990
|
var dataState = React.useState(null);
|
|
646
991
|
var data = dataState[0];
|
|
647
992
|
var setData = dataState[1];
|
|
648
|
-
var auditState = React.useState(null);
|
|
649
|
-
var audit = auditState[0];
|
|
650
|
-
var setAudit = auditState[1];
|
|
651
|
-
var healthState = React.useState(null);
|
|
652
|
-
var health = healthState[0];
|
|
653
|
-
var setHealth = healthState[1];
|
|
654
993
|
var errorState = React.useState(null);
|
|
655
994
|
var error = errorState[0];
|
|
656
995
|
var setError = errorState[1];
|
|
657
|
-
var
|
|
658
|
-
var busyId =
|
|
659
|
-
var setBusyId =
|
|
660
|
-
var
|
|
661
|
-
var confirmPurge =
|
|
662
|
-
var setConfirmPurge =
|
|
663
|
-
var
|
|
664
|
-
var
|
|
665
|
-
var
|
|
666
|
-
var
|
|
667
|
-
var
|
|
668
|
-
var
|
|
669
|
-
var
|
|
670
|
-
var
|
|
671
|
-
var
|
|
672
|
-
var
|
|
673
|
-
var scan = scanState[0];
|
|
674
|
-
var setScan = scanState[1];
|
|
675
|
-
var scanErrorState = React.useState(null);
|
|
676
|
-
var scanError = scanErrorState[0];
|
|
677
|
-
var setScanError = scanErrorState[1];
|
|
678
|
-
var cleanState = React.useState(false);
|
|
679
|
-
var cleaning = cleanState[0];
|
|
680
|
-
var setCleaning = cleanState[1];
|
|
681
|
-
var cleanMsgState = React.useState("");
|
|
682
|
-
var cleanMsg = cleanMsgState[0];
|
|
683
|
-
var setCleanMsg = cleanMsgState[1];
|
|
684
|
-
var receiptsState = React.useState(null);
|
|
685
|
-
var receipts = receiptsState[0];
|
|
686
|
-
var setReceipts = receiptsState[1];
|
|
687
|
-
|
|
688
|
-
const loadReceipts = React.useCallback(() => {
|
|
689
|
-
props
|
|
690
|
-
.call("receipts", { limit: 50 })
|
|
691
|
-
.then((/** @type {any} */ value) => {
|
|
692
|
-
setReceipts(value?.entries ? value.entries : []);
|
|
693
|
-
})
|
|
694
|
-
.catch(() => setReceipts([]));
|
|
695
|
-
}, []);
|
|
696
|
-
|
|
697
|
-
const loadHealth = React.useCallback(() => {
|
|
698
|
-
setScan(null);
|
|
699
|
-
setScanError(null);
|
|
700
|
-
props
|
|
701
|
-
.call("healthScan")
|
|
702
|
-
.then((/** @type {any} */ value) => {
|
|
703
|
-
setScan(value);
|
|
704
|
-
})
|
|
705
|
-
.catch((/** @type {any} */ reason) => {
|
|
706
|
-
setScanError(errorText(reason));
|
|
707
|
-
});
|
|
708
|
-
}, []);
|
|
709
|
-
|
|
710
|
-
const loadAudit = React.useCallback(() => {
|
|
711
|
-
props
|
|
712
|
-
.call("audit", { limit: 100 })
|
|
713
|
-
.then((/** @type {any} */ value) => {
|
|
714
|
-
setAudit(value?.entries ? value.entries : []);
|
|
715
|
-
})
|
|
716
|
-
.catch(() => {});
|
|
717
|
-
}, []);
|
|
996
|
+
var busyIdState = React.useState(null);
|
|
997
|
+
var busyId = busyIdState[0];
|
|
998
|
+
var setBusyId = busyIdState[1];
|
|
999
|
+
var confirmPurgeState = React.useState(null);
|
|
1000
|
+
var confirmPurge = confirmPurgeState[0];
|
|
1001
|
+
var setConfirmPurge = confirmPurgeState[1];
|
|
1002
|
+
var selectedState = React.useState({});
|
|
1003
|
+
var selected = selectedState[0];
|
|
1004
|
+
var setSelected = selectedState[1];
|
|
1005
|
+
var batchState = React.useState(null);
|
|
1006
|
+
var batch = batchState[0];
|
|
1007
|
+
var setBatch = batchState[1];
|
|
1008
|
+
var readOnlyState = React.useState(false);
|
|
1009
|
+
var readOnly = readOnlyState[0];
|
|
1010
|
+
var setReadOnly = readOnlyState[1];
|
|
1011
|
+
var batchControl = React.useRef({ stop: false });
|
|
718
1012
|
|
|
1013
|
+
var loader = React.useMemo(
|
|
1014
|
+
() =>
|
|
1015
|
+
createPanelLoader(props.call, {
|
|
1016
|
+
setData: setData,
|
|
1017
|
+
setReadOnly: setReadOnly,
|
|
1018
|
+
setError: setError,
|
|
1019
|
+
}),
|
|
1020
|
+
[],
|
|
1021
|
+
);
|
|
719
1022
|
var refresh = React.useCallback(() => {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
.then((/** @type {any} */ value) => {
|
|
723
|
-
setData(value);
|
|
724
|
-
})
|
|
725
|
-
.catch((/** @type {any} */ reason) => {
|
|
726
|
-
setError(errorText(reason));
|
|
727
|
-
});
|
|
728
|
-
}, []);
|
|
1023
|
+
void loader.load();
|
|
1024
|
+
}, [loader]);
|
|
729
1025
|
|
|
730
1026
|
React.useEffect(() => {
|
|
731
1027
|
if (!open) return undefined;
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
.then((/** @type {any} */ value) => {
|
|
736
|
-
setHealth(value);
|
|
737
|
-
})
|
|
738
|
-
.catch(() => {});
|
|
739
|
-
loadAudit();
|
|
740
|
-
// 面板打开期间自动同步,不需要手动刷新按钮。
|
|
1028
|
+
void loader.load();
|
|
1029
|
+
void loader.loadHealth();
|
|
1030
|
+
// 面板打开期间自动同步:agent 工具、另一个窗口都可能改动回收站。
|
|
741
1031
|
const timer = setInterval(() => {
|
|
742
1032
|
if (document.visibilityState === "visible") refresh();
|
|
743
|
-
},
|
|
1033
|
+
}, PANEL_POLL_MS);
|
|
744
1034
|
const onVisible = () => {
|
|
745
1035
|
if (document.visibilityState === "visible") refresh();
|
|
746
1036
|
};
|
|
@@ -751,32 +1041,15 @@ window.__ModuleLoader__.load({
|
|
|
751
1041
|
};
|
|
752
1042
|
}, [open]);
|
|
753
1043
|
|
|
754
|
-
const listRef = React.useRef(null);
|
|
755
|
-
const onListKeyDown = (/** @type {any} */ event) => {
|
|
756
|
-
if (event.key === "Escape") {
|
|
757
|
-
event.preventDefault();
|
|
758
|
-
props.panelStore.set(false);
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
const keys = ["ArrowDown", "ArrowUp", "Home", "End"];
|
|
762
|
-
if (!keys.includes(event.key)) return;
|
|
763
|
-
const root = listRef.current;
|
|
764
|
-
if (!root) return;
|
|
765
|
-
const items = [...root.querySelectorAll("button:not([disabled])")];
|
|
766
|
-
if (items.length === 0) return;
|
|
767
|
-
const current = items.indexOf(document.activeElement);
|
|
768
|
-
let next = 0;
|
|
769
|
-
if (event.key === "Home") next = 0;
|
|
770
|
-
else if (event.key === "End") next = items.length - 1;
|
|
771
|
-
else if (event.key === "ArrowDown")
|
|
772
|
-
next = current < 0 ? 0 : Math.min(items.length - 1, current + 1);
|
|
773
|
-
else next = current <= 0 ? 0 : current - 1;
|
|
774
|
-
event.preventDefault();
|
|
775
|
-
items[next].focus();
|
|
776
|
-
};
|
|
777
|
-
|
|
778
1044
|
if (!open) return null;
|
|
779
1045
|
|
|
1046
|
+
var entries = data?.entries || [];
|
|
1047
|
+
var selectedIds = Object.keys(selected).filter(
|
|
1048
|
+
(/** @type {string} */ entryId) => selected[entryId],
|
|
1049
|
+
);
|
|
1050
|
+
var allSelected = entries.length > 0 && selectedIds.length === entries.length;
|
|
1051
|
+
var batchRunning = batch?.running === true;
|
|
1052
|
+
|
|
780
1053
|
var doRestore = (/** @type {any} */ entryId, /** @type {any} */ sessionId) => {
|
|
781
1054
|
setBusyId(entryId);
|
|
782
1055
|
props
|
|
@@ -809,513 +1082,266 @@ window.__ModuleLoader__.load({
|
|
|
809
1082
|
});
|
|
810
1083
|
};
|
|
811
1084
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
setConfirmPurge(null);
|
|
843
|
-
setTrashMsg(props.t("batch.done", { ok: result.succeeded, total: result.total }));
|
|
844
|
-
setSelectedTrash({});
|
|
845
|
-
refresh();
|
|
846
|
-
props.bump?.();
|
|
847
|
-
for (const item of result.results) if (item.ok) props.onPurged?.(undefined);
|
|
848
|
-
})
|
|
849
|
-
.catch((/** @type {any} */ reason) => {
|
|
850
|
-
setTrashBusy(false);
|
|
851
|
-
setTrashMsg(errorText(reason));
|
|
1085
|
+
/**
|
|
1086
|
+
* 分批执行批量动作。宿主单次上限是防御性的硬上限,界面按 BATCH_CHUNK 切块,
|
|
1087
|
+
* 每块之间让出一帧:进度可见、可中途停止、部分失败不中断其余批次。
|
|
1088
|
+
* @param {string[]} ids
|
|
1089
|
+
* @param {"purge" | "restore"} kind
|
|
1090
|
+
*/
|
|
1091
|
+
var startBatch = (ids, kind) => {
|
|
1092
|
+
if (ids.length === 0 || batchRunning) return;
|
|
1093
|
+
batchControl.current = { stop: false };
|
|
1094
|
+
setBatch({ kind: kind, running: true, done: 0, total: ids.length, failures: [] });
|
|
1095
|
+
void runBatch({
|
|
1096
|
+
ids: ids,
|
|
1097
|
+
kind: kind,
|
|
1098
|
+
call: props.call,
|
|
1099
|
+
chunkSize: BATCH_CHUNK,
|
|
1100
|
+
onProgress: (/** @type {any} */ state) => {
|
|
1101
|
+
setBatch(state);
|
|
1102
|
+
},
|
|
1103
|
+
shouldStop: () => batchControl.current.stop === true,
|
|
1104
|
+
onRestored: (/** @type {any} */ sessionId) => props.onRestored?.(sessionId),
|
|
1105
|
+
}).then((/** @type {any} */ summary) => {
|
|
1106
|
+
setSelected((/** @type {any} */ current) => {
|
|
1107
|
+
/** @type {Record<string, boolean>} */
|
|
1108
|
+
var keep = {};
|
|
1109
|
+
for (let index = 0; index < summary.failures.length; index += 1) {
|
|
1110
|
+
if (current[summary.failures[index].entryId]) {
|
|
1111
|
+
keep[summary.failures[index].entryId] = true;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
return keep;
|
|
852
1115
|
});
|
|
1116
|
+
setConfirmPurge(null);
|
|
1117
|
+
refresh();
|
|
1118
|
+
props.bump?.();
|
|
1119
|
+
if (kind === "purge") props.onPurged?.(undefined);
|
|
1120
|
+
});
|
|
853
1121
|
};
|
|
854
1122
|
|
|
855
|
-
var
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
1123
|
+
var toolbar = h(
|
|
1124
|
+
"div",
|
|
1125
|
+
{ className: "dsh-sdel-toolbar" },
|
|
1126
|
+
h(Check, {
|
|
1127
|
+
checked: allSelected,
|
|
1128
|
+
disabled: batchRunning || entries.length === 0,
|
|
1129
|
+
label:
|
|
1130
|
+
selectedIds.length > 0
|
|
1131
|
+
? props.t("trash.selectCount", { n: selectedIds.length, total: entries.length })
|
|
1132
|
+
: props.t("trash.selectAll"),
|
|
1133
|
+
onChange: (/** @type {any} */ next) => {
|
|
1134
|
+
/** @type {Record<string, boolean>} */
|
|
1135
|
+
var map = {};
|
|
1136
|
+
if (next) {
|
|
1137
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
1138
|
+
map[entries[index].entryId] = true;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
setSelected(map);
|
|
1142
|
+
},
|
|
1143
|
+
}),
|
|
1144
|
+
h("span", { style: { flex: 1 } }),
|
|
873
1145
|
h(
|
|
874
|
-
|
|
875
|
-
{
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
setTab("audit");
|
|
890
|
-
loadAudit();
|
|
891
|
-
},
|
|
892
|
-
},
|
|
893
|
-
props.t("panel.tabAudit"),
|
|
894
|
-
),
|
|
895
|
-
h(
|
|
896
|
-
Btn,
|
|
897
|
-
{
|
|
898
|
-
onClick: () => {
|
|
899
|
-
setTab("health");
|
|
900
|
-
loadHealth();
|
|
901
|
-
},
|
|
902
|
-
},
|
|
903
|
-
props.t("panel.tabHealth"),
|
|
904
|
-
),
|
|
905
|
-
h(
|
|
906
|
-
Btn,
|
|
907
|
-
{
|
|
908
|
-
onClick: () => {
|
|
909
|
-
setTab("receipts");
|
|
910
|
-
loadReceipts();
|
|
911
|
-
},
|
|
912
|
-
},
|
|
913
|
-
props.t("panel.tabReceipts"),
|
|
914
|
-
),
|
|
1146
|
+
Btn,
|
|
1147
|
+
{
|
|
1148
|
+
disabled: batchRunning || selectedIds.length === 0,
|
|
1149
|
+
onClick: () => startBatch(selectedIds, "restore"),
|
|
1150
|
+
},
|
|
1151
|
+
props.t("trash.restoreMany", { n: selectedIds.length }),
|
|
1152
|
+
),
|
|
1153
|
+
h(
|
|
1154
|
+
Btn,
|
|
1155
|
+
{
|
|
1156
|
+
variant: "danger",
|
|
1157
|
+
disabled: batchRunning || selectedIds.length === 0,
|
|
1158
|
+
onClick: () => setConfirmPurge("__batch__"),
|
|
1159
|
+
},
|
|
1160
|
+
props.t("trash.purgeMany", { n: selectedIds.length }),
|
|
915
1161
|
),
|
|
916
1162
|
);
|
|
917
1163
|
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
1164
|
+
var batchLine = batch
|
|
1165
|
+
? h(
|
|
1166
|
+
"div",
|
|
1167
|
+
{ className: "dsh-sdel-batch" },
|
|
921
1168
|
h(
|
|
922
|
-
"
|
|
923
|
-
{
|
|
924
|
-
|
|
1169
|
+
"span",
|
|
1170
|
+
{ role: "status" },
|
|
1171
|
+
batch.running
|
|
1172
|
+
? props.t("batch.progress", { done: batch.done, total: batch.total })
|
|
1173
|
+
: props.t("batch.done", {
|
|
1174
|
+
ok: batch.total - batch.failures.length,
|
|
1175
|
+
total: batch.total,
|
|
1176
|
+
}),
|
|
925
1177
|
),
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
receipts.forEach((/** @type {any} */ receipt, /** @type {any} */ index) => {
|
|
929
|
-
const removed = receipt.removed || [];
|
|
930
|
-
const okCount = removed.filter(
|
|
931
|
-
(/** @type {any} */ item) => item.status === "ok",
|
|
932
|
-
).length;
|
|
933
|
-
const detail =
|
|
934
|
-
receipt.action === "trash"
|
|
935
|
-
? `${formatBytes(receipt.sizeBytes || 0)} · ${okCount}/${removed.length}`
|
|
936
|
-
: receipt.action === "restore"
|
|
937
|
-
? props.t("receipts.restored")
|
|
938
|
-
: receipt.action === "purge"
|
|
939
|
-
? formatBytes(receipt.bytes || 0)
|
|
940
|
-
: String(receipt.total || 0);
|
|
941
|
-
content.push(
|
|
942
|
-
h(
|
|
943
|
-
"div",
|
|
944
|
-
{
|
|
945
|
-
key: `receipt-${index}`,
|
|
946
|
-
title: String(receipt.sessionId || ""),
|
|
947
|
-
style: {
|
|
948
|
-
borderTop: `1px solid ${T.border}`,
|
|
949
|
-
padding: "7px 0",
|
|
950
|
-
fontSize: "12px",
|
|
951
|
-
display: "flex",
|
|
952
|
-
alignItems: "baseline",
|
|
953
|
-
gap: "6px",
|
|
954
|
-
},
|
|
955
|
-
},
|
|
956
|
-
h(
|
|
957
|
-
"span",
|
|
958
|
-
{ style: { color: T.faint, whiteSpace: "nowrap" } },
|
|
959
|
-
formatTime(receipt.at),
|
|
960
|
-
),
|
|
961
|
-
h(
|
|
962
|
-
"span",
|
|
963
|
-
{ style: { fontWeight: 600, whiteSpace: "nowrap" } },
|
|
964
|
-
String(receipt.action || ""),
|
|
965
|
-
),
|
|
966
|
-
h(
|
|
1178
|
+
batch.failures.length > 0
|
|
1179
|
+
? h(
|
|
967
1180
|
"span",
|
|
1181
|
+
{ style: { color: T.danger } },
|
|
1182
|
+
props.t("batch.failed", { n: batch.failures.length }),
|
|
1183
|
+
)
|
|
1184
|
+
: null,
|
|
1185
|
+
batch.running
|
|
1186
|
+
? h(
|
|
1187
|
+
Btn,
|
|
968
1188
|
{
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
color: T.dim,
|
|
973
|
-
overflow: "hidden",
|
|
974
|
-
textOverflow: "ellipsis",
|
|
975
|
-
whiteSpace: "nowrap",
|
|
1189
|
+
tight: true,
|
|
1190
|
+
onClick: () => {
|
|
1191
|
+
batchControl.current.stop = true;
|
|
976
1192
|
},
|
|
977
1193
|
},
|
|
978
|
-
|
|
979
|
-
)
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
content.push(
|
|
988
|
-
h("div", { key: "scan-err", style: { color: T.danger, padding: "8px 0" } }, scanError),
|
|
989
|
-
);
|
|
990
|
-
} else if (!scan) {
|
|
991
|
-
content.push(
|
|
992
|
-
h(
|
|
993
|
-
"div",
|
|
994
|
-
{ key: "scan-loading", style: { color: T.dim, padding: "8px 0" } },
|
|
995
|
-
props.t("health.loading"),
|
|
996
|
-
),
|
|
997
|
-
);
|
|
998
|
-
} else if (!scan.ok) {
|
|
999
|
-
content.push(
|
|
1000
|
-
h(
|
|
1001
|
-
"div",
|
|
1002
|
-
{ key: "scan-na", style: { color: T.dim, padding: "8px 0" } },
|
|
1003
|
-
props.t("health.unavailable", { reason: scan.reason || "" }),
|
|
1004
|
-
),
|
|
1005
|
-
);
|
|
1006
|
-
} else {
|
|
1007
|
-
content.push(
|
|
1008
|
-
h(
|
|
1009
|
-
"div",
|
|
1010
|
-
{ key: "scan-inventory", style: { color: T.dim, fontSize: "12px" } },
|
|
1011
|
-
props.t("health.inventory", scan.inventory || {}),
|
|
1012
|
-
),
|
|
1013
|
-
);
|
|
1014
|
-
content.push(
|
|
1015
|
-
h(
|
|
1194
|
+
props.t("batch.stop"),
|
|
1195
|
+
)
|
|
1196
|
+
: null,
|
|
1197
|
+
)
|
|
1198
|
+
: null;
|
|
1199
|
+
|
|
1200
|
+
var confirmLine =
|
|
1201
|
+
confirmPurge === "__batch__"
|
|
1202
|
+
? h(
|
|
1016
1203
|
"div",
|
|
1017
|
-
{
|
|
1018
|
-
props.t("
|
|
1019
|
-
state: scan.agentTool
|
|
1020
|
-
? props.t("health.agentToolOn")
|
|
1021
|
-
: props.t("health.agentToolOff"),
|
|
1022
|
-
}),
|
|
1023
|
-
),
|
|
1024
|
-
);
|
|
1025
|
-
if (scan.findings.length === 0) {
|
|
1026
|
-
content.push(
|
|
1027
|
-
h("div", { key: "scan-ok", style: { padding: "8px 0" } }, props.t("health.ok")),
|
|
1028
|
-
);
|
|
1029
|
-
}
|
|
1030
|
-
scan.findings.forEach((/** @type {any} */ finding, /** @type {any} */ index) => {
|
|
1031
|
-
content.push(
|
|
1204
|
+
{ className: "dsh-sdel-confirm" },
|
|
1205
|
+
h("span", null, props.t("trash.purgeManyConfirm", { n: selectedIds.length })),
|
|
1032
1206
|
h(
|
|
1033
|
-
|
|
1034
|
-
{
|
|
1035
|
-
key: `finding-${index}`,
|
|
1036
|
-
style: {
|
|
1037
|
-
borderTop: `1px solid ${T.border}`,
|
|
1038
|
-
padding: "8px 0",
|
|
1039
|
-
color: finding.severity === "warn" ? T.text : T.dim,
|
|
1040
|
-
},
|
|
1041
|
-
},
|
|
1042
|
-
h(
|
|
1043
|
-
"div",
|
|
1044
|
-
{ style: { fontWeight: 600 } },
|
|
1045
|
-
`${finding.label} · ${props.t("health.items", { n: finding.items.length })}`,
|
|
1046
|
-
),
|
|
1047
|
-
h(
|
|
1048
|
-
"div",
|
|
1049
|
-
{ style: { color: T.faint, fontSize: "12px", wordBreak: "break-all" } },
|
|
1050
|
-
finding.items
|
|
1051
|
-
.slice(0, 6)
|
|
1052
|
-
.map((/** @type {any} */ item) =>
|
|
1053
|
-
typeof item === "string" ? item : JSON.stringify(item),
|
|
1054
|
-
)
|
|
1055
|
-
.join(" · "),
|
|
1056
|
-
),
|
|
1057
|
-
),
|
|
1058
|
-
);
|
|
1059
|
-
});
|
|
1060
|
-
if (scan.cleanable && scan.cleanable.total > 0) {
|
|
1061
|
-
content.push(
|
|
1062
|
-
h(
|
|
1063
|
-
"div",
|
|
1207
|
+
Btn,
|
|
1064
1208
|
{
|
|
1065
|
-
|
|
1066
|
-
|
|
1209
|
+
tight: true,
|
|
1210
|
+
variant: "danger",
|
|
1211
|
+
onClick: () => startBatch(selectedIds, "purge"),
|
|
1067
1212
|
},
|
|
1068
|
-
|
|
1069
|
-
? h(
|
|
1070
|
-
Btn,
|
|
1071
|
-
{
|
|
1072
|
-
danger: true,
|
|
1073
|
-
disabled: cleaning,
|
|
1074
|
-
onClick: () => {
|
|
1075
|
-
setCleaning(true);
|
|
1076
|
-
setCleanMsg("");
|
|
1077
|
-
props
|
|
1078
|
-
.call("cleanHealth", { classes: ["archived", "pinned", "workspace"] })
|
|
1079
|
-
.then((/** @type {any} */ result) => {
|
|
1080
|
-
setCleaning(false);
|
|
1081
|
-
setConfirmPurge(null);
|
|
1082
|
-
setCleanMsg(props.t("health.cleanDone", { n: result.total }));
|
|
1083
|
-
loadHealth();
|
|
1084
|
-
props.bump?.();
|
|
1085
|
-
})
|
|
1086
|
-
.catch((/** @type {any} */ reason) => {
|
|
1087
|
-
setCleaning(false);
|
|
1088
|
-
setCleanMsg(errorText(reason));
|
|
1089
|
-
});
|
|
1090
|
-
},
|
|
1091
|
-
},
|
|
1092
|
-
props.t("health.cleanConfirm", { n: scan.cleanable.total }),
|
|
1093
|
-
)
|
|
1094
|
-
: h(
|
|
1095
|
-
Btn,
|
|
1096
|
-
{ onClick: () => setConfirmPurge("__health__") },
|
|
1097
|
-
props.t("health.clean", { n: scan.cleanable.total }),
|
|
1098
|
-
),
|
|
1213
|
+
props.t("panel.purge"),
|
|
1099
1214
|
),
|
|
1100
|
-
);
|
|
1101
|
-
}
|
|
1102
|
-
if (cleanMsg) {
|
|
1103
|
-
content.push(
|
|
1104
1215
|
h(
|
|
1105
|
-
|
|
1106
|
-
{
|
|
1107
|
-
|
|
1216
|
+
Btn,
|
|
1217
|
+
{ tight: true, onClick: () => setConfirmPurge(null) },
|
|
1218
|
+
props.t("panel.cancelConfirm"),
|
|
1108
1219
|
),
|
|
1109
|
-
)
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1220
|
+
)
|
|
1221
|
+
: null;
|
|
1222
|
+
|
|
1223
|
+
var rows = [];
|
|
1224
|
+
for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
|
|
1225
|
+
const entry = entries[entryIndex];
|
|
1226
|
+
const confirmThis = confirmPurge === entry.entryId;
|
|
1227
|
+
rows.push(
|
|
1228
|
+
h(
|
|
1229
|
+
"div",
|
|
1230
|
+
{ key: entry.entryId, className: "dsh-sdel-row" },
|
|
1231
|
+
h(Check, {
|
|
1232
|
+
checked: Boolean(selected[entry.entryId]),
|
|
1233
|
+
disabled: batchRunning,
|
|
1234
|
+
onChange: () =>
|
|
1235
|
+
setSelected((/** @type {any} */ current) => ({
|
|
1236
|
+
...current,
|
|
1237
|
+
[entry.entryId]: !current[entry.entryId],
|
|
1238
|
+
})),
|
|
1239
|
+
}),
|
|
1123
1240
|
h(
|
|
1124
|
-
"
|
|
1125
|
-
{
|
|
1126
|
-
key: "trash-tools",
|
|
1127
|
-
style: {
|
|
1128
|
-
display: "flex",
|
|
1129
|
-
gap: "8px",
|
|
1130
|
-
alignItems: "center",
|
|
1131
|
-
marginBottom: "8px",
|
|
1132
|
-
flexWrap: "wrap",
|
|
1133
|
-
},
|
|
1134
|
-
},
|
|
1241
|
+
"span",
|
|
1242
|
+
{ className: "dsh-sdel-row-text" },
|
|
1135
1243
|
h(
|
|
1136
|
-
|
|
1244
|
+
"span",
|
|
1137
1245
|
{
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
const all = {};
|
|
1141
|
-
for (const item of entries) all[item.entryId] = true;
|
|
1142
|
-
setSelectedTrash(all);
|
|
1143
|
-
},
|
|
1144
|
-
disabled: trashBusy,
|
|
1246
|
+
className: "dsh-sdel-row-title dsh-sdel-truncate",
|
|
1247
|
+
title: entry.title || entry.sessionId,
|
|
1145
1248
|
},
|
|
1146
|
-
|
|
1249
|
+
entry.title || entry.sessionId,
|
|
1147
1250
|
),
|
|
1148
1251
|
h(
|
|
1149
|
-
|
|
1150
|
-
{
|
|
1151
|
-
props.t("
|
|
1152
|
-
),
|
|
1153
|
-
h(
|
|
1154
|
-
Btn,
|
|
1155
|
-
{
|
|
1156
|
-
disabled: trashBusy || selectedEntryIds.length === 0,
|
|
1157
|
-
onClick: doBatchRestore,
|
|
1158
|
-
},
|
|
1159
|
-
props.t("trash.restoreMany", { n: selectedEntryIds.length }),
|
|
1252
|
+
"span",
|
|
1253
|
+
{ className: "dsh-sdel-row-meta" },
|
|
1254
|
+
`${props.t("panel.size", { size: formatBytes(entry.bytes) })} · ${props.t("panel.trashedAt", { time: formatTime(entry.trashedAt) })}`,
|
|
1160
1255
|
),
|
|
1161
|
-
|
|
1162
|
-
|
|
1256
|
+
),
|
|
1257
|
+
confirmThis
|
|
1258
|
+
? h(
|
|
1259
|
+
"span",
|
|
1260
|
+
{ className: "dsh-sdel-row-actions dsh-sdel-row-actions--open" },
|
|
1261
|
+
h(
|
|
1163
1262
|
Btn,
|
|
1164
1263
|
{
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
onClick:
|
|
1264
|
+
tight: true,
|
|
1265
|
+
variant: "danger",
|
|
1266
|
+
onClick: () => doPurge(entry.entryId, entry.sessionId),
|
|
1168
1267
|
},
|
|
1169
|
-
props.t("
|
|
1170
|
-
)
|
|
1171
|
-
|
|
1268
|
+
props.t("panel.purgeConfirm"),
|
|
1269
|
+
),
|
|
1270
|
+
h(
|
|
1271
|
+
Btn,
|
|
1272
|
+
{ tight: true, onClick: () => setConfirmPurge(null) },
|
|
1273
|
+
props.t("panel.cancelConfirm"),
|
|
1274
|
+
),
|
|
1275
|
+
)
|
|
1276
|
+
: h(
|
|
1277
|
+
"span",
|
|
1278
|
+
{ className: "dsh-sdel-row-actions" },
|
|
1279
|
+
h(
|
|
1172
1280
|
Btn,
|
|
1173
1281
|
{
|
|
1174
|
-
|
|
1175
|
-
disabled:
|
|
1176
|
-
onClick: () =>
|
|
1282
|
+
tight: true,
|
|
1283
|
+
disabled: busyId === entry.entryId || batchRunning,
|
|
1284
|
+
onClick: () => doRestore(entry.entryId, entry.sessionId),
|
|
1177
1285
|
},
|
|
1178
|
-
props.t("
|
|
1286
|
+
props.t("panel.restore"),
|
|
1179
1287
|
),
|
|
1180
|
-
),
|
|
1181
|
-
);
|
|
1182
|
-
if (trashMsg) {
|
|
1183
|
-
content.push(
|
|
1184
|
-
h(
|
|
1185
|
-
"div",
|
|
1186
|
-
{
|
|
1187
|
-
key: "trash-msg",
|
|
1188
|
-
style: { color: T.dim, fontSize: "12px", marginBottom: "6px" },
|
|
1189
|
-
},
|
|
1190
|
-
trashMsg,
|
|
1191
|
-
),
|
|
1192
|
-
);
|
|
1193
|
-
}
|
|
1194
|
-
entries.forEach((/** @type {any} */ entry) => {
|
|
1195
|
-
content.push(
|
|
1196
|
-
h(
|
|
1197
|
-
"div",
|
|
1198
|
-
{ key: entry.entryId, style: rowStyle },
|
|
1199
|
-
h(
|
|
1200
|
-
"label",
|
|
1201
|
-
{ style: { display: "flex", alignItems: "baseline", gap: "8px" } },
|
|
1202
|
-
h("input", {
|
|
1203
|
-
type: "checkbox",
|
|
1204
|
-
checked: Boolean(/** @type {any} */ (selectedTrash)[entry.entryId]),
|
|
1205
|
-
disabled: trashBusy,
|
|
1206
|
-
onChange: () =>
|
|
1207
|
-
setSelectedTrash((/** @type {any} */ current) => ({
|
|
1208
|
-
...current,
|
|
1209
|
-
[entry.entryId]: !current[entry.entryId],
|
|
1210
|
-
})),
|
|
1211
|
-
style: { marginTop: "2px" },
|
|
1212
|
-
}),
|
|
1213
|
-
h("span", { style: { fontWeight: 600 } }, entry.title || entry.sessionId),
|
|
1214
|
-
),
|
|
1215
|
-
h(
|
|
1216
|
-
"div",
|
|
1217
|
-
{ style: { color: T.dim, fontSize: "12px" } },
|
|
1218
|
-
props.t("panel.size", { size: formatBytes(entry.bytes) }) +
|
|
1219
|
-
" · " +
|
|
1220
|
-
props.t("panel.trashedAt", { time: formatTime(entry.trashedAt) }),
|
|
1221
|
-
),
|
|
1222
|
-
h(
|
|
1223
|
-
"div",
|
|
1224
|
-
{ style: { display: "flex", gap: "8px", marginTop: "6px" } },
|
|
1225
1288
|
h(
|
|
1226
1289
|
Btn,
|
|
1227
1290
|
{
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1291
|
+
tight: true,
|
|
1292
|
+
variant: "danger",
|
|
1293
|
+
disabled: busyId === entry.entryId || batchRunning,
|
|
1294
|
+
onClick: () => setConfirmPurge(entry.entryId),
|
|
1232
1295
|
},
|
|
1233
|
-
props.t("panel.
|
|
1296
|
+
props.t("panel.purge"),
|
|
1234
1297
|
),
|
|
1235
|
-
confirmPurge === entry.entryId
|
|
1236
|
-
? h(
|
|
1237
|
-
Btn,
|
|
1238
|
-
{
|
|
1239
|
-
onClick: () => {
|
|
1240
|
-
doPurge(entry.entryId, entry.sessionId);
|
|
1241
|
-
},
|
|
1242
|
-
danger: true,
|
|
1243
|
-
disabled: busyId === entry.entryId,
|
|
1244
|
-
},
|
|
1245
|
-
props.t("panel.purgeConfirm"),
|
|
1246
|
-
)
|
|
1247
|
-
: h(
|
|
1248
|
-
Btn,
|
|
1249
|
-
{
|
|
1250
|
-
onClick: () => {
|
|
1251
|
-
setConfirmPurge(entry.entryId);
|
|
1252
|
-
},
|
|
1253
|
-
danger: true,
|
|
1254
|
-
},
|
|
1255
|
-
props.t("panel.purge"),
|
|
1256
|
-
),
|
|
1257
1298
|
),
|
|
1258
|
-
),
|
|
1259
|
-
);
|
|
1260
|
-
});
|
|
1261
|
-
}
|
|
1262
|
-
} else if ((audit || []).length === 0) {
|
|
1263
|
-
content.push(
|
|
1264
|
-
h(
|
|
1265
|
-
"div",
|
|
1266
|
-
{ key: "ae", style: { color: T.dim, padding: "12px 0" } },
|
|
1267
|
-
props.t("panel.auditEmpty"),
|
|
1268
1299
|
),
|
|
1269
1300
|
);
|
|
1270
|
-
} else {
|
|
1271
|
-
(audit || [])
|
|
1272
|
-
.slice()
|
|
1273
|
-
.reverse()
|
|
1274
|
-
.forEach((/** @type {any} */ entry, /** @type {any} */ index) => {
|
|
1275
|
-
content.push(
|
|
1276
|
-
h(
|
|
1277
|
-
"div",
|
|
1278
|
-
{
|
|
1279
|
-
key: `audit-${index}`,
|
|
1280
|
-
style: { borderTop: `1px solid ${T.border}`, padding: "6px 0", fontSize: "12px" },
|
|
1281
|
-
},
|
|
1282
|
-
h("span", { style: { color: T.faint } }, `${formatTime(entry.ts)} `),
|
|
1283
|
-
h("span", { style: { fontWeight: 600 } }, `${String(entry.action || "")} `),
|
|
1284
|
-
h(
|
|
1285
|
-
"span",
|
|
1286
|
-
{ title: entry.sessionId || "", style: { color: T.dim } },
|
|
1287
|
-
String(entry.result || "") +
|
|
1288
|
-
(entry.sessionId ? ` · ${String(entry.sessionId).slice(0, 13)}…` : "") +
|
|
1289
|
-
(entry.detail ? ` · ${entry.detail}` : ""),
|
|
1290
|
-
),
|
|
1291
|
-
),
|
|
1292
|
-
);
|
|
1293
|
-
});
|
|
1294
1301
|
}
|
|
1295
1302
|
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1303
|
+
var body = h(
|
|
1304
|
+
React.Fragment,
|
|
1305
|
+
null,
|
|
1306
|
+
readOnly
|
|
1307
|
+
? h(
|
|
1308
|
+
"div",
|
|
1309
|
+
{ style: { color: T.danger, marginBottom: "10px" } },
|
|
1310
|
+
props.t("panel.readOnly"),
|
|
1311
|
+
)
|
|
1312
|
+
: null,
|
|
1313
|
+
error ? h("div", { style: { color: T.danger, marginBottom: "10px" } }, error) : null,
|
|
1314
|
+
entries.length === 0
|
|
1315
|
+
? h("div", { style: { color: T.dim, padding: "12px 0" } }, props.t("panel.empty"))
|
|
1316
|
+
: h(
|
|
1317
|
+
"div",
|
|
1318
|
+
{ className: "dsh-sdel-panel" },
|
|
1319
|
+
toolbar,
|
|
1320
|
+
confirmLine,
|
|
1321
|
+
batchLine,
|
|
1322
|
+
h("div", { className: "dsh-sdel-list" }, rows),
|
|
1323
|
+
),
|
|
1324
|
+
(data?.unknown?.length ?? 0) > 0
|
|
1325
|
+
? h(
|
|
1326
|
+
"div",
|
|
1327
|
+
{ style: { color: T.faint, fontSize: "12px", marginTop: "8px" } },
|
|
1328
|
+
props.t("panel.unknown", { n: data.unknown.length }),
|
|
1329
|
+
)
|
|
1330
|
+
: null,
|
|
1331
|
+
(data?.pending?.length ?? 0) > 0
|
|
1332
|
+
? h(
|
|
1333
|
+
"div",
|
|
1334
|
+
{ style: { color: T.faint, fontSize: "12px", marginTop: "4px" } },
|
|
1335
|
+
props.t("panel.pending", { n: data.pending.length }),
|
|
1336
|
+
)
|
|
1337
|
+
: null,
|
|
1338
|
+
);
|
|
1314
1339
|
|
|
1315
1340
|
return h(
|
|
1316
1341
|
Dialog,
|
|
1317
1342
|
{
|
|
1318
1343
|
onClose: () => {
|
|
1344
|
+
if (batchRunning) return;
|
|
1319
1345
|
props.panelStore.set(false);
|
|
1320
1346
|
},
|
|
1321
1347
|
closeLabel: props.t("panel.close"),
|
|
@@ -1323,19 +1349,281 @@ window.__ModuleLoader__.load({
|
|
|
1323
1349
|
footer: h(
|
|
1324
1350
|
Btn,
|
|
1325
1351
|
{
|
|
1326
|
-
autoFocus: true,
|
|
1327
1352
|
onClick: () => {
|
|
1328
1353
|
props.panelStore.set(false);
|
|
1329
1354
|
},
|
|
1355
|
+
disabled: batchRunning,
|
|
1330
1356
|
},
|
|
1331
1357
|
props.t("panel.close"),
|
|
1332
1358
|
),
|
|
1333
1359
|
},
|
|
1360
|
+
body,
|
|
1361
|
+
);
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
/**
|
|
1365
|
+
* 设置页「会话回收站」:偏好 + 回收站概览 + 维护(体检/回执/审计)。
|
|
1366
|
+
* 原来这四块是回收站面板里的四个页签,搬到这里后主面板只剩一件事。
|
|
1367
|
+
*/
|
|
1368
|
+
function SettingsSection(/** @type {any} */ props) {
|
|
1369
|
+
var prefsState = useStore(props.prefsStore);
|
|
1370
|
+
var prefs = prefsState[0];
|
|
1371
|
+
var infoState = React.useState(null);
|
|
1372
|
+
var info = infoState[0];
|
|
1373
|
+
var setInfo = infoState[1];
|
|
1374
|
+
var healthState = React.useState(null);
|
|
1375
|
+
var health = healthState[0];
|
|
1376
|
+
var setHealth = healthState[1];
|
|
1377
|
+
var healthErrorState = React.useState(null);
|
|
1378
|
+
var healthError = healthErrorState[0];
|
|
1379
|
+
var setHealthError = healthErrorState[1];
|
|
1380
|
+
var receiptsState = React.useState(null);
|
|
1381
|
+
var receipts = receiptsState[0];
|
|
1382
|
+
var setReceipts = receiptsState[1];
|
|
1383
|
+
var auditState = React.useState(null);
|
|
1384
|
+
var audit = auditState[0];
|
|
1385
|
+
var setAudit = auditState[1];
|
|
1386
|
+
var cleaningState = React.useState(false);
|
|
1387
|
+
var cleaning = cleaningState[0];
|
|
1388
|
+
var setCleaning = cleaningState[1];
|
|
1389
|
+
var confirmCleanState = React.useState(false);
|
|
1390
|
+
var confirmClean = confirmCleanState[0];
|
|
1391
|
+
var setConfirmClean = confirmCleanState[1];
|
|
1392
|
+
var msgState = React.useState("");
|
|
1393
|
+
var message = msgState[0];
|
|
1394
|
+
var setMessage = msgState[1];
|
|
1395
|
+
|
|
1396
|
+
React.useEffect(() => {
|
|
1397
|
+
var alive = true;
|
|
1398
|
+
props
|
|
1399
|
+
.call("list")
|
|
1400
|
+
.then((/** @type {any} */ value) => {
|
|
1401
|
+
if (alive) setInfo(value);
|
|
1402
|
+
})
|
|
1403
|
+
.catch(() => {});
|
|
1404
|
+
props
|
|
1405
|
+
.call("healthScan")
|
|
1406
|
+
.then((/** @type {any} */ value) => {
|
|
1407
|
+
if (alive) setHealth(value);
|
|
1408
|
+
})
|
|
1409
|
+
.catch((/** @type {any} */ reason) => {
|
|
1410
|
+
if (alive) setHealthError(errorText(reason));
|
|
1411
|
+
});
|
|
1412
|
+
props
|
|
1413
|
+
.call("receipts", { limit: 50 })
|
|
1414
|
+
.then((/** @type {any} */ value) => {
|
|
1415
|
+
if (alive) setReceipts(value?.entries || []);
|
|
1416
|
+
})
|
|
1417
|
+
.catch((/** @type {any} */ reason) => {
|
|
1418
|
+
// 空白 + 一声不响是最差的失败姿态:把原因写进页面里。
|
|
1419
|
+
if (alive) setMessage(errorText(reason));
|
|
1420
|
+
});
|
|
1421
|
+
props
|
|
1422
|
+
.call("audit", { limit: 100 })
|
|
1423
|
+
.then((/** @type {any} */ value) => {
|
|
1424
|
+
if (alive) setAudit(value?.entries || []);
|
|
1425
|
+
})
|
|
1426
|
+
.catch((/** @type {any} */ reason) => {
|
|
1427
|
+
if (alive) setMessage(errorText(reason));
|
|
1428
|
+
});
|
|
1429
|
+
return () => {
|
|
1430
|
+
alive = false;
|
|
1431
|
+
};
|
|
1432
|
+
}, []);
|
|
1433
|
+
|
|
1434
|
+
var entries = info?.entries || [];
|
|
1435
|
+
var totalBytes = 0;
|
|
1436
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
1437
|
+
totalBytes += Number(entries[index].bytes) || 0;
|
|
1438
|
+
}
|
|
1439
|
+
var cascade = prefs ? prefs.cascadeChildren === true : false;
|
|
1440
|
+
|
|
1441
|
+
var setCascade = (/** @type {any} */ next) => {
|
|
1442
|
+
props.prefsStore.set({ cascadeChildren: next });
|
|
1443
|
+
props.call("setPrefs", { cascadeChildren: next }).catch(() => {});
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1446
|
+
var cleanable = health?.ok ? health.cleanable : null;
|
|
1447
|
+
var cleanRows = [];
|
|
1448
|
+
if (confirmClean && cleanable && cleanable.total > 0) {
|
|
1449
|
+
cleanRows.push(
|
|
1450
|
+
h(
|
|
1451
|
+
"div",
|
|
1452
|
+
{ key: "confirm", style: { display: "flex", gap: "8px", alignItems: "center" } },
|
|
1453
|
+
h(
|
|
1454
|
+
"span",
|
|
1455
|
+
{ style: { color: T.danger, fontSize: "12px" } },
|
|
1456
|
+
props.t("settings.health.cleanConfirm", { n: cleanable.total }),
|
|
1457
|
+
),
|
|
1458
|
+
h(
|
|
1459
|
+
Btn,
|
|
1460
|
+
{
|
|
1461
|
+
tight: true,
|
|
1462
|
+
variant: "danger",
|
|
1463
|
+
disabled: cleaning,
|
|
1464
|
+
onClick: () => {
|
|
1465
|
+
setCleaning(true);
|
|
1466
|
+
props
|
|
1467
|
+
.call("cleanHealth", { classes: ["archived", "pinned", "workspace"] })
|
|
1468
|
+
.then((/** @type {any} */ result) => {
|
|
1469
|
+
setCleaning(false);
|
|
1470
|
+
setConfirmClean(false);
|
|
1471
|
+
setMessage(props.t("settings.health.cleaned", { n: result.total }));
|
|
1472
|
+
})
|
|
1473
|
+
.catch((/** @type {any} */ reason) => {
|
|
1474
|
+
setCleaning(false);
|
|
1475
|
+
setMessage(errorText(reason));
|
|
1476
|
+
});
|
|
1477
|
+
},
|
|
1478
|
+
},
|
|
1479
|
+
props.t("settings.health.clean", { n: cleanable.total }),
|
|
1480
|
+
),
|
|
1481
|
+
h(
|
|
1482
|
+
Btn,
|
|
1483
|
+
{ tight: true, onClick: () => setConfirmClean(false) },
|
|
1484
|
+
props.t("confirm.cancel"),
|
|
1485
|
+
),
|
|
1486
|
+
),
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
return h(
|
|
1491
|
+
"div",
|
|
1492
|
+
{ className: "dsh-sdel-settings" },
|
|
1493
|
+
h("div", { className: "dsh-sdel-group" }, props.t("settings.group.delete")),
|
|
1494
|
+
h(SettingRow, {
|
|
1495
|
+
title: props.t("settings.cascade.title"),
|
|
1496
|
+
description: props.t("settings.cascade.desc"),
|
|
1497
|
+
action: h(Toggle, {
|
|
1498
|
+
checked: cascade,
|
|
1499
|
+
label: props.t("settings.cascade.title"),
|
|
1500
|
+
onChange: setCascade,
|
|
1501
|
+
}),
|
|
1502
|
+
}),
|
|
1503
|
+
h(SettingRow, {
|
|
1504
|
+
title: "",
|
|
1505
|
+
description: null,
|
|
1506
|
+
action: h(
|
|
1507
|
+
Btn,
|
|
1508
|
+
{
|
|
1509
|
+
tight: true,
|
|
1510
|
+
disabled: !cascade,
|
|
1511
|
+
onClick: () => {
|
|
1512
|
+
setCascade(false);
|
|
1513
|
+
setMessage(props.t("settings.cascade.resetDone"));
|
|
1514
|
+
},
|
|
1515
|
+
},
|
|
1516
|
+
props.t("settings.cascade.reset"),
|
|
1517
|
+
),
|
|
1518
|
+
}),
|
|
1519
|
+
h("div", { className: "dsh-sdel-group" }, props.t("settings.group.trash")),
|
|
1520
|
+
h(SettingRow, {
|
|
1521
|
+
title: props.t("settings.trash.summary", {
|
|
1522
|
+
n: entries.length,
|
|
1523
|
+
size: formatBytes(totalBytes),
|
|
1524
|
+
}),
|
|
1525
|
+
description: info ? info.trashRoot : null,
|
|
1526
|
+
action: h(
|
|
1527
|
+
Btn,
|
|
1528
|
+
{
|
|
1529
|
+
tight: true,
|
|
1530
|
+
onClick: () => {
|
|
1531
|
+
props.close?.();
|
|
1532
|
+
props.panelStore.set(true);
|
|
1533
|
+
},
|
|
1534
|
+
},
|
|
1535
|
+
props.t("settings.trash.open"),
|
|
1536
|
+
),
|
|
1537
|
+
}),
|
|
1538
|
+
h("div", { className: "dsh-sdel-group" }, props.t("settings.group.maintenance")),
|
|
1539
|
+
h(SettingRow, {
|
|
1540
|
+
title: props.t("settings.health.title"),
|
|
1541
|
+
description: props.t("settings.health.desc"),
|
|
1542
|
+
action:
|
|
1543
|
+
cleanable && cleanable.total > 0
|
|
1544
|
+
? h(
|
|
1545
|
+
Btn,
|
|
1546
|
+
{ tight: true, disabled: cleaning, onClick: () => setConfirmClean(true) },
|
|
1547
|
+
props.t("settings.health.items", { n: cleanable.total }),
|
|
1548
|
+
)
|
|
1549
|
+
: null,
|
|
1550
|
+
children: healthError
|
|
1551
|
+
? h(
|
|
1552
|
+
"div",
|
|
1553
|
+
{ style: { color: T.danger, fontSize: "12px" } },
|
|
1554
|
+
props.t("settings.health.unavailable", { reason: healthError }),
|
|
1555
|
+
)
|
|
1556
|
+
: !health
|
|
1557
|
+
? h(
|
|
1558
|
+
"div",
|
|
1559
|
+
{ style: { color: T.faint, fontSize: "12px" } },
|
|
1560
|
+
props.t("settings.loading"),
|
|
1561
|
+
)
|
|
1562
|
+
: !health.ok
|
|
1563
|
+
? h(
|
|
1564
|
+
"div",
|
|
1565
|
+
{ style: { color: T.dim, fontSize: "12px" } },
|
|
1566
|
+
props.t("settings.health.unavailable", { reason: health.reason || "" }),
|
|
1567
|
+
)
|
|
1568
|
+
: health.findings && health.findings.length === 0
|
|
1569
|
+
? h(
|
|
1570
|
+
"div",
|
|
1571
|
+
{ style: { color: T.dim, fontSize: "12px" } },
|
|
1572
|
+
props.t("settings.health.ok"),
|
|
1573
|
+
)
|
|
1574
|
+
: h(
|
|
1575
|
+
"div",
|
|
1576
|
+
{ style: { color: T.dim, fontSize: "12px" } },
|
|
1577
|
+
joinList(
|
|
1578
|
+
(health.findings || []).map((/** @type {any} */ finding) => finding.label),
|
|
1579
|
+
4,
|
|
1580
|
+
),
|
|
1581
|
+
),
|
|
1582
|
+
}),
|
|
1583
|
+
cleanRows.length > 0 ? h("div", { style: { padding: "0 0 12px" } }, cleanRows) : null,
|
|
1334
1584
|
h(
|
|
1335
1585
|
"div",
|
|
1336
|
-
{
|
|
1337
|
-
|
|
1586
|
+
{ className: "dsh-sdel-setting-row dsh-sdel-setting-row--stack" },
|
|
1587
|
+
h(
|
|
1588
|
+
Disclosure,
|
|
1589
|
+
{
|
|
1590
|
+
label: props.t("settings.receipts.title"),
|
|
1591
|
+
meta: receipts ? String(receipts.length) : "",
|
|
1592
|
+
},
|
|
1593
|
+
!receipts || receipts.length === 0
|
|
1594
|
+
? h("div", null, props.t("settings.receipts.empty"))
|
|
1595
|
+
: receipts.map((/** @type {any} */ receipt, /** @type {any} */ receiptIndex) =>
|
|
1596
|
+
h(
|
|
1597
|
+
"div",
|
|
1598
|
+
{ key: `receipt-${receiptIndex}`, className: "dsh-sdel-truncate" },
|
|
1599
|
+
`${formatTime(receipt.at)} · ${String(receipt.action || "")} · ${String(receipt.title || receipt.sessionId || "")}`,
|
|
1600
|
+
),
|
|
1601
|
+
),
|
|
1602
|
+
),
|
|
1338
1603
|
),
|
|
1604
|
+
h(
|
|
1605
|
+
"div",
|
|
1606
|
+
{ className: "dsh-sdel-setting-row dsh-sdel-setting-row--stack" },
|
|
1607
|
+
h(
|
|
1608
|
+
Disclosure,
|
|
1609
|
+
{ label: props.t("settings.audit.title"), meta: audit ? String(audit.length) : "" },
|
|
1610
|
+
!audit || audit.length === 0
|
|
1611
|
+
? h("div", null, props.t("settings.audit.empty"))
|
|
1612
|
+
: audit
|
|
1613
|
+
.slice()
|
|
1614
|
+
.reverse()
|
|
1615
|
+
.map((/** @type {any} */ entry, /** @type {any} */ auditIndex) =>
|
|
1616
|
+
h(
|
|
1617
|
+
"div",
|
|
1618
|
+
{ key: `audit-${auditIndex}`, className: "dsh-sdel-truncate" },
|
|
1619
|
+
`${formatTime(entry.ts)} · ${String(entry.action || "")} · ${String(entry.result || "")}${entry.detail ? ` · ${entry.detail}` : ""}`,
|
|
1620
|
+
),
|
|
1621
|
+
),
|
|
1622
|
+
),
|
|
1623
|
+
),
|
|
1624
|
+
message
|
|
1625
|
+
? h("div", { style: { color: T.dim, fontSize: "12px", paddingTop: "8px" } }, message)
|
|
1626
|
+
: null,
|
|
1339
1627
|
);
|
|
1340
1628
|
}
|
|
1341
1629
|
|
|
@@ -1343,6 +1631,7 @@ window.__ModuleLoader__.load({
|
|
|
1343
1631
|
var toastState = useStore(props.toastStore);
|
|
1344
1632
|
var toast = toastState[0];
|
|
1345
1633
|
var entryId = toast ? toast.entryId : null;
|
|
1634
|
+
var text = toast ? toast.text : null;
|
|
1346
1635
|
var shownState = React.useState(false);
|
|
1347
1636
|
var shown = shownState[0];
|
|
1348
1637
|
var setShown = shownState[1];
|
|
@@ -1351,7 +1640,7 @@ window.__ModuleLoader__.load({
|
|
|
1351
1640
|
var setRestoring = restoreState[1];
|
|
1352
1641
|
|
|
1353
1642
|
React.useEffect(() => {
|
|
1354
|
-
if (!
|
|
1643
|
+
if (!toast) {
|
|
1355
1644
|
setShown(false);
|
|
1356
1645
|
return undefined;
|
|
1357
1646
|
}
|
|
@@ -1365,7 +1654,7 @@ window.__ModuleLoader__.load({
|
|
|
1365
1654
|
clearTimeout(raise);
|
|
1366
1655
|
clearTimeout(timer);
|
|
1367
1656
|
};
|
|
1368
|
-
}, [
|
|
1657
|
+
}, [toast]);
|
|
1369
1658
|
|
|
1370
1659
|
if (!toast) return null;
|
|
1371
1660
|
return h(
|
|
@@ -1391,29 +1680,148 @@ window.__ModuleLoader__.load({
|
|
|
1391
1680
|
transition: "opacity .18s ease, transform .18s ease",
|
|
1392
1681
|
},
|
|
1393
1682
|
},
|
|
1394
|
-
h("span", null, props.t("confirm.done")),
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1683
|
+
h("span", null, text ? text : props.t("confirm.done")),
|
|
1684
|
+
entryId
|
|
1685
|
+
? h(
|
|
1686
|
+
Btn,
|
|
1687
|
+
{
|
|
1688
|
+
disabled: restoring,
|
|
1689
|
+
onClick: () => {
|
|
1690
|
+
setRestoring(true);
|
|
1691
|
+
props
|
|
1692
|
+
.call("restore", { entryId: toast.entryId })
|
|
1693
|
+
.then(() => {
|
|
1694
|
+
setRestoring(false);
|
|
1695
|
+
props.toastStore.set(null);
|
|
1696
|
+
})
|
|
1697
|
+
.catch(() => {
|
|
1698
|
+
setRestoring(false);
|
|
1699
|
+
});
|
|
1700
|
+
},
|
|
1701
|
+
},
|
|
1702
|
+
props.t("confirm.undo"),
|
|
1703
|
+
)
|
|
1704
|
+
: null,
|
|
1414
1705
|
);
|
|
1415
1706
|
}
|
|
1416
1707
|
|
|
1708
|
+
/** 面板打开后的轮询间隔:外部(agent 工具 / 另一个窗口)改了回收站也要跟上。 */
|
|
1709
|
+
var PANEL_POLL_MS = 5000;
|
|
1710
|
+
|
|
1711
|
+
/**
|
|
1712
|
+
* 加载回收站面板的数据。抽出来是为了单测能直接驱动它 —— 面板的加载失败
|
|
1713
|
+
* 不许把整个浮层(确认框、toast)一起拖死,这个行为必须在没有浏览器的地方也能验证。
|
|
1714
|
+
* @param {(method: string, request?: any) => Promise<any>} call
|
|
1715
|
+
* @param {{ setData?: (value: any) => void, setReadOnly?: (value: boolean) => void,
|
|
1716
|
+
* setError?: (value: string | null) => void }} sinks
|
|
1717
|
+
* @returns {{ load: () => Promise<any>, loadHealth: () => Promise<void> }}
|
|
1718
|
+
*/
|
|
1719
|
+
function createPanelLoader(call, sinks) {
|
|
1720
|
+
var report = (/** @type {any} */ reason) => {
|
|
1721
|
+
try {
|
|
1722
|
+
sinks.setError?.(errorText(reason));
|
|
1723
|
+
} catch (_error) {
|
|
1724
|
+
/* 渲染层挂了也不该让 RPC 的 rejection 逃逸成未捕获异常 */
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
var load = () =>
|
|
1728
|
+
Promise.resolve()
|
|
1729
|
+
.then(() => call("list"))
|
|
1730
|
+
.then(
|
|
1731
|
+
(/** @type {any} */ value) => {
|
|
1732
|
+
try {
|
|
1733
|
+
sinks.setData?.(value);
|
|
1734
|
+
} catch (_error) {}
|
|
1735
|
+
return value;
|
|
1736
|
+
},
|
|
1737
|
+
(/** @type {any} */ reason) => {
|
|
1738
|
+
report(reason);
|
|
1739
|
+
return null;
|
|
1740
|
+
},
|
|
1741
|
+
);
|
|
1742
|
+
var loadHealth = () =>
|
|
1743
|
+
Promise.resolve()
|
|
1744
|
+
.then(() => call("health"))
|
|
1745
|
+
.then(
|
|
1746
|
+
(/** @type {any} */ value) => {
|
|
1747
|
+
try {
|
|
1748
|
+
sinks.setReadOnly?.(value?.readOnly === true);
|
|
1749
|
+
} catch (_error) {}
|
|
1750
|
+
},
|
|
1751
|
+
() => {
|
|
1752
|
+
/* 能力快照拿不到只影响只读横幅,不报错 */
|
|
1753
|
+
},
|
|
1754
|
+
);
|
|
1755
|
+
return { load: load, loadHealth: loadHealth };
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
/**
|
|
1759
|
+
* 分批执行批量动作。宿主单次上限是防御性硬上限,界面按 chunkSize 切块;
|
|
1760
|
+
* 每块之间让出一帧:进度可见、可中途停止、部分失败不中断其余批次。
|
|
1761
|
+
* 抽成纯函数是为了在单测里用假 call 直接验证「>50 条不会被整单拒绝」与
|
|
1762
|
+
* 「部分失败被汇总、成功的也不再算失败」。
|
|
1763
|
+
* @param {{ ids: string[], kind: "purge" | "restore", call: (method: string, request?: any) => Promise<any>,
|
|
1764
|
+
* chunkSize?: number, onProgress?: (state: any) => void, shouldStop?: () => boolean,
|
|
1765
|
+
* onRestored?: (sessionId: string) => void }} options
|
|
1766
|
+
* @returns {Promise<{ kind: string, total: number, done: number, ok: number, failures: any[], stopped: boolean }>}
|
|
1767
|
+
*/
|
|
1768
|
+
async function runBatch(options) {
|
|
1769
|
+
var ids = options.ids || [];
|
|
1770
|
+
var kind = options.kind === "restore" ? "restore" : "purge";
|
|
1771
|
+
var chunkSize = options.chunkSize || BATCH_CHUNK;
|
|
1772
|
+
var groups = chunk(ids, chunkSize);
|
|
1773
|
+
/** @type {any[]} */
|
|
1774
|
+
var failures = [];
|
|
1775
|
+
var done = 0;
|
|
1776
|
+
var stopped = false;
|
|
1777
|
+
const emit = (/** @type {boolean} */ running) => {
|
|
1778
|
+
try {
|
|
1779
|
+
options.onProgress?.({
|
|
1780
|
+
kind: kind,
|
|
1781
|
+
running: running,
|
|
1782
|
+
done: done,
|
|
1783
|
+
total: ids.length,
|
|
1784
|
+
failures: failures.slice(),
|
|
1785
|
+
});
|
|
1786
|
+
} catch (_error) {}
|
|
1787
|
+
};
|
|
1788
|
+
for (let index = 0; index < groups.length; index += 1) {
|
|
1789
|
+
if (options.shouldStop?.()) {
|
|
1790
|
+
stopped = true;
|
|
1791
|
+
break;
|
|
1792
|
+
}
|
|
1793
|
+
const group = groups[index];
|
|
1794
|
+
try {
|
|
1795
|
+
const result = await options.call(kind === "purge" ? "purgeMany" : "restoreMany", {
|
|
1796
|
+
entryIds: group,
|
|
1797
|
+
});
|
|
1798
|
+
const results = result?.results || [];
|
|
1799
|
+
for (let itemIndex = 0; itemIndex < results.length; itemIndex += 1) {
|
|
1800
|
+
const item = results[itemIndex];
|
|
1801
|
+
if (!item.ok) failures.push(item);
|
|
1802
|
+
else if (kind === "restore" && item.sessionId) options.onRestored?.(item.sessionId);
|
|
1803
|
+
}
|
|
1804
|
+
} catch (reason) {
|
|
1805
|
+
for (let groupIndex = 0; groupIndex < group.length; groupIndex += 1) {
|
|
1806
|
+
failures.push({ entryId: group[groupIndex], ok: false, error: errorText(reason) });
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
done += group.length;
|
|
1810
|
+
emit(true);
|
|
1811
|
+
// 让出一帧:让「处理中 n/total」和「停止」真的可见、可点。
|
|
1812
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1813
|
+
}
|
|
1814
|
+
emit(false);
|
|
1815
|
+
return {
|
|
1816
|
+
kind: kind,
|
|
1817
|
+
total: ids.length,
|
|
1818
|
+
done: done,
|
|
1819
|
+
ok: done - failures.length,
|
|
1820
|
+
failures: failures,
|
|
1821
|
+
stopped: stopped,
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1417
1825
|
/** 一个浮层里渲染确认框 + 面板 + toast,因为 shell.overlay 是单实例 slot。 */
|
|
1418
1826
|
function SessionDeleteOverlay(/** @type {any} */ props) {
|
|
1419
1827
|
return h(
|
|
@@ -1423,8 +1831,10 @@ window.__ModuleLoader__.load({
|
|
|
1423
1831
|
DeleteConfirm,
|
|
1424
1832
|
Object.assign({}, props, {
|
|
1425
1833
|
requestStore: props.requestStore,
|
|
1834
|
+
prefsStore: props.prefsStore,
|
|
1426
1835
|
call: props.call,
|
|
1427
1836
|
onTrashed: props.onTrashed,
|
|
1837
|
+
onTrashedMany: props.onTrashedMany,
|
|
1428
1838
|
}),
|
|
1429
1839
|
),
|
|
1430
1840
|
h(
|
|
@@ -1442,25 +1852,83 @@ window.__ModuleLoader__.load({
|
|
|
1442
1852
|
);
|
|
1443
1853
|
}
|
|
1444
1854
|
|
|
1855
|
+
/** 单批条目数:既让「处理中 n/total」有节奏,也避免一次 RPC 太久没有反馈。 */
|
|
1856
|
+
var BATCH_CHUNK = 20;
|
|
1857
|
+
|
|
1858
|
+
/**
|
|
1859
|
+
* 等 contextMenus 服务就绪的宽限期(毫秒)。Cordis 的 inject 只有「必须」语义,
|
|
1860
|
+
* 没有可选依赖:老宿主永远不会提供这个服务,等下去就等于「会话菜单里没有删除项」。
|
|
1861
|
+
* 所以超时就认为没有该服务,退回到旧的 slot 渲染。
|
|
1862
|
+
*/
|
|
1863
|
+
var MENU_FALLBACK = { ms: 1200 };
|
|
1864
|
+
|
|
1865
|
+
/** 菜单图标键:注册到宿主的 contextMenu.icon keyed slot 上。 */
|
|
1866
|
+
var TRASH_ICON = "session-delete.trash";
|
|
1867
|
+
|
|
1868
|
+
/** 快捷键命令 id:菜单行的 commandId 必须与它一致,键位提示才会显示。 */
|
|
1869
|
+
var COMMAND_DELETE = "session.delete";
|
|
1870
|
+
var COMMAND_DELETE_WORKSPACE = "session.deleteWorkspace";
|
|
1871
|
+
|
|
1445
1872
|
exports.inject = ["slots", "locale", "connection"];
|
|
1446
1873
|
exports.apply = function apply(/** @type {any} */ ctx) {
|
|
1447
1874
|
ctx.effect(() => ctx.locale.register(NS, { zh: zh, en: en }), "session-delete: dictionaries");
|
|
1448
1875
|
|
|
1876
|
+
/** @type {(key: string, values?: any) => string} */
|
|
1877
|
+
var translate;
|
|
1878
|
+
var fallbackTranslate = (/** @type {string} */ key) =>
|
|
1879
|
+
/** @type {Record<string, string>} */ (zh)[key] || key;
|
|
1880
|
+
try {
|
|
1881
|
+
translate =
|
|
1882
|
+
ctx.locale && typeof ctx.locale.bind === "function"
|
|
1883
|
+
? ctx.locale.bind(NS)
|
|
1884
|
+
: fallbackTranslate;
|
|
1885
|
+
} catch (_error) {
|
|
1886
|
+
translate = fallbackTranslate;
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1449
1889
|
// 用真实的 :hover / :focus-visible 伪类,避免依赖 React 合成事件与内联样式。
|
|
1890
|
+
// 原则:控件外观只调宿主 token;行高与间距对齐设置页(16px 竖向留白、.5px 分隔线)。
|
|
1450
1891
|
ctx.effect(() => {
|
|
1451
1892
|
const style = document.createElement("style");
|
|
1452
1893
|
// 标注归属:便于在 DevTools 里认出这段样式、也方便测试断言插件确实加载了。
|
|
1453
1894
|
style.setAttribute("data-plugin", "@kangyishuai/dsh-session-delete");
|
|
1454
1895
|
style.textContent = [
|
|
1455
|
-
".dsh-sdel-btn{background:transparent;color:var(--dsw-alias-label-primary,inherit);border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));transition:background-color 150ms ease,border-color 150ms ease,transform 80ms ease,color 150ms ease;}",
|
|
1456
|
-
".dsh-sdel-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.16));}",
|
|
1457
|
-
".dsh-sdel-btn:active{transform:scale(.98);}",
|
|
1896
|
+
".dsh-sdel-btn{background:transparent;color:var(--dsw-alias-label-primary,inherit);border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));transition:background-color 150ms ease,border-color 150ms ease,transform 80ms ease,color 150ms ease;white-space:nowrap;}",
|
|
1897
|
+
".dsh-sdel-btn:hover:enabled{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.16));}",
|
|
1898
|
+
".dsh-sdel-btn:active:enabled{transform:scale(.98);}",
|
|
1458
1899
|
".dsh-sdel-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f7cff);outline-offset:1px;}",
|
|
1459
1900
|
".dsh-sdel-btn--danger{color:var(--dsw-alias-state-error-primary,#d9534f);}",
|
|
1460
|
-
".dsh-sdel-btn--danger:hover{background:var(--dsw-alias-interactive-bg-hover-danger,rgba(217,83,79,.16));}",
|
|
1901
|
+
".dsh-sdel-btn--danger:hover:enabled{background:var(--dsw-alias-interactive-bg-hover-danger,rgba(217,83,79,.16));}",
|
|
1902
|
+
".dsh-sdel-btn--quiet{border-color:transparent;}",
|
|
1903
|
+
".dsh-sdel-btn--tight{padding:2px 8px;border-radius:6px;font-size:12px;}",
|
|
1461
1904
|
".dsh-sdel-footer{background:transparent;color:var(--dsw-alias-label-secondary,GrayText);border:1px solid transparent;border-radius:8px;transition:background-color 150ms ease,color 150ms ease;}",
|
|
1462
1905
|
".dsh-sdel-footer:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.16));color:var(--dsw-alias-label-primary,inherit);}",
|
|
1463
1906
|
".dsh-sdel-footer:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f7cff);outline-offset:1px;}",
|
|
1907
|
+
".dsh-sdel-truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;}",
|
|
1908
|
+
".dsh-sdel-panel{display:flex;flex-direction:column;gap:8px;min-height:0;}",
|
|
1909
|
+
".dsh-sdel-toolbar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;}",
|
|
1910
|
+
".dsh-sdel-list{max-height:min(56vh,520px);overflow-y:auto;border-top:.5px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));}",
|
|
1911
|
+
".dsh-sdel-row{display:flex;align-items:center;gap:10px;padding:7px 0;border-bottom:.5px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));min-width:0;}",
|
|
1912
|
+
".dsh-sdel-row:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.08));}",
|
|
1913
|
+
".dsh-sdel-row-text{display:flex;flex-direction:column;gap:1px;flex:1 1 auto;min-width:0;}",
|
|
1914
|
+
".dsh-sdel-row-title{font-size:13px;line-height:18px;min-width:0;}",
|
|
1915
|
+
".dsh-sdel-row-meta{color:var(--dsw-alias-label-tertiary,GrayText);font-size:11px;line-height:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}",
|
|
1916
|
+
".dsh-sdel-row-actions{display:flex;gap:6px;flex:none;opacity:0;transition:opacity 120ms ease;}",
|
|
1917
|
+
".dsh-sdel-row:hover .dsh-sdel-row-actions,.dsh-sdel-row:focus-within .dsh-sdel-row-actions,.dsh-sdel-row-actions--open{opacity:1;}",
|
|
1918
|
+
".dsh-sdel-batch{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--dsw-alias-label-secondary,GrayText);}",
|
|
1919
|
+
".dsh-sdel-confirm{display:flex;align-items:center;gap:8px;padding:6px 8px;border-radius:8px;background:var(--dsw-alias-interactive-bg-hover-danger,rgba(217,83,79,.12));font-size:12px;color:var(--dsw-alias-state-error-primary,#d9534f);}",
|
|
1920
|
+
".dsh-sdel-disclosure{display:flex;align-items:center;gap:6px;background:transparent;border:none;padding:2px 0;cursor:pointer;color:var(--dsw-alias-label-secondary,GrayText);font-size:12px;font-family:inherit;}",
|
|
1921
|
+
".dsh-sdel-disclosure:hover{color:var(--dsw-alias-label-primary,inherit);}",
|
|
1922
|
+
".dsh-sdel-disclosure:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f7cff);outline-offset:2px;border-radius:4px;}",
|
|
1923
|
+
".dsh-sdel-disclosure-meta{margin-left:auto;color:var(--dsw-alias-label-tertiary,GrayText);}",
|
|
1924
|
+
".dsh-sdel-settings{display:flex;flex-direction:column;width:100%;}",
|
|
1925
|
+
".dsh-sdel-group{color:var(--dsw-alias-label-secondary,GrayText);font-size:12px;font-weight:600;padding:20px 0 4px;}",
|
|
1926
|
+
".dsh-sdel-setting-row{display:flex;align-items:center;justify-content:space-between;gap:24px;padding:16px 0;border-bottom:.5px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));}",
|
|
1927
|
+
".dsh-sdel-setting-row--stack{display:block;}",
|
|
1928
|
+
".dsh-sdel-setting-text{min-width:0;flex:1;}",
|
|
1929
|
+
".dsh-sdel-setting-title{color:var(--dsw-alias-label-primary,inherit);font-size:14px;line-height:22px;}",
|
|
1930
|
+
".dsh-sdel-setting-desc{color:var(--dsw-alias-label-tertiary,GrayText);font-size:12px;line-height:18px;margin-top:4px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}",
|
|
1931
|
+
".dsh-sdel-setting-action{display:flex;align-items:center;gap:8px;flex:none;}",
|
|
1464
1932
|
].join("\n");
|
|
1465
1933
|
document.head.appendChild(style);
|
|
1466
1934
|
return () => style.remove();
|
|
@@ -1470,12 +1938,13 @@ window.__ModuleLoader__.load({
|
|
|
1470
1938
|
var panelStore = createStore(false);
|
|
1471
1939
|
var toastStore = createStore(null);
|
|
1472
1940
|
var tickStore = createStore(0);
|
|
1941
|
+
var prefsStore = createStore(null);
|
|
1473
1942
|
|
|
1474
1943
|
/**
|
|
1475
1944
|
* 调宿主 sessionDelete 的 Remote 方法。走 /api 的普通 RPC 通道:
|
|
1476
1945
|
* 无构建插件没有 typert 生成的客户端产物,不能用 ctx.reflect.get。
|
|
1477
1946
|
* @param {string} method
|
|
1478
|
-
* @param {any} request
|
|
1947
|
+
* @param {any} [request]
|
|
1479
1948
|
* @returns {Promise<any>}
|
|
1480
1949
|
*/
|
|
1481
1950
|
function call(method, request) {
|
|
@@ -1499,6 +1968,18 @@ window.__ModuleLoader__.load({
|
|
|
1499
1968
|
);
|
|
1500
1969
|
}
|
|
1501
1970
|
|
|
1971
|
+
/** 偏好只加载一次:确认框与设置页共享同一份快照。 */
|
|
1972
|
+
var loadPrefs = () => {
|
|
1973
|
+
call("getPrefs")
|
|
1974
|
+
.then((/** @type {any} */ value) => {
|
|
1975
|
+
prefsStore.set(value || { cascadeChildren: false });
|
|
1976
|
+
})
|
|
1977
|
+
.catch(() => {
|
|
1978
|
+
prefsStore.set({ cascadeChildren: false });
|
|
1979
|
+
});
|
|
1980
|
+
};
|
|
1981
|
+
loadPrefs();
|
|
1982
|
+
|
|
1502
1983
|
// 宿主列表 = persistence ∪ live:刷新会把宿主内存里还没释放的会话折回来。
|
|
1503
1984
|
// 所以删掉的 id 要记住,并在每次 refresh 后重放移除事件(参考实现同款做法)。
|
|
1504
1985
|
const retired = new Set();
|
|
@@ -1544,6 +2025,66 @@ window.__ModuleLoader__.load({
|
|
|
1544
2025
|
void refreshRows(result?.sessionId ? result.sessionId : undefined);
|
|
1545
2026
|
tickStore.set(tickStore.getSnapshot() + 1);
|
|
1546
2027
|
};
|
|
2028
|
+
/**
|
|
2029
|
+
* 工作区批量的收尾:逐条结果汇总成一句 toast,并把删掉的 id 记进 retired,
|
|
2030
|
+
* 让下一次 refreshRows 重放移除事件(否则刷新会把 live 会话折回来)。
|
|
2031
|
+
* @param {any} result
|
|
2032
|
+
*/
|
|
2033
|
+
const onTrashedMany = (result) => {
|
|
2034
|
+
var ok = 0;
|
|
2035
|
+
var total = 0;
|
|
2036
|
+
if (result && Array.isArray(result.results)) {
|
|
2037
|
+
total = result.results.length;
|
|
2038
|
+
for (let index = 0; index < total; index += 1) {
|
|
2039
|
+
const item = result.results[index];
|
|
2040
|
+
if (!item.ok) continue;
|
|
2041
|
+
ok += 1;
|
|
2042
|
+
if (item.sessionId) retired.add(String(item.sessionId));
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
toastStore.set({ text: translate("toast.workspace.done", { ok: ok, total: total }) });
|
|
2046
|
+
void refreshRows(undefined);
|
|
2047
|
+
tickStore.set(tickStore.getSnapshot() + 1);
|
|
2048
|
+
};
|
|
2049
|
+
|
|
2050
|
+
/** 当前会话(主视图持有的那一条)。快捷键的语义就是「这个会话」。 */
|
|
2051
|
+
const currentSession = () => {
|
|
2052
|
+
try {
|
|
2053
|
+
const sessions = ctx.get ? ctx.get("sessions") : undefined;
|
|
2054
|
+
const list = sessions?.list?.getSnapshot?.();
|
|
2055
|
+
if (!list?.byId) return undefined;
|
|
2056
|
+
const ids = Array.isArray(list.ids) ? list.ids : Object.keys(list.byId);
|
|
2057
|
+
for (let index = 0; index < ids.length; index += 1) {
|
|
2058
|
+
const row = list.byId[ids[index]];
|
|
2059
|
+
if ((row?.retainedBy?.mainView ?? 0) > 0) return row;
|
|
2060
|
+
}
|
|
2061
|
+
} catch (_error) {
|
|
2062
|
+
return undefined;
|
|
2063
|
+
}
|
|
2064
|
+
return undefined;
|
|
2065
|
+
};
|
|
2066
|
+
|
|
2067
|
+
/** 当前会话所属的工作区(工作区记账里包含它,或路径与它的 cwd 相同)。 */
|
|
2068
|
+
const currentWorkspace = () => {
|
|
2069
|
+
var row = currentSession();
|
|
2070
|
+
if (!row) return undefined;
|
|
2071
|
+
try {
|
|
2072
|
+
const workspaces = ctx.get ? ctx.get("workspaces") : undefined;
|
|
2073
|
+
const snapshot = workspaces?.list?.getSnapshot?.();
|
|
2074
|
+
const items = snapshot?.items || [];
|
|
2075
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
2076
|
+
const item = items[index];
|
|
2077
|
+
if (Array.isArray(item.sessionIds) && item.sessionIds.includes(row.id)) return item;
|
|
2078
|
+
}
|
|
2079
|
+
for (let cursor = 0; cursor < items.length; cursor += 1) {
|
|
2080
|
+
if (typeof row.cwd === "string" && items[cursor].path === row.cwd) return items[cursor];
|
|
2081
|
+
}
|
|
2082
|
+
} catch (_error) {
|
|
2083
|
+
return undefined;
|
|
2084
|
+
}
|
|
2085
|
+
return undefined;
|
|
2086
|
+
};
|
|
2087
|
+
|
|
1547
2088
|
// 外部变更(agent 工具、另一个窗口、CLI)不会通知本页面,
|
|
1548
2089
|
// 定期拉一次会话列表;页面重新可见时也立刻拉一次。
|
|
1549
2090
|
ctx.effect(() => {
|
|
@@ -1570,26 +2111,223 @@ window.__ModuleLoader__.load({
|
|
|
1570
2111
|
void refreshRows(undefined);
|
|
1571
2112
|
};
|
|
1572
2113
|
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
2114
|
+
/**
|
|
2115
|
+
* 菜单:优先走官方的 contextMenus 贡献。
|
|
2116
|
+
* 好处有三点:能参与官方排序(不再是「兼容位置」的附加行)、能显示快捷键、
|
|
2117
|
+
* 工作区「…」菜单也有正式入口。拿不到服务(老宿主)时退回旧 slot,功能不减。
|
|
2118
|
+
*/
|
|
2119
|
+
const openSessionConfirm = (/** @type {any} */ sessionId, /** @type {any} */ title) => {
|
|
2120
|
+
requestStore.set({ sessionId: sessionId, title: title || null });
|
|
2121
|
+
};
|
|
2122
|
+
const openWorkspaceConfirm = (/** @type {any} */ workspaceId, /** @type {any} */ title) => {
|
|
2123
|
+
requestStore.set({ workspaceId: String(workspaceId), title: title || null });
|
|
2124
|
+
};
|
|
2125
|
+
|
|
2126
|
+
/** @param {any} contextMenus */
|
|
2127
|
+
const installMenuContributions = (contextMenus) => {
|
|
2128
|
+
if (!contextMenus || typeof contextMenus.register !== "function") return false;
|
|
2129
|
+
try {
|
|
2130
|
+
ctx.effect(
|
|
2131
|
+
() =>
|
|
2132
|
+
contextMenus.register({
|
|
2133
|
+
id: COMMAND_DELETE,
|
|
2134
|
+
target: "session",
|
|
2135
|
+
order: 560,
|
|
2136
|
+
resolve: (/** @type {any} */ target) => [
|
|
2137
|
+
{
|
|
2138
|
+
id: "delete",
|
|
2139
|
+
label: translate("menu.delete"),
|
|
2140
|
+
danger: true,
|
|
2141
|
+
separatorBefore: true,
|
|
2142
|
+
...(typeof IconTrash === "function" ? { icon: { key: TRASH_ICON } } : {}),
|
|
2143
|
+
commandId: COMMAND_DELETE,
|
|
2144
|
+
run: () => openSessionConfirm(target.sessionId, target.displayTitle),
|
|
1585
2145
|
},
|
|
1586
|
-
|
|
1587
|
-
},
|
|
1588
|
-
|
|
2146
|
+
],
|
|
2147
|
+
}),
|
|
2148
|
+
"session-delete: session menu action",
|
|
2149
|
+
);
|
|
2150
|
+
ctx.effect(
|
|
2151
|
+
() =>
|
|
2152
|
+
contextMenus.register({
|
|
2153
|
+
id: COMMAND_DELETE_WORKSPACE,
|
|
2154
|
+
target: "workspace",
|
|
2155
|
+
order: 250,
|
|
2156
|
+
resolve: (/** @type {any} */ target) => [
|
|
2157
|
+
{
|
|
2158
|
+
id: "delete-workspace-sessions",
|
|
2159
|
+
label: translate("menu.workspaceTrash"),
|
|
2160
|
+
danger: true,
|
|
2161
|
+
separatorBefore: true,
|
|
2162
|
+
...(typeof IconTrash === "function" ? { icon: { key: TRASH_ICON } } : {}),
|
|
2163
|
+
commandId: COMMAND_DELETE_WORKSPACE,
|
|
2164
|
+
run: () => openWorkspaceConfirm(target.workspaceId, target.displayTitle),
|
|
2165
|
+
},
|
|
2166
|
+
],
|
|
2167
|
+
}),
|
|
2168
|
+
"session-delete: workspace menu action",
|
|
2169
|
+
);
|
|
2170
|
+
if (typeof IconTrash === "function") {
|
|
2171
|
+
try {
|
|
2172
|
+
ctx.effect(
|
|
2173
|
+
() =>
|
|
2174
|
+
ctx.slots.inject("contextMenu.icon", () =>
|
|
2175
|
+
ctx.slots.register(
|
|
2176
|
+
{ name: "contextMenu.icon", key: TRASH_ICON },
|
|
2177
|
+
function TrashMenuIcon() {
|
|
2178
|
+
return h(IconTrash, { size: 14 });
|
|
2179
|
+
},
|
|
2180
|
+
),
|
|
2181
|
+
),
|
|
2182
|
+
"session-delete: menu icon",
|
|
2183
|
+
);
|
|
2184
|
+
} catch (_error) {
|
|
2185
|
+
/* 图标 slot 不存在时菜单仍然可用(宿主的 icon key 匹配不到就不画) */
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
return true;
|
|
2189
|
+
} catch (error) {
|
|
2190
|
+
ctx.logger?.warn?.(
|
|
2191
|
+
`session-delete: cannot register menu contributions: ${errorText(error)}`,
|
|
2192
|
+
);
|
|
2193
|
+
return false;
|
|
2194
|
+
}
|
|
2195
|
+
};
|
|
2196
|
+
|
|
2197
|
+
/** @returns {any} ctx.effect 的释放函数(contextMenus 迟到时用它撤掉旧 slot,避免两行)。 */
|
|
2198
|
+
const registerLegacyMenuItem = () =>
|
|
2199
|
+
ctx.effect(
|
|
2200
|
+
() =>
|
|
2201
|
+
ctx.slots.inject("sidebar.workspaces.session.menu.item", () =>
|
|
2202
|
+
ctx.slots.register(
|
|
2203
|
+
{
|
|
2204
|
+
name: "sidebar.workspaces.session.menu.item",
|
|
2205
|
+
id: "session-delete",
|
|
2206
|
+
order: 420,
|
|
2207
|
+
locale: NS,
|
|
2208
|
+
inject: () => ({
|
|
2209
|
+
requestDelete: (/** @type {any} */ request) => {
|
|
2210
|
+
requestStore.set(request);
|
|
2211
|
+
},
|
|
2212
|
+
}),
|
|
2213
|
+
},
|
|
2214
|
+
DeleteSessionMenuItem,
|
|
2215
|
+
),
|
|
1589
2216
|
),
|
|
1590
|
-
),
|
|
1591
|
-
|
|
1592
|
-
|
|
2217
|
+
"session-delete: session menu item (legacy slot)",
|
|
2218
|
+
);
|
|
2219
|
+
|
|
2220
|
+
/**
|
|
2221
|
+
* 快捷键:删除「当前会话」与「当前工作区的全部会话」。
|
|
2222
|
+
* 注册整体包 try/catch —— 与本机已有的自定义键位冲突时宿主会抛错,
|
|
2223
|
+
* 那种情况下只失去快捷键,菜单与确认框照常工作。
|
|
2224
|
+
*/
|
|
2225
|
+
/** @param {any} shortcuts */
|
|
2226
|
+
const installShortcuts = (shortcuts) => {
|
|
2227
|
+
if (!shortcuts || typeof shortcuts.register !== "function") return;
|
|
2228
|
+
const register = (/** @type {any} */ command) => {
|
|
2229
|
+
try {
|
|
2230
|
+
ctx.effect(() => shortcuts.register(command), `session-delete: shortcut ${command.id}`);
|
|
2231
|
+
} catch (error) {
|
|
2232
|
+
ctx.logger?.warn?.(
|
|
2233
|
+
`session-delete: shortcut ${command.id} unavailable: ${errorText(error)}`,
|
|
2234
|
+
);
|
|
2235
|
+
}
|
|
2236
|
+
};
|
|
2237
|
+
const busy = () =>
|
|
2238
|
+
requestStore.getSnapshot()
|
|
2239
|
+
? { status: "blocked", reason: translate("shortcut.busy") }
|
|
2240
|
+
: null;
|
|
2241
|
+
register({
|
|
2242
|
+
id: COMMAND_DELETE,
|
|
2243
|
+
label: () => translate("shortcut.delete"),
|
|
2244
|
+
aliases: ["delete session", "remove session", "删除会话"],
|
|
2245
|
+
// Linux(桌面与 Web)都不声明默认值:宿主把「修饰键 + Backspace」列为保留组合,
|
|
2246
|
+
// 声明了 register() 会抛错,整条快捷键就没了。用户在设置里可以自己绑。
|
|
2247
|
+
defaults: {
|
|
2248
|
+
"desktop:macos": { code: "Backspace", modifiers: ["primary", "alt"] },
|
|
2249
|
+
"desktop:windows": { code: "Backspace", modifiers: ["primary", "alt"] },
|
|
2250
|
+
"web:macos": { code: "Backspace", modifiers: ["primary", "alt"] },
|
|
2251
|
+
"web:windows": { code: "Backspace", modifiers: ["primary", "alt"] },
|
|
2252
|
+
},
|
|
2253
|
+
// 编辑区也放行:⌘⌥⌫ 不是 macOS/Windows 的文本编辑键(那些是 ⌘⌫ / ⌥⌫ / ⌘⌃⌫),
|
|
2254
|
+
// 而 composer 几乎总是持有焦点,只允许 page 会让快捷键实际上按不出来。
|
|
2255
|
+
// 终端排除在外:那里的删除键有更强的本地语义。
|
|
2256
|
+
regions: ["page", "editable"],
|
|
2257
|
+
modals: [],
|
|
2258
|
+
resolve: () => {
|
|
2259
|
+
const blockedNow = busy();
|
|
2260
|
+
if (blockedNow) return blockedNow;
|
|
2261
|
+
const row = currentSession();
|
|
2262
|
+
if (!row) return { status: "blocked", reason: translate("shortcut.noSession") };
|
|
2263
|
+
return {
|
|
2264
|
+
status: "handled",
|
|
2265
|
+
run: () => openSessionConfirm(row.id, row.displayTitle),
|
|
2266
|
+
};
|
|
2267
|
+
},
|
|
2268
|
+
});
|
|
2269
|
+
// 工作区级清空没有默认键位:误触代价太大,键位留给用户在设置里自己绑。
|
|
2270
|
+
register({
|
|
2271
|
+
id: COMMAND_DELETE_WORKSPACE,
|
|
2272
|
+
label: () => translate("shortcut.workspace"),
|
|
2273
|
+
aliases: ["delete workspace sessions", "清空工作区会话"],
|
|
2274
|
+
defaults: {},
|
|
2275
|
+
regions: ["page"],
|
|
2276
|
+
modals: [],
|
|
2277
|
+
resolve: () => {
|
|
2278
|
+
const blockedNow = busy();
|
|
2279
|
+
if (blockedNow) return blockedNow;
|
|
2280
|
+
const workspace = currentWorkspace();
|
|
2281
|
+
if (!workspace) return { status: "blocked", reason: translate("shortcut.noSession") };
|
|
2282
|
+
return {
|
|
2283
|
+
status: "handled",
|
|
2284
|
+
run: () => openWorkspaceConfirm(workspace.workspaceId, workspace.title),
|
|
2285
|
+
};
|
|
2286
|
+
},
|
|
2287
|
+
});
|
|
2288
|
+
};
|
|
2289
|
+
|
|
2290
|
+
// 两个服务都可能比插件晚就绪:用 ctx.inject 延迟,缺任何一个都不影响插件本身加载。
|
|
2291
|
+
// ctx.inject 只有「必须」语义,所以再加一个宽限期兜底:超时就认定宿主没有
|
|
2292
|
+
// contextMenus,直接上旧的会话菜单 slot(否则老宿主上「删除会话」入口会整个消失)。
|
|
2293
|
+
let menusInstalled = false;
|
|
2294
|
+
/** @type {any} */
|
|
2295
|
+
let legacyDispose = null;
|
|
2296
|
+
const ensureLegacyMenu = () => {
|
|
2297
|
+
if (menusInstalled || legacyDispose) return;
|
|
2298
|
+
legacyDispose = registerLegacyMenuItem();
|
|
2299
|
+
};
|
|
2300
|
+
try {
|
|
2301
|
+
if (typeof ctx.inject === "function") {
|
|
2302
|
+
ctx.inject(["contextMenus"], (/** @type {any} */ scoped) => {
|
|
2303
|
+
const service = scoped?.contextMenus ?? (ctx.get ? ctx.get("contextMenus") : undefined);
|
|
2304
|
+
if (installMenuContributions(service)) {
|
|
2305
|
+
menusInstalled = true;
|
|
2306
|
+
if (legacyDispose) {
|
|
2307
|
+
legacyDispose();
|
|
2308
|
+
legacyDispose = null;
|
|
2309
|
+
}
|
|
2310
|
+
} else {
|
|
2311
|
+
ensureLegacyMenu();
|
|
2312
|
+
}
|
|
2313
|
+
});
|
|
2314
|
+
ctx.inject(["shortcuts"], (/** @type {any} */ scoped) => {
|
|
2315
|
+
installShortcuts(scoped?.shortcuts ?? (ctx.get ? ctx.get("shortcuts") : undefined));
|
|
2316
|
+
});
|
|
2317
|
+
const timer = setTimeout(ensureLegacyMenu, MENU_FALLBACK.ms);
|
|
2318
|
+
ctx.effect(() => () => clearTimeout(timer), "session-delete: menu fallback timer");
|
|
2319
|
+
} else {
|
|
2320
|
+
const menus = ctx.get ? ctx.get("contextMenus") : undefined;
|
|
2321
|
+
if (installMenuContributions(menus)) menusInstalled = true;
|
|
2322
|
+
else ensureLegacyMenu();
|
|
2323
|
+
installShortcuts(ctx.get ? ctx.get("shortcuts") : undefined);
|
|
2324
|
+
}
|
|
2325
|
+
} catch (error) {
|
|
2326
|
+
ctx.logger?.warn?.(
|
|
2327
|
+
`session-delete: menu/shortcut setup failed, falling back: ${errorText(error)}`,
|
|
2328
|
+
);
|
|
2329
|
+
ensureLegacyMenu();
|
|
2330
|
+
}
|
|
1593
2331
|
|
|
1594
2332
|
// 回收站入口固定在侧栏页脚,不出现在每个会话的「…」菜单里。
|
|
1595
2333
|
ctx.effect(
|
|
@@ -1616,6 +2354,34 @@ window.__ModuleLoader__.load({
|
|
|
1616
2354
|
"session-delete: sidebar footer trash entry",
|
|
1617
2355
|
);
|
|
1618
2356
|
|
|
2357
|
+
// 设置页分节:偏好 + 回收站概览 + 维护(体检/回执/审计)。
|
|
2358
|
+
// 宿主没有 settings.section 的版本会静默跳过,不影响主流程。
|
|
2359
|
+
try {
|
|
2360
|
+
ctx.effect(
|
|
2361
|
+
() =>
|
|
2362
|
+
ctx.slots.inject("settings.section", () =>
|
|
2363
|
+
ctx.slots.register(
|
|
2364
|
+
{
|
|
2365
|
+
name: "settings.section",
|
|
2366
|
+
id: "session-delete",
|
|
2367
|
+
order: 90,
|
|
2368
|
+
label: () => translate("settings.nav"),
|
|
2369
|
+
locale: NS,
|
|
2370
|
+
inject: () => ({
|
|
2371
|
+
prefsStore: prefsStore,
|
|
2372
|
+
panelStore: panelStore,
|
|
2373
|
+
call: call,
|
|
2374
|
+
}),
|
|
2375
|
+
},
|
|
2376
|
+
SettingsSection,
|
|
2377
|
+
),
|
|
2378
|
+
),
|
|
2379
|
+
"session-delete: settings section",
|
|
2380
|
+
);
|
|
2381
|
+
} catch (error) {
|
|
2382
|
+
ctx.logger?.warn?.(`session-delete: settings section unavailable: ${errorText(error)}`);
|
|
2383
|
+
}
|
|
2384
|
+
|
|
1619
2385
|
ctx.effect(
|
|
1620
2386
|
() =>
|
|
1621
2387
|
ctx.slots.inject("shell.overlay", () =>
|
|
@@ -1627,9 +2393,11 @@ window.__ModuleLoader__.load({
|
|
|
1627
2393
|
Object.assign({}, props, {
|
|
1628
2394
|
requestStore: requestStore,
|
|
1629
2395
|
panelStore: panelStore,
|
|
2396
|
+
prefsStore: prefsStore,
|
|
1630
2397
|
toastStore: toastStore,
|
|
1631
2398
|
call: call,
|
|
1632
2399
|
onTrashed: onTrashed,
|
|
2400
|
+
onTrashedMany: onTrashedMany,
|
|
1633
2401
|
onPurged: onPurged,
|
|
1634
2402
|
onRestored: onRestored,
|
|
1635
2403
|
tickStore: tickStore,
|
|
@@ -1643,6 +2411,24 @@ window.__ModuleLoader__.load({
|
|
|
1643
2411
|
);
|
|
1644
2412
|
};
|
|
1645
2413
|
|
|
2414
|
+
// 供 node:vm 单测读取的内部出口(非枚举,不影响运行时)。
|
|
2415
|
+
Object.defineProperty(exports, "__test", {
|
|
2416
|
+
value: Object.freeze({
|
|
2417
|
+
tokens: T,
|
|
2418
|
+
chunk: chunk,
|
|
2419
|
+
joinList: joinList,
|
|
2420
|
+
impactLine: impactLine,
|
|
2421
|
+
batchChunk: BATCH_CHUNK,
|
|
2422
|
+
menuFallback: MENU_FALLBACK,
|
|
2423
|
+
createPanelLoader: createPanelLoader,
|
|
2424
|
+
runBatch: runBatch,
|
|
2425
|
+
panelPollMs: PANEL_POLL_MS,
|
|
2426
|
+
// 词典也暴露出来:单测要比对「内联词典 / locale/*.json」的键集,防止两处漂移。
|
|
2427
|
+
zh: zh,
|
|
2428
|
+
en: en,
|
|
2429
|
+
}),
|
|
2430
|
+
});
|
|
2431
|
+
|
|
1646
2432
|
return module.exports;
|
|
1647
2433
|
},
|
|
1648
2434
|
});
|