@wangyf397/session_del 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/client.js +155 -252
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ DSH 自带的能力只有「归档」:归档只是把会话从侧栏隐藏,
|
|
|
7
7
|
|
|
8
8
|
| 入口 | 用法 |
|
|
9
9
|
|---|---|
|
|
10
|
-
| 侧栏菜单 | 会话行「…」→ **彻底删除会话** →
|
|
10
|
+
| 侧栏菜单 | 会话行「…」→ **彻底删除会话** → 再点一次确认 → 删除 |
|
|
11
11
|
| 人类命令 | `/session-del list`、`/session-del delete <会话ID…>` |
|
|
12
12
|
| Agent 工具 | `session_del({ action: "list" })`、`session_del({ action: "delete", session_ids: [...] })` |
|
|
13
13
|
|
|
@@ -54,8 +54,11 @@ dsh plugin --profile web add link:/Users/wangyf/code/dsh-plugins/session_del
|
|
|
54
54
|
- 删除通过 `ctx.remote.commands.execute(sessionId, "/session-del delete …")` 落到 Host,
|
|
55
55
|
因此需要一个**当前打开的会话**作为命令的执行者(正在看的那个会话本身删不掉)。
|
|
56
56
|
命令会在当前会话里留下两条 log-only 的 `command/run`、`command/done` 记录,便于审计。
|
|
57
|
-
-
|
|
58
|
-
|
|
57
|
+
- 侧栏菜单采用「点两下 + 行内反馈」:第一下变成「再点一次,彻底删除」,第二下执行,
|
|
58
|
+
成功/失败信息都显示在那一行里(不弹窗、不写全局 DOM/样式)。
|
|
59
|
+
- 侧栏列表由客户端会话列表驱动:删除成功后该行要刷新页面才会消失;磁盘与索引在删除当刻就干净了。
|
|
60
|
+
- 工作区注册表里那条会话的排序占位 id 没有公开删除 API:显示时已被过滤,下次该工作区有任何变更时
|
|
61
|
+
会连带清掉。
|
|
59
62
|
|
|
60
63
|
## 发布
|
|
61
64
|
|
package/client.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* session_del — Client half.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* 由 Host 端执行真正的删除(会话日志 + 投影缓存 + 归档/置顶记录)。
|
|
4
|
+
* 在侧栏每个会话的「…」菜单里加一行「彻底删除会话」。点一下变成确认态,
|
|
5
|
+
* 再点一下才真正执行;执行结果(成功 / Host 拒绝的原因)直接显示在这一行里。
|
|
7
6
|
*
|
|
8
|
-
*
|
|
7
|
+
* 删除动作通过 ctx.remote.commands.execute(sessionId, "/session-del delete <id>")
|
|
8
|
+
* 交给 Host 的 /session-del 命令完成——UI 与 Agent 工具共用同一套操作。
|
|
9
|
+
*
|
|
10
|
+
* 本组件只依赖 React 和运行时服务的惰性读取(与本 profile 里可用的
|
|
11
|
+
* thinking-dial 插件同一套写法),不依赖 slot 提供的 hook、不写全局 DOM/样式,
|
|
12
|
+
* 把出错面压到最小。任何缺服务/缺会话都会在行内显示原因,而不是静默失败。
|
|
9
13
|
*
|
|
10
14
|
* @module @wangyf397/session_del/client
|
|
11
15
|
*/
|
|
@@ -19,85 +23,57 @@ window.__ModuleLoader__.load({
|
|
|
19
23
|
/** 运行时 locale 命名空间(同时用于插件元数据)。 */
|
|
20
24
|
const NS = 'session_del'
|
|
21
25
|
|
|
22
|
-
/** 仅本插件使用的全局样式(随 shell.overlay 入口长期挂载)。 */
|
|
23
|
-
const CSS = `
|
|
24
|
-
.sd-menu-item{display:flex;align-items:center;gap:8px;box-sizing:border-box;width:100%;height:28px;padding:0 8px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-primary);font-family:inherit;font-size:13px;font-weight:400;line-height:18px;text-align:left;cursor:pointer}
|
|
25
|
-
.sd-menu-item:hover{background:color-mix(in srgb,var(--dsw-alias-label-primary) 8%,transparent)}
|
|
26
|
-
.sd-menu-item:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-alias-brand-primary);outline-offset:-2px}
|
|
27
|
-
.sd-menu-item-icon{display:inline-flex;flex:none;width:14px;height:14px;color:var(--dsw-alias-state-error-primary)}
|
|
28
|
-
.sd-dialog{box-sizing:border-box;width:min(460px,calc(100vw - 40px));margin:auto;padding:0;border:0;border-radius:12px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font-family:inherit;box-shadow:0 16px 48px rgba(0,0,0,.35);pointer-events:auto}
|
|
29
|
-
.sd-dialog::backdrop{background:rgba(0,0,0,.42);pointer-events:auto}
|
|
30
|
-
.sd-dialog-body{display:flex;flex-direction:column;gap:10px;padding:18px 20px 4px}
|
|
31
|
-
.sd-dialog-title{font-size:15px;font-weight:600;line-height:22px}
|
|
32
|
-
.sd-dialog-desc{margin:0;font-size:13px;line-height:20px;color:var(--dsw-alias-label-primary);overflow-wrap:anywhere}
|
|
33
|
-
.sd-dialog-note{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
|
|
34
|
-
.sd-dialog-status{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
|
|
35
|
-
.sd-dialog-result{margin:0;max-height:180px;overflow:auto;font-family:inherit;font-size:12px;line-height:18px;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
36
|
-
.sd-dialog-result.sd-err{color:var(--dsw-alias-state-error-primary)}
|
|
37
|
-
.sd-dialog-result.sd-ok{color:var(--dsw-alias-state-success-primary)}
|
|
38
|
-
.sd-dialog-footer{display:flex;justify-content:flex-end;gap:8px;padding:14px 20px 18px}
|
|
39
|
-
.sd-btn{height:28px;padding:0 12px;border:.5px solid var(--dsw-alias-border-l2);border-radius:6px;background:transparent;color:var(--dsw-alias-label-primary);font-family:inherit;font-size:13px;line-height:18px;cursor:pointer}
|
|
40
|
-
.sd-btn:hover:not(:disabled){background:color-mix(in srgb,var(--dsw-alias-label-primary) 8%,transparent)}
|
|
41
|
-
.sd-btn:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-alias-brand-primary);outline-offset:2px}
|
|
42
|
-
.sd-btn:disabled{opacity:.5;cursor:default}
|
|
43
|
-
.sd-btn.sd-danger:not(:disabled){color:var(--dsw-alias-state-error-primary);border-color:var(--dsw-alias-state-error-primary)}
|
|
44
|
-
`
|
|
45
|
-
|
|
46
26
|
/** 中英文案。 */
|
|
47
27
|
const zh = {
|
|
48
|
-
'menu.delete': '
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
'
|
|
56
|
-
'done': '完成',
|
|
57
|
-
'error.noRunner': '没有可用的会话来执行删除。请先打开任意一个会话,再回来重试。',
|
|
58
|
-
'error.noRemote': '当前界面无法连接 Host(ctx.remote.commands 不可用)。',
|
|
59
|
-
'error.unknownCommand': 'Host 上没有 /session-del 命令:插件可能未生效,或 Host 版本不匹配。',
|
|
60
|
-
'error.current': '这是当前正在查看的会话,无法删除。请先切到别的会话。',
|
|
28
|
+
'menu.delete': '彻底删除会话(不可恢复)',
|
|
29
|
+
'menu.confirm': '再点一次,彻底删除',
|
|
30
|
+
'menu.busy': '正在删除…',
|
|
31
|
+
'menu.done': '已彻底删除',
|
|
32
|
+
'menu.failed': '删除失败:{reason}',
|
|
33
|
+
'error.noRunner': '没有可执行删除的会话,请先打开任意会话',
|
|
34
|
+
'error.noRemote': '无法连接 Host(ctx.remote.commands 不可用)',
|
|
35
|
+
'error.unknownCommand': 'Host 上没有 /session-del 命令(插件未生效?)',
|
|
61
36
|
}
|
|
62
37
|
|
|
63
38
|
const en = {
|
|
64
39
|
'menu.delete': 'Delete session permanently',
|
|
65
|
-
'
|
|
66
|
-
'
|
|
67
|
-
'
|
|
68
|
-
'
|
|
69
|
-
'
|
|
70
|
-
'
|
|
71
|
-
'
|
|
72
|
-
'done': 'Done',
|
|
73
|
-
'error.noRunner': 'No session is available to run the deletion. Open any session and try again.',
|
|
74
|
-
'error.noRemote': 'This page cannot reach the Host (ctx.remote.commands is unavailable).',
|
|
75
|
-
'error.unknownCommand': 'The Host has no /session-del command: the plugin may not be active, or the Host version does not match.',
|
|
76
|
-
'error.current': 'This is the session you are viewing; it cannot be deleted. Switch to another session first.',
|
|
40
|
+
'menu.confirm': 'Click again to delete permanently',
|
|
41
|
+
'menu.busy': 'Deleting…',
|
|
42
|
+
'menu.done': 'Deleted permanently',
|
|
43
|
+
'menu.failed': 'Delete failed: {reason}',
|
|
44
|
+
'error.noRunner': 'No session available to run the deletion; open any session first',
|
|
45
|
+
'error.noRemote': 'Cannot reach the Host (ctx.remote.commands is unavailable)',
|
|
46
|
+
'error.unknownCommand': 'The Host has no /session-del command (is the plugin active?)',
|
|
77
47
|
}
|
|
78
48
|
|
|
79
|
-
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
49
|
+
/** 当前 client 上下文(惰性读取服务,与 provider 顺序无关)。 */
|
|
50
|
+
let pluginCtx
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 从一个 Cordis 上下文里读服务,服务尚未提供时返回 undefined 而不抛错。
|
|
54
|
+
* @param {object|undefined} host 上下文,apply 之前为 undefined。
|
|
55
|
+
* @param {string} name 服务名。
|
|
56
|
+
* @returns {*} 服务实例或 undefined。
|
|
57
|
+
*/
|
|
58
|
+
function readService(host, name) {
|
|
59
|
+
if (host === undefined || host === null) return undefined
|
|
60
|
+
try {
|
|
61
|
+
const viaGet = host.get(name)
|
|
62
|
+
if (viaGet !== undefined) return viaGet
|
|
63
|
+
} catch {
|
|
64
|
+
/* 走属性形式 */
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
return host[name]
|
|
68
|
+
} catch {
|
|
69
|
+
return undefined
|
|
95
70
|
}
|
|
96
71
|
}
|
|
97
72
|
|
|
98
|
-
/** 当前主视图里的会话 id
|
|
99
|
-
function mainViewSessionId(
|
|
100
|
-
const byId =
|
|
73
|
+
/** 当前主视图里的会话 id:命令需要一个 agent 作为执行者。 */
|
|
74
|
+
function mainViewSessionId(sessions, excludeId) {
|
|
75
|
+
const byId = sessions?.list?.getSnapshot?.()?.byId
|
|
76
|
+
if (!byId) return undefined
|
|
101
77
|
for (const row of Object.values(byId)) {
|
|
102
78
|
if (!row || String(row.id) === String(excludeId)) continue
|
|
103
79
|
if ((row.retainedBy?.mainView ?? 0) > 0) return String(row.id)
|
|
@@ -127,197 +103,141 @@ window.__ModuleLoader__.load({
|
|
|
127
103
|
}
|
|
128
104
|
|
|
129
105
|
/**
|
|
130
|
-
*
|
|
131
|
-
* @param {object}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const { sessionId, displayTitle, useMenuOpenState, useSessions, requestDelete, t } = props
|
|
135
|
-
const [, setMenuOpen] = useMenuOpenState()
|
|
136
|
-
const sessionState = useSessions((state) => state)
|
|
137
|
-
return h(
|
|
138
|
-
'button',
|
|
139
|
-
{
|
|
140
|
-
type: 'button',
|
|
141
|
-
role: 'menuitem',
|
|
142
|
-
className: 'sd-menu-item',
|
|
143
|
-
onClick: () => {
|
|
144
|
-
setMenuOpen(false)
|
|
145
|
-
requestDelete({
|
|
146
|
-
sessionId: String(sessionId),
|
|
147
|
-
displayTitle: displayTitle || undefined,
|
|
148
|
-
runnerSessionId: mainViewSessionId(sessionState, sessionId),
|
|
149
|
-
})
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
h('span', { className: 'sd-menu-item-icon', key: 'icon' }, TrashIcon()),
|
|
153
|
-
h('span', { key: 'label' }, t('menu.delete'))
|
|
154
|
-
)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* shell.overlay 入口:全局样式 + 有请求时的确认框。
|
|
159
|
-
* @param {object} props usePendingDelete / settleDelete / t
|
|
106
|
+
* 从命令执行结果里取出要展示的文字。
|
|
107
|
+
* @param {object|undefined} result ctx.remote.commands.execute 的返回值
|
|
108
|
+
* @param {Function} t 翻译函数
|
|
109
|
+
* @returns {{ok: boolean, text: string}}
|
|
160
110
|
*/
|
|
161
|
-
function
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
key: `${request.sessionId}-${request.at}`,
|
|
171
|
-
request,
|
|
172
|
-
settleDelete,
|
|
173
|
-
t,
|
|
174
|
-
})
|
|
175
|
-
: null
|
|
176
|
-
)
|
|
111
|
+
function readResult(result, t) {
|
|
112
|
+
if (!result || result.ok !== true) {
|
|
113
|
+
const message = result?.error?.message ?? t('error.noRemote')
|
|
114
|
+
const code = result?.error?.code ? ` (${result.error.code})` : ''
|
|
115
|
+
return { ok: false, text: `${message}${code}` }
|
|
116
|
+
}
|
|
117
|
+
if (result.value === undefined) return { ok: false, text: t('error.unknownCommand') }
|
|
118
|
+
const execution = result.value.result ?? {}
|
|
119
|
+
return { ok: execution.kind === 'success', text: String(execution.text ?? '') }
|
|
177
120
|
}
|
|
178
121
|
|
|
179
122
|
/**
|
|
180
|
-
*
|
|
181
|
-
* @param {object} props
|
|
123
|
+
* 侧栏会话菜单里的一行:idle → confirm → busy → done/failed。
|
|
124
|
+
* @param {object} props sessionId / displayTitle / t
|
|
182
125
|
*/
|
|
183
|
-
function
|
|
184
|
-
const {
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
React.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
} else {
|
|
201
|
-
dialog.setAttribute('open', '')
|
|
202
|
-
}
|
|
203
|
-
return () => {
|
|
204
|
-
if (dialog.open) dialog.close()
|
|
205
|
-
}
|
|
206
|
-
}, [])
|
|
207
|
-
|
|
208
|
-
const close = () => {
|
|
209
|
-
if (busy) return
|
|
210
|
-
settleDelete()
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const confirm = async () => {
|
|
214
|
-
if (busy) return
|
|
215
|
-
if (!request.runnerSessionId) {
|
|
216
|
-
setOutcome({ kind: 'error', text: t('error.noRunner') })
|
|
126
|
+
function DeleteMenuItem(props) {
|
|
127
|
+
const { sessionId, displayTitle, t } = props
|
|
128
|
+
const id = String(sessionId ?? '')
|
|
129
|
+
const tt = typeof t === 'function' ? t : (key, vars) => (vars ? `${key} ${JSON.stringify(vars)}` : key)
|
|
130
|
+
|
|
131
|
+
const [phase, setPhase] = React.useState('idle')
|
|
132
|
+
const [reason, setReason] = React.useState('')
|
|
133
|
+
const [hover, setHover] = React.useState(false)
|
|
134
|
+
const [focused, setFocused] = React.useState(false)
|
|
135
|
+
|
|
136
|
+
/** 执行删除(直接读已注入的 remote.commands 命名空间与 sessions 服务)。 */
|
|
137
|
+
const run = async () => {
|
|
138
|
+
const commands = readService(pluginCtx, 'remote.commands')
|
|
139
|
+
if (!commands || typeof commands.execute !== 'function') {
|
|
140
|
+
setPhase('failed')
|
|
141
|
+
setReason(tt('error.noRemote'))
|
|
217
142
|
return
|
|
218
143
|
}
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
144
|
+
const sessions = readService(pluginCtx, 'sessions')
|
|
145
|
+
const runner = mainViewSessionId(sessions, id)
|
|
146
|
+
if (!runner) {
|
|
147
|
+
setPhase('failed')
|
|
148
|
+
setReason(tt('error.noRunner'))
|
|
222
149
|
return
|
|
223
150
|
}
|
|
224
|
-
|
|
225
|
-
setOutcome(null)
|
|
151
|
+
setPhase('busy')
|
|
226
152
|
try {
|
|
227
|
-
const result = await
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (!result || result.ok !== true) {
|
|
233
|
-
const message = result?.error?.message ?? '调用 Host 失败'
|
|
234
|
-
const code = result?.error?.code ? ` (${result.error.code})` : ''
|
|
235
|
-
setOutcome({ kind: 'error', text: `${message}${code}` })
|
|
236
|
-
} else if (result.value === undefined) {
|
|
237
|
-
setOutcome({ kind: 'error', text: t('error.unknownCommand') })
|
|
153
|
+
const result = await commands.execute(runner, `/session-del delete ${id}`, [])
|
|
154
|
+
const outcome = readResult(result, tt)
|
|
155
|
+
if (outcome.ok) {
|
|
156
|
+
setPhase('done')
|
|
157
|
+
setReason('')
|
|
238
158
|
} else {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
kind: execution.kind === 'success' ? 'success' : 'error',
|
|
242
|
-
text: String(execution.text ?? ''),
|
|
243
|
-
})
|
|
159
|
+
setPhase('failed')
|
|
160
|
+
setReason(outcome.text || 'error')
|
|
244
161
|
}
|
|
245
162
|
} catch (error) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
setBusy(false)
|
|
163
|
+
setPhase('failed')
|
|
164
|
+
setReason(String(error?.message ?? error))
|
|
249
165
|
}
|
|
250
166
|
}
|
|
251
167
|
|
|
252
|
-
const
|
|
253
|
-
|
|
168
|
+
const label =
|
|
169
|
+
phase === 'confirm'
|
|
170
|
+
? tt('menu.confirm')
|
|
171
|
+
: phase === 'busy'
|
|
172
|
+
? tt('menu.busy')
|
|
173
|
+
: phase === 'done'
|
|
174
|
+
? tt('menu.done')
|
|
175
|
+
: phase === 'failed'
|
|
176
|
+
? tt('menu.failed', { reason })
|
|
177
|
+
: tt('menu.delete')
|
|
178
|
+
|
|
179
|
+
const danger = phase === 'confirm' || phase === 'failed'
|
|
180
|
+
const busy = phase === 'busy'
|
|
181
|
+
|
|
182
|
+
const style = {
|
|
183
|
+
display: 'flex',
|
|
184
|
+
alignItems: 'center',
|
|
185
|
+
gap: 8,
|
|
186
|
+
boxSizing: 'border-box',
|
|
187
|
+
width: '100%',
|
|
188
|
+
minWidth: 0,
|
|
189
|
+
height: 28,
|
|
190
|
+
padding: '0 8px',
|
|
191
|
+
margin: 0,
|
|
192
|
+
border: 0,
|
|
193
|
+
borderRadius: 6,
|
|
194
|
+
background: hover && !busy ? 'color-mix(in srgb, var(--dsw-alias-label-primary) 8%, transparent)' : 'transparent',
|
|
195
|
+
color: danger ? 'var(--dsw-alias-state-error-primary)' : 'var(--dsw-alias-label-primary)',
|
|
196
|
+
fontFamily: 'inherit',
|
|
197
|
+
fontSize: 13,
|
|
198
|
+
fontWeight: 400,
|
|
199
|
+
lineHeight: '18px',
|
|
200
|
+
textAlign: 'left',
|
|
201
|
+
cursor: busy ? 'default' : 'pointer',
|
|
202
|
+
opacity: busy ? 0.6 : 1,
|
|
203
|
+
outline: focused ? 'var(--dsw-focus-ring-width, 2px) solid var(--dsw-alias-brand-primary)' : 'none',
|
|
204
|
+
outlineOffset: focused ? -2 : 0,
|
|
205
|
+
}
|
|
254
206
|
|
|
255
207
|
return h(
|
|
256
|
-
'
|
|
208
|
+
'button',
|
|
257
209
|
{
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
210
|
+
type: 'button',
|
|
211
|
+
role: 'menuitem',
|
|
212
|
+
style,
|
|
213
|
+
title: [displayTitle, phase === 'failed' ? reason : undefined].filter(Boolean).join(' — ') || undefined,
|
|
214
|
+
disabled: busy,
|
|
215
|
+
'aria-label': tt('menu.delete'),
|
|
216
|
+
onMouseEnter: () => setHover(true),
|
|
217
|
+
onMouseLeave: () => setHover(false),
|
|
218
|
+
onFocus: () => setFocused(true),
|
|
219
|
+
onBlur: () => setFocused(false),
|
|
220
|
+
onClick: () => {
|
|
221
|
+
if (phase === 'idle') {
|
|
222
|
+
setPhase('confirm')
|
|
223
|
+
return
|
|
224
|
+
}
|
|
225
|
+
if (phase === 'confirm' || phase === 'failed') {
|
|
226
|
+
void run()
|
|
227
|
+
}
|
|
267
228
|
},
|
|
268
229
|
},
|
|
269
|
-
h(
|
|
270
|
-
|
|
271
|
-
{ className: 'sd-dialog-body' },
|
|
272
|
-
h('div', { className: 'sd-dialog-title', key: 'title' }, t('dialog.title')),
|
|
273
|
-
h('p', { className: 'sd-dialog-desc', key: 'desc' }, t('dialog.desc', { title })),
|
|
274
|
-
h('p', { className: 'sd-dialog-note', key: 'note' }, t('dialog.note')),
|
|
275
|
-
busy ? h('div', { className: 'sd-dialog-status', key: 'status', role: 'status' }, t('dialog.working')) : null,
|
|
276
|
-
outcome
|
|
277
|
-
? h(
|
|
278
|
-
'div',
|
|
279
|
-
{
|
|
280
|
-
className: `sd-dialog-result ${succeeded ? 'sd-ok' : 'sd-err'}`,
|
|
281
|
-
key: 'result',
|
|
282
|
-
role: 'alert',
|
|
283
|
-
},
|
|
284
|
-
outcome.text
|
|
285
|
-
)
|
|
286
|
-
: null
|
|
287
|
-
),
|
|
288
|
-
h(
|
|
289
|
-
'div',
|
|
290
|
-
{ className: 'sd-dialog-footer' },
|
|
291
|
-
succeeded
|
|
292
|
-
? h('button', { type: 'button', className: 'sd-btn', onClick: () => window.location.reload() }, t('reload'))
|
|
293
|
-
: h('button', { type: 'button', className: 'sd-btn', disabled: busy, onClick: close }, t('cancel')),
|
|
294
|
-
succeeded
|
|
295
|
-
? h('button', { type: 'button', className: 'sd-btn', onClick: close }, t('done'))
|
|
296
|
-
: h(
|
|
297
|
-
'button',
|
|
298
|
-
{ type: 'button', className: 'sd-btn sd-danger', disabled: busy, onClick: confirm },
|
|
299
|
-
t('confirm')
|
|
300
|
-
)
|
|
301
|
-
)
|
|
230
|
+
h('span', { key: 'icon', style: { display: 'inline-flex', flex: 'none', width: 14, height: 14 } }, TrashIcon()),
|
|
231
|
+
h('span', { key: 'label', style: { minWidth: 0, overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' } }, label)
|
|
302
232
|
)
|
|
303
233
|
}
|
|
304
234
|
|
|
305
|
-
/** 待确认的删除请求;菜单与确认框通过它传递。 */
|
|
306
|
-
const pendingDelete = createStore(null)
|
|
307
|
-
/** 当前 client 上下文(供确认框按需取用 ctx.remote)。 */
|
|
308
|
-
let ctxRef = null
|
|
309
|
-
|
|
310
235
|
return {
|
|
311
|
-
inject: ['slots', 'locale'],
|
|
236
|
+
inject: ['slots', 'locale', 'remote', 'remote.commands', 'sessions'],
|
|
312
237
|
apply(ctx) {
|
|
313
|
-
|
|
238
|
+
pluginCtx = ctx
|
|
314
239
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'session_del: dictionaries')
|
|
315
240
|
|
|
316
|
-
/** 打开一次确认。 */
|
|
317
|
-
const requestDelete = (request) => {
|
|
318
|
-
pendingDelete.set({ ...request, at: Date.now() })
|
|
319
|
-
}
|
|
320
|
-
|
|
321
241
|
ctx.slots.inject('sidebar.workspaces.session.menu.item', () =>
|
|
322
242
|
ctx.slots.register(
|
|
323
243
|
{
|
|
@@ -325,27 +245,10 @@ window.__ModuleLoader__.load({
|
|
|
325
245
|
id: 'session_del',
|
|
326
246
|
order: 600,
|
|
327
247
|
locale: NS,
|
|
328
|
-
inject: () => ({ requestDelete }),
|
|
329
248
|
},
|
|
330
249
|
DeleteMenuItem
|
|
331
250
|
)
|
|
332
251
|
)
|
|
333
|
-
|
|
334
|
-
ctx.slots.inject('shell.overlay', () =>
|
|
335
|
-
ctx.slots.register(
|
|
336
|
-
{
|
|
337
|
-
name: 'shell.overlay',
|
|
338
|
-
id: 'session_del.confirm',
|
|
339
|
-
order: 600,
|
|
340
|
-
locale: NS,
|
|
341
|
-
inject: () => ({
|
|
342
|
-
hooks: { pendingDelete },
|
|
343
|
-
settleDelete: () => pendingDelete.set(null),
|
|
344
|
-
}),
|
|
345
|
-
},
|
|
346
|
-
DeleteOverlay
|
|
347
|
-
)
|
|
348
|
-
)
|
|
349
252
|
},
|
|
350
253
|
}
|
|
351
254
|
},
|
package/package.json
CHANGED