@hyprnos/dsh-remote-plugin 0.0.0-stage → 0.8.8
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.en.md +61 -0
- package/README.md +60 -2
- package/apk/dsh-remote.apk +0 -0
- package/approval-summary.mjs +115 -0
- package/client.js +197 -0
- package/cordis.patch.yml +5 -0
- package/doctor-skill.mjs +99 -0
- package/doctor-target.mjs +24 -0
- package/file-delivery.mjs +84 -0
- package/gateway-stats.cjs +501 -0
- package/gateway.cjs +8451 -0
- package/index.mjs +1784 -0
- package/insights.mjs +111 -0
- package/market.mjs +86 -0
- package/package.json +71 -4
- package/peak-reminders.mjs +50 -0
- package/plugin-center.mjs +777 -0
- package/plugin-transaction.mjs +300 -0
- package/public/activity.js +188 -0
- package/public/admin.html +820 -0
- package/public/admin.js +1167 -0
- package/public/announcement-forms.js +89 -0
- package/public/announcements.json +464 -0
- package/public/app.js +8826 -0
- package/public/approval-records.js +301 -0
- package/public/approval-summary.js +78 -0
- package/public/build.json +5 -0
- package/public/cache-upgrade.js +51 -0
- package/public/chat-copy.js +59 -0
- package/public/chat-files.js +87 -0
- package/public/desktop/desktop.css +816 -0
- package/public/desktop/desktop.html +871 -0
- package/public/desktop/desktop.js +4548 -0
- package/public/desktop/i18n.js +85 -0
- package/public/diagnostics.js +203 -0
- package/public/doctor-entry.js +94 -0
- package/public/doctor.css +205 -0
- package/public/doctor.js +769 -0
- package/public/donate.png +0 -0
- package/public/e2ee-transport.js +219 -0
- package/public/extensions.css +109 -0
- package/public/extensions.js +215 -0
- package/public/file-inbox.css +66 -0
- package/public/file-inbox.js +289 -0
- package/public/genui.css +8 -0
- package/public/genui.js +254 -0
- package/public/history.js +304 -0
- package/public/i18n.js +57 -0
- package/public/icon.svg +12 -0
- package/public/image-cache.js +141 -0
- package/public/image-preview.js +290 -0
- package/public/index.html +1548 -0
- package/public/insights.css +28 -0
- package/public/insights.js +290 -0
- package/public/jsqr.min.js +10104 -0
- package/public/lan-discovery.js +94 -0
- package/public/link-check.js +109 -0
- package/public/manifest.webmanifest +16 -0
- package/public/md.js +333 -0
- package/public/morphicons-init.js +41 -0
- package/public/motion.js +557 -0
- package/public/network.js +100 -0
- package/public/onboarding.css +36 -0
- package/public/onboarding.js +253 -0
- package/public/operations.js +141 -0
- package/public/permission-presets.js +159 -0
- package/public/plugin-center.css +120 -0
- package/public/plugin-center.js +666 -0
- package/public/plugin-icon.svg +5 -0
- package/public/plugin.html +68 -0
- package/public/plugin.js +211 -0
- package/public/qrcode.min.js +2297 -0
- package/public/relay-autopair.js +251 -0
- package/public/relay-devices.js +80 -0
- package/public/relay-settings.css +24 -0
- package/public/relay-settings.js +194 -0
- package/public/remote-state.js +27 -0
- package/public/remote-ui.css +148 -0
- package/public/remote-ui.js +243 -0
- package/public/session-deck.css +79 -0
- package/public/session-deck.js +180 -0
- package/public/session-presets.js +47 -0
- package/public/setup.css +18 -0
- package/public/setup.js +213 -0
- package/public/sha256.js +119 -0
- package/public/skills.css +81 -0
- package/public/skills.js +202 -0
- package/public/skins/blue-fish/DESIGN.md +24 -0
- package/public/skins/blue-fish/face.png +0 -0
- package/public/skins/blue-fish/icon-blush.png +0 -0
- package/public/skins/blue-fish/icon-sleep.png +0 -0
- package/public/skins/blue-fish/icon-smile.png +0 -0
- package/public/skins/blue-fish/icon-star.png +0 -0
- package/public/skins/blue-fish/icon-wink.png +0 -0
- package/public/skins/blue-fish/icon.png +0 -0
- package/public/skins/blue-fish/mascot.png +0 -0
- package/public/skins/blue-fish/pattern.png +0 -0
- package/public/skins/blue-fish/preview.html +12 -0
- package/public/skins/blue-fish/skin.css +122 -0
- package/public/skins/blue-fish/sparkles.svg +18 -0
- package/public/skins/bocchi/DESIGN.md +99 -0
- package/public/skins/bocchi/face.png +0 -0
- package/public/skins/bocchi/grain.png +0 -0
- package/public/skins/bocchi/icon-blush.png +0 -0
- package/public/skins/bocchi/icon-sleep.png +0 -0
- package/public/skins/bocchi/icon-smile.png +0 -0
- package/public/skins/bocchi/icon-star.png +0 -0
- package/public/skins/bocchi/icon-wink.png +0 -0
- package/public/skins/bocchi/icon.png +0 -0
- package/public/skins/bocchi/pattern-soft.png +0 -0
- package/public/skins/bocchi/pattern.png +0 -0
- package/public/skins/bocchi/preview.html +55 -0
- package/public/skins/bocchi/skin.css +233 -0
- package/public/skins/bocchi/stage-bg.png +0 -0
- package/public/skins/bocchi/stage-soft.png +0 -0
- package/public/skins/bocchi/stand.png +0 -0
- package/public/skins/bocchi/sticker-guitar.png +0 -0
- package/public/skins/kessoku/DESIGN.md +38 -0
- package/public/skins/kessoku/grain.png +0 -0
- package/public/skins/kessoku/skin.css +212 -0
- package/public/skins/kita/SOURCES.json +51 -0
- package/public/skins/kita/face.png +0 -0
- package/public/skins/kita/icon-live.png +0 -0
- package/public/skins/kita/icon-reddress.png +0 -0
- package/public/skins/kita/icon-seifuku.png +0 -0
- package/public/skins/kita/pattern.png +0 -0
- package/public/skins/kita/preview.html +56 -0
- package/public/skins/kita/skin.css +26 -0
- package/public/skins/kita/stand.png +0 -0
- package/public/skins/kita/sticker-live.png +0 -0
- package/public/skins/nijika/SOURCES.json +51 -0
- package/public/skins/nijika/face.png +0 -0
- package/public/skins/nijika/icon-live.png +0 -0
- package/public/skins/nijika/icon-reddress.png +0 -0
- package/public/skins/nijika/icon-seifuku.png +0 -0
- package/public/skins/nijika/pattern.png +0 -0
- package/public/skins/nijika/preview.html +56 -0
- package/public/skins/nijika/skin.css +25 -0
- package/public/skins/nijika/stand.png +0 -0
- package/public/skins/nijika/sticker-live.png +0 -0
- package/public/skins/penguin/DESIGN.md +33 -0
- package/public/skins/penguin/SOURCES.json +22 -0
- package/public/skins/penguin/aic-blueprint.svg +24 -0
- package/public/skins/penguin/endfield-triangles.svg +4 -0
- package/public/skins/penguin/face.png +0 -0
- package/public/skins/penguin/icon-blush.png +0 -0
- package/public/skins/penguin/icon-dizzy.png +0 -0
- package/public/skins/penguin/icon-laugh.png +0 -0
- package/public/skins/penguin/icon-sleep.png +0 -0
- package/public/skins/penguin/icon-smile.png +0 -0
- package/public/skins/penguin/icon-star.png +0 -0
- package/public/skins/penguin/icon-wink.png +0 -0
- package/public/skins/penguin/icon.png +0 -0
- package/public/skins/penguin/mascot.png +0 -0
- package/public/skins/penguin/pattern-night.png +0 -0
- package/public/skins/penguin/pattern.png +0 -0
- package/public/skins/penguin/preview.html +12 -0
- package/public/skins/penguin/skin.css +212 -0
- package/public/skins/ryo/SOURCES.json +51 -0
- package/public/skins/ryo/face.png +0 -0
- package/public/skins/ryo/icon-live.png +0 -0
- package/public/skins/ryo/icon-reddress.png +0 -0
- package/public/skins/ryo/icon-seifuku.png +0 -0
- package/public/skins/ryo/pattern.png +0 -0
- package/public/skins/ryo/preview.html +56 -0
- package/public/skins/ryo/skin.css +25 -0
- package/public/skins/ryo/stand.png +0 -0
- package/public/skins/ryo/sticker-live.png +0 -0
- package/public/sponsor-entry.js +21 -0
- package/public/styles.css +1494 -0
- package/public/subagents.css +61 -0
- package/public/subagents.js +275 -0
- package/public/task-board.js +109 -0
- package/public/teams.js +98 -0
- package/public/theme-picker.css +58 -0
- package/public/theme-vars.css +1044 -0
- package/public/theme.js +166 -0
- package/public/transcribe-core.js +74 -0
- package/public/turn-results.js +121 -0
- package/public/update.json +49 -0
- package/public/vendor/gsap/NOTICE.md +10 -0
- package/public/vendor/gsap/gsap.min.js +11 -0
- package/public/vendor/morphicons/LICENSE +21 -0
- package/public/vendor/morphicons/README.md +10 -0
- package/public/vendor/morphicons/controller-CXZuwJ_M.js +152 -0
- package/public/vendor/morphicons/dom.js +206 -0
- package/public/vendor/morphicons/element.js +261 -0
- package/public/vendor/morphicons/normalize-CYnN3Npw.js +540 -0
- package/public/vendor/morphicons/spring-CFHloqPP.js +623 -0
- package/public/version.json +3 -0
- package/public/voice-input.js +739 -0
- package/public/workflow.css +365 -0
- package/public/workflow.js +409 -0
- package/session-file.mjs +39 -0
- package/skills/dsh-remote-doctor/SKILL.md +186 -0
- package/skills/dsh-remote-doctor/references/wiki/README.md +40 -0
- package/skills/dsh-remote-doctor/references/wiki/ai-guide.md +61 -0
- package/skills/dsh-remote-doctor/references/wiki/connection.md +76 -0
- package/skills/dsh-remote-doctor/references/wiki/errors.md +26 -0
- package/skills/dsh-remote-doctor/references/wiki/evidence.md +44 -0
- package/skills/dsh-remote-doctor/references/wiki/files.md +31 -0
- package/skills/dsh-remote-doctor/references/wiki/maintenance.md +30 -0
- package/skills/dsh-remote-doctor/references/wiki/notifications.md +33 -0
- package/skills/dsh-remote-doctor/references/wiki/operations.md +32 -0
- package/skills/dsh-remote-doctor/references/wiki/plugins.md +90 -0
- package/skills/dsh-remote-doctor/references/wiki/sessions.md +45 -0
- package/skills/dsh-remote-doctor/references/wiki/sources.md +27 -0
- package/skills.mjs +53 -0
- package/task-board.mjs +57 -0
- package/teams.mjs +58 -0
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
/* Shared mobile/desktop plugin center. Credentials stay in the parent connection. */
|
|
2
|
+
'use strict';
|
|
3
|
+
window.DshPluginCenter = (() => {
|
|
4
|
+
let dialog, connection, snapshot, timer, generation = 0, pending = false, tab = 'installed', offset = 0, searchSequence = 0, detailSequence = 0
|
|
5
|
+
const expandedDetails = new Map()
|
|
6
|
+
const marketCompatibility = new Map()
|
|
7
|
+
let renderedInstalled = '', renderedJobs = '', filter = '', statusFilter = 'all', refreshSequence = 0, trackedOperation = '', experimentalExpanded = false
|
|
8
|
+
const labels = { install: '安装', update: '更新', 'update-all': '批量更新', remove: '卸载', restore: '恢复', enable: '启用', disable: '停用', queued: '等待执行', running: '执行中', complete: '已完成', failed: '失败', interrupted: '已中断', active: '运行中', pending: '等待依赖', loading: '加载中', disposed: '未运行', unloading: '卸载中', inactive: '未运行' }
|
|
9
|
+
const stages = { queued: '等待主机启动', backup: '备份配置', snapshot: '备份插件文件', restore: '恢复并校验', 'profile-lock': '检查配置锁', cli: '执行插件命令', verify: '保存并核验', complete: '完成' }
|
|
10
|
+
function compareVersions(left, right) {
|
|
11
|
+
const parse = value => {
|
|
12
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(String(value || '').trim())
|
|
13
|
+
if (!match) return null
|
|
14
|
+
const pre = match[4]?.split('.')
|
|
15
|
+
if (pre?.some(value => /^\d+$/.test(value) && value.length > 1 && value[0] === '0')) return null
|
|
16
|
+
return { core: match.slice(1, 4), pre }
|
|
17
|
+
}
|
|
18
|
+
const a = parse(left), b = parse(right)
|
|
19
|
+
if (!a || !b) return null
|
|
20
|
+
const numeric = (x, y) => x.length !== y.length ? Math.sign(x.length - y.length) : x === y ? 0 : x < y ? -1 : 1
|
|
21
|
+
for (let i = 0; i < 3; i++) { const order = numeric(a.core[i], b.core[i]); if (order) return order }
|
|
22
|
+
if (!a.pre || !b.pre) return a.pre ? -1 : b.pre ? 1 : 0
|
|
23
|
+
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
24
|
+
const x = a.pre[i], y = b.pre[i]
|
|
25
|
+
if (x === y) continue
|
|
26
|
+
if (x === undefined || y === undefined) return x === undefined ? -1 : 1
|
|
27
|
+
const nx = /^\d+$/.test(x), ny = /^\d+$/.test(y)
|
|
28
|
+
return nx && ny ? numeric(x, y) : nx !== ny ? nx ? -1 : 1 : x < y ? -1 : 1
|
|
29
|
+
}
|
|
30
|
+
return 0
|
|
31
|
+
}
|
|
32
|
+
function jobProgress(job) {
|
|
33
|
+
const active = ['queued', 'running'].includes(job.phase), now = Date.now()
|
|
34
|
+
const elapsed = Math.max(0, Math.floor(((active ? now : job.endedAt || now) - job.startedAt) / 1000))
|
|
35
|
+
const parts = [stages[job.stage] || labels[job.phase] || job.phase, '耗时 ' + elapsed + ' 秒']
|
|
36
|
+
if (active && job.updatedAt && now - job.updatedAt > 15000) parts.push('主机任务状态超过 15 秒未更新,正在重新核对进程')
|
|
37
|
+
if (active && job.stage === 'cli') {
|
|
38
|
+
const silence = Math.max(0, Math.floor((now - (job.lastOutputAt || job.startedAt)) / 1000))
|
|
39
|
+
parts.push(job.lastOutputAt ? '最近输出在 ' + silence + ' 秒前' : '等待首次输出')
|
|
40
|
+
if (silence >= 30) parts.push('暂无新输出,命令仍待结束;请展开日志检查网络或锁占用')
|
|
41
|
+
}
|
|
42
|
+
return parts.join(' · ')
|
|
43
|
+
}
|
|
44
|
+
function node(tag, text, className) {
|
|
45
|
+
const el = document.createElement(tag)
|
|
46
|
+
if (text != null) el.textContent = text
|
|
47
|
+
if (className) el.className = className
|
|
48
|
+
return el
|
|
49
|
+
}
|
|
50
|
+
function button(text, action) {
|
|
51
|
+
const el = node('button', text)
|
|
52
|
+
el.type = 'button'; el.addEventListener('click', () => {
|
|
53
|
+
const current = generation
|
|
54
|
+
Promise.resolve().then(() => { if (current === generation) return action() }).catch(error => { if (current === generation) message(error.message) })
|
|
55
|
+
})
|
|
56
|
+
return el
|
|
57
|
+
}
|
|
58
|
+
function message(text) { dialog.querySelector('.pc-message').textContent = text }
|
|
59
|
+
function updateAllControl() {
|
|
60
|
+
const control = dialog.querySelector('.pc-update-all')
|
|
61
|
+
control.hidden = tab !== 'installed'
|
|
62
|
+
control.disabled = pending || !snapshot?.writable || snapshot.busy || snapshot.capabilities?.updateAll !== true
|
|
63
|
+
control.title = snapshot?.capabilities?.updateAll ? '检查全部已安装的 registry 插件,确认后批量更新' : '需要升级主机端 Remote 插件以支持批量更新'
|
|
64
|
+
for (const tab of dialog.querySelectorAll('[data-pc-tab]')) tab.disabled = pending
|
|
65
|
+
}
|
|
66
|
+
async function api(path, body) {
|
|
67
|
+
if (!connection.valid()) throw new Error('连接已切换,请关闭后重新打开插件中心')
|
|
68
|
+
const current = generation
|
|
69
|
+
const response = await fetch(connection.url('/remote/api/plugins' + path), {
|
|
70
|
+
method: body ? 'POST' : 'GET', headers: { ...connection.headers, 'content-type': 'application/json' },
|
|
71
|
+
...(body ? { body: JSON.stringify(body) } : {}), signal: AbortSignal.timeout(path === '/preflight' ? 130000 : 30000),
|
|
72
|
+
})
|
|
73
|
+
if (current !== generation || !dialog.open || !connection.valid()) throw new Error('连接已切换,请重新打开插件中心')
|
|
74
|
+
let data
|
|
75
|
+
try { data = await response.json() } catch { throw new Error('当前服务器不支持插件中心,请升级主机端 Remote 插件') }
|
|
76
|
+
if (current !== generation || !dialog.open || !connection.valid()) throw new Error('连接已切换,请重新打开插件中心')
|
|
77
|
+
if (!response.ok || data.ok === false) throw Object.assign(new Error(data.message || '请求失败:HTTP ' + response.status), { status: response.status })
|
|
78
|
+
return data
|
|
79
|
+
}
|
|
80
|
+
function card(name, description) {
|
|
81
|
+
const el = node('article', null, 'pc-card')
|
|
82
|
+
const header = node('div', null, 'pc-card-head')
|
|
83
|
+
const icon = node('span', (name || 'P').replace(/^@/, '').slice(0, 1).toUpperCase(), 'pc-plugin-icon')
|
|
84
|
+
icon.setAttribute('aria-hidden', 'true')
|
|
85
|
+
header.append(icon, node('h3', name)); el.append(header)
|
|
86
|
+
if (description) el.append(node('p', description, 'pc-description'))
|
|
87
|
+
return el
|
|
88
|
+
}
|
|
89
|
+
const experimentalPlugin = item => item.name?.startsWith('@deepseek-ai/dsh-experimental-') === true
|
|
90
|
+
const installedPlugin = item => item.managed || item.name === '@hyprnos/dsh-remote-plugin' || experimentalPlugin(item)
|
|
91
|
+
function renderInstalled() {
|
|
92
|
+
const list = dialog.querySelector('.pc-list'), restore = preserveListPosition(list)
|
|
93
|
+
experimentalExpanded = list.querySelector('.pc-experimental')?.open ?? experimentalExpanded
|
|
94
|
+
list.replaceChildren()
|
|
95
|
+
if (!snapshot) { list.append(node('p', '尚未读取插件状态,请点击刷新。')); return }
|
|
96
|
+
const rows = snapshot.items.filter(item => tab === 'builtin' ? !installedPlugin(item) : installedPlugin(item))
|
|
97
|
+
.filter(item => [item.name, item.displayName, item.description].join(' ').toLowerCase().includes(filter.toLowerCase()))
|
|
98
|
+
.filter(item => statusFilter === 'all' || (statusFilter === 'enabled' ? item.enabled : !item.enabled))
|
|
99
|
+
if (!rows.length) list.append(node('p', filter || statusFilter !== 'all' ? '没有匹配的插件。' : tab === 'builtin' ? '暂无内置插件。' : '当前主机没有其他已安装插件。第三方插件可按需选择。', 'pc-empty'))
|
|
100
|
+
const experimentalRows = rows.filter(experimentalPlugin)
|
|
101
|
+
const experimental = node('details', null, 'pc-experimental'), experimentalList = node('div', null, 'pc-list pc-experimental-list')
|
|
102
|
+
experimental.open = experimentalExpanded
|
|
103
|
+
experimental.append(node('summary', '实验性插件(' + experimentalRows.length + ')'), experimentalList)
|
|
104
|
+
experimental.addEventListener('toggle', () => {
|
|
105
|
+
if (list.querySelector('.pc-experimental') === experimental) experimentalExpanded = experimental.open
|
|
106
|
+
})
|
|
107
|
+
for (const item of rows) {
|
|
108
|
+
const el = card(item.displayName || item.name, item.description)
|
|
109
|
+
el.append(node('small', item.name, 'pc-package'))
|
|
110
|
+
const meta = node('div', null, 'pc-meta')
|
|
111
|
+
meta.append(node('span', item.version ? 'v' + item.version : item.requested || '内置', 'pc-version'))
|
|
112
|
+
if (experimentalPlugin(item)) meta.append(node('span', '实验性', 'pc-badge'))
|
|
113
|
+
if (!item.bundle || !item.managed || !snapshot.writable) meta.append(node('span', item.enabled ? '配置启用' : '配置停用', 'pc-badge ' + (item.enabled ? 'is-active' : '')))
|
|
114
|
+
const runtime = item.runtime || []
|
|
115
|
+
if (runtime.some(entry => entry.phase === 'failed')) meta.append(node('span', '运行异常', 'pc-badge is-error'))
|
|
116
|
+
else if (runtime.length) meta.append(node('span', `${runtime.filter(entry => entry.phase === 'active').length}/${runtime.length} 组件运行中`, 'pc-badge'))
|
|
117
|
+
el.append(meta)
|
|
118
|
+
for (const diagnostic of window.DshExtensions?.diagnosticsFor?.(snapshot, item, connection) || []) {
|
|
119
|
+
const status = node('p', (window.I18N?.lang === 'en' ? 'Adapter: ' : '适配:') + diagnostic.label, 'pc-adaptation')
|
|
120
|
+
status.dataset.code = diagnostic.code
|
|
121
|
+
const help = node('a', window.I18N?.lang === 'en' ? 'Troubleshooting' : '插件排障文档')
|
|
122
|
+
help.href = diagnostic.helpUrl; help.target = '_blank'; help.rel = 'noopener noreferrer'
|
|
123
|
+
status.append(node('span', ' · '), help); el.append(status)
|
|
124
|
+
}
|
|
125
|
+
const actions = node('div', null, 'pc-card-actions')
|
|
126
|
+
const area = inlineArea(item.name)
|
|
127
|
+
const detail = button('查看详情', () => installedDetails(item, area, detail)); detail.className = 'pc-detail-button'
|
|
128
|
+
actions.append(detail)
|
|
129
|
+
if (item.managed && snapshot.writable) {
|
|
130
|
+
actions.append(button('查看更新', () => showDetails(item.name, '', area, detail, true)))
|
|
131
|
+
if (item.bundle) {
|
|
132
|
+
const toggle = button(item.enabled ? '已启用' : '已停用', () => mutate(item.enabled ? 'disable' : 'enable', item.name))
|
|
133
|
+
toggle.className = 'pc-toggle'; toggle.disabled = pending || snapshot.busy
|
|
134
|
+
toggle.setAttribute('role', 'switch'); toggle.setAttribute('aria-checked', String(item.enabled)); toggle.setAttribute('aria-label', '启用 ' + item.name)
|
|
135
|
+
toggle.setAttribute('title', item.enabled ? '配置已启用' : '配置已停用')
|
|
136
|
+
el.querySelector('.pc-card-head').append(toggle)
|
|
137
|
+
}
|
|
138
|
+
const remove = button('卸载', () => mutate('remove', item.name)); remove.className = 'pc-danger-button'; actions.append(remove)
|
|
139
|
+
for (const action of actions.children) if (action !== detail) action.disabled = pending || snapshot.busy
|
|
140
|
+
} else if (item.selfUpdate && snapshot.writable) {
|
|
141
|
+
const update = button('更新 Remote', () => showDetails(item.name, '', area, detail, true))
|
|
142
|
+
update.disabled = snapshot.busy || pending; actions.append(update)
|
|
143
|
+
} else actions.append(node('small', '主机维护 · 只读'))
|
|
144
|
+
if (connection.onFeature) {
|
|
145
|
+
for (const feature of window.DshExtensions?.featuresFor(snapshot, item, !!connection.getSession?.()?.sessionId) || []) {
|
|
146
|
+
const action = button(feature.label, () => connection.onFeature(feature.id))
|
|
147
|
+
action.className = 'pc-open-feature'; actions.prepend(action)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
el.dataset.plugin = item.name
|
|
151
|
+
detail.setAttribute('aria-controls', area.id)
|
|
152
|
+
renderInline(area, detail, item)
|
|
153
|
+
el.append(actions, area)
|
|
154
|
+
if (experimentalPlugin(item)) experimentalList.append(el)
|
|
155
|
+
else list.append(el)
|
|
156
|
+
}
|
|
157
|
+
if (experimentalRows.length) list.append(experimental)
|
|
158
|
+
const runtime = node('details', null, 'pc-runtime')
|
|
159
|
+
runtime.append(node('summary', '当前进程实际加载状态 (' + snapshot.runtime.length + ')'))
|
|
160
|
+
if (!snapshot.runtimeAvailable) runtime.append(node('p', '此 DSH 版本未提供加载状态'))
|
|
161
|
+
for (const entry of snapshot.runtime) runtime.append(node('p', entry.name + ' · ' + entry.phase + (entry.enabled ? '' : ' · disabled')))
|
|
162
|
+
list.append(runtime)
|
|
163
|
+
restore()
|
|
164
|
+
}
|
|
165
|
+
function preserveListPosition(list) {
|
|
166
|
+
const anchor = [...list.children].find(el => el.dataset.plugin && el.getBoundingClientRect?.().bottom > 0)
|
|
167
|
+
if (!anchor?.getBoundingClientRect) return () => {}
|
|
168
|
+
const top = anchor.getBoundingClientRect().top, name = anchor.dataset.plugin
|
|
169
|
+
let parent = list.parentElement
|
|
170
|
+
while (parent && !/(auto|scroll)/.test(getComputedStyle(parent).overflowY)) parent = parent.parentElement
|
|
171
|
+
return () => {
|
|
172
|
+
const current = [...list.children].find(el => el.dataset.plugin === name)
|
|
173
|
+
if (!current) return
|
|
174
|
+
const delta = current.getBoundingClientRect().top - top
|
|
175
|
+
if (parent) parent.scrollTop += delta
|
|
176
|
+
else window.scrollBy(0, delta)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function inlineArea(name) {
|
|
180
|
+
const area = node('section', null, 'pc-inline-detail')
|
|
181
|
+
area.dataset.key = tab + ':' + name
|
|
182
|
+
area.id = 'pc-detail-' + encodeURIComponent(area.dataset.key)
|
|
183
|
+
return area
|
|
184
|
+
}
|
|
185
|
+
function currentArea(key) { return [...dialog.querySelectorAll('.pc-inline-detail')].find(el => el.dataset.key === key) }
|
|
186
|
+
function renderInline(area, control, installed) {
|
|
187
|
+
const entry = expandedDetails.get(area.dataset.key)
|
|
188
|
+
control.textContent = entry ? '收起详情' : '查看详情'
|
|
189
|
+
control.setAttribute('aria-expanded', String(!!entry))
|
|
190
|
+
area.replaceChildren(); area.hidden = !entry
|
|
191
|
+
if (!entry) return
|
|
192
|
+
if (entry.loading) { area.append(node('p', '正在加载详情…', 'pc-detail-loading')); return }
|
|
193
|
+
if (entry.error) { area.append(node('p', entry.error, 'pc-detail-error'), button('重试', () => showDetails(entry.name, entry.version, area, control, true))); return }
|
|
194
|
+
if (entry.kind === 'installed') {
|
|
195
|
+
const item = installed || entry.item
|
|
196
|
+
if (item.description) area.append(node('p', item.description))
|
|
197
|
+
area.append(node('p', '配置:' + (item.enabled ? '启用' : '停用')), node('h4', '组件运行状态'))
|
|
198
|
+
const entries = item.runtime || []
|
|
199
|
+
if (!entries.length) area.append(node('p', '未获得该包的组件归属。可在列表底部查看当前进程全部加载状态。'))
|
|
200
|
+
for (const component of entries) area.append(node('p', component.name + ' · ' + (labels[component.phase] || component.phase)))
|
|
201
|
+
if (!item.managed) area.append(node('p', '随 DSH 提供的核心插件由主机维护。'))
|
|
202
|
+
readmeControl(area, item)
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
const item = entry.item
|
|
206
|
+
area.append(node('h4', item.name + ' @ ' + item.version), node('p', item.description || ''), node('p', '许可证:' + (item.license || '未声明') + ' · ' + (item.bundle ? 'DSH bundle' : '未声明 DSH bundle')))
|
|
207
|
+
area.append(node('p', '运行要求:' + JSON.stringify(item.engines) + ';依赖要求:' + JSON.stringify(item.peers)))
|
|
208
|
+
area.append(node('p', '插件代码将在 DSH 主机运行。安装脚本默认禁用;需要额外配置的插件须在主机完成配置。'))
|
|
209
|
+
if (/^https:\/\//.test(item.homepage)) {
|
|
210
|
+
const link = node('a', '项目主页'); link.href = item.homepage; link.target = '_blank'; link.rel = 'noopener noreferrer'; area.append(link)
|
|
211
|
+
}
|
|
212
|
+
const input = node('input'); input.value = entry.versionDraft ?? item.version; input.setAttribute('aria-label', '插件版本'); input.placeholder = '指定版本,如 1.2.3'
|
|
213
|
+
input.addEventListener('input', () => { entry.versionDraft = input.value })
|
|
214
|
+
area.append(input, button('查看此版本', () => showDetails(entry.name, input.value.trim(), area, control, true)))
|
|
215
|
+
const row = snapshot?.items.find(row => row.name === item.name), action = row ? 'update' : 'install'
|
|
216
|
+
const order = row ? compareVersions(item.version, row.version) : null
|
|
217
|
+
const older = row && order !== null && order < 0, uncertain = row && order === null
|
|
218
|
+
if (older) area.append(node('p', '已安装 v' + row.version + ',高于此版本。若确需降级,请指定版本并点击“查看此版本”。', 'pc-detail-notice'))
|
|
219
|
+
else if (uncertain) area.append(node('p', '无法比较已安装版本与此版本;请指定版本后确认切换。', 'pc-detail-notice'))
|
|
220
|
+
const label = row && order === 0 ? '已安装' : older ? '降级至' : uncertain ? '切换至' : labels[action]
|
|
221
|
+
const install = button(label + ' ' + item.version, () => mutate(action, item.name, item.version))
|
|
222
|
+
install.disabled = !item.bundle || item.protected && !(row?.selfUpdate && action === 'update') || !snapshot?.writable || snapshot.busy || pending || row && order === 0 || (older || uncertain) && !entry.version || marketCompatibility.get(item.name + '@' + item.version) === false
|
|
223
|
+
area.append(install)
|
|
224
|
+
readmeControl(area, item)
|
|
225
|
+
}
|
|
226
|
+
function installedDetails(item, area, control) {
|
|
227
|
+
if (expandedDetails.has(area.dataset.key)) expandedDetails.delete(area.dataset.key)
|
|
228
|
+
else expandedDetails.set(area.dataset.key, { kind: 'installed', item })
|
|
229
|
+
renderInline(area, control, item)
|
|
230
|
+
}
|
|
231
|
+
function renderTabs() {
|
|
232
|
+
for (const button of dialog.querySelectorAll('[data-pc-tab]')) {
|
|
233
|
+
button.classList.toggle('active', button.dataset.pcTab === tab)
|
|
234
|
+
button.setAttribute('aria-pressed', String(button.dataset.pcTab === tab))
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async function refresh() {
|
|
238
|
+
const sequence = ++refreshSequence
|
|
239
|
+
let data
|
|
240
|
+
try { data = await api('/state') } catch (error) { if (sequence === refreshSequence) throw error; return }
|
|
241
|
+
if (sequence !== refreshSequence) return
|
|
242
|
+
snapshot = data
|
|
243
|
+
updateAllControl()
|
|
244
|
+
window.DshExtensions?.remember(connection, snapshot)
|
|
245
|
+
const tracked = snapshot.operations.find(job => job.id === trackedOperation)
|
|
246
|
+
if (tracked && !['queued', 'running'].includes(tracked.phase)) {
|
|
247
|
+
message((labels[tracked.phase] || tracked.phase) + ':' + tracked.name + '。' + (tracked.message || '请查看操作记录。'))
|
|
248
|
+
trackedOperation = ''
|
|
249
|
+
}
|
|
250
|
+
const recovery = dialog.querySelector('.pc-recovery'); recovery.replaceChildren()
|
|
251
|
+
if (snapshot.recovery) {
|
|
252
|
+
recovery.append(node('p', snapshot.recovery.reason))
|
|
253
|
+
const action = button('恢复旧任务', () => {
|
|
254
|
+
const body = { id: snapshot.recovery.id, revision: snapshot.revision, confirmNoRunningProcess: true }
|
|
255
|
+
const review = card('解除旧任务锁', '请先在主机确认没有正在运行的插件安装或卸载进程。此操作保留文件和备份,不执行回滚。')
|
|
256
|
+
review.append(button('已确认,解除锁定', () => executeMutation(body, '/recover')), button('取消', () => dialog.querySelector('.pc-detail').replaceChildren()))
|
|
257
|
+
dialog.querySelector('.pc-detail').replaceChildren(review)
|
|
258
|
+
})
|
|
259
|
+
action.disabled = !snapshot.writable || pending; recovery.append(action)
|
|
260
|
+
}
|
|
261
|
+
dialog.querySelector('.pc-profile').textContent = snapshot.profile ? '当前环境:' + snapshot.profile : '当前环境无法识别'
|
|
262
|
+
dialog.querySelector('.pc-status').textContent = snapshot.reason || (snapshot.pendingRestart ? '插件配置已变更,重启 DSH 后生效。' : '安装到当前连接的 DSH 主机。')
|
|
263
|
+
dialog.querySelector('.pc-status').hidden = !snapshot.reason && !snapshot.pendingRestart
|
|
264
|
+
const summary = dialog.querySelector('.pc-summary'); summary.replaceChildren()
|
|
265
|
+
for (const [count, title] of [[snapshot.items.filter(installedPlugin).length, '已安装'], [snapshot.items.filter(item => installedPlugin(item) && item.enabled).length, '配置启用']]) {
|
|
266
|
+
const stat = node('span', null, 'pc-stat'); stat.append(node('strong', String(count)), node('span', title)); summary.append(stat)
|
|
267
|
+
}
|
|
268
|
+
if (snapshot.busy) summary.append(node('span', '任务执行中', 'pc-badge'))
|
|
269
|
+
const progress = dialog.querySelector('.pc-progress'); progress.replaceChildren()
|
|
270
|
+
const activeJob = snapshot.operations.find(job => ['queued', 'running'].includes(job.phase))
|
|
271
|
+
if (activeJob) progress.append(node('strong', (labels[activeJob.action] || activeJob.action) + ' ' + activeJob.name), node('p', jobProgress(activeJob)), node('p', activeJob.message || '任务在主机执行,可关闭窗口后回来查看。'))
|
|
272
|
+
if (snapshot.busyReason) progress.append(node('p', snapshot.busyReason))
|
|
273
|
+
if (snapshot.profileLock) progress.append(node('p', snapshot.profileLock.message))
|
|
274
|
+
progress.hidden = !progress.children.length
|
|
275
|
+
const installedKey = JSON.stringify([snapshot.items, snapshot.runtime, snapshot.runtimeAvailable, snapshot.pendingRestart, snapshot.busy, snapshot.writable, snapshot.adaptations,
|
|
276
|
+
snapshot.items.flatMap(item => window.DshExtensions?.diagnosticsFor?.(snapshot, item, connection) || []), pending, tab, filter, statusFilter])
|
|
277
|
+
if (['installed', 'builtin'].includes(tab) && installedKey !== renderedInstalled) { renderInstalled(); renderedInstalled = installedKey }
|
|
278
|
+
renderTabs()
|
|
279
|
+
const jobsKey = JSON.stringify(snapshot.operations.map(job => [job, jobProgress(job)]))
|
|
280
|
+
if (jobsKey === renderedJobs) return
|
|
281
|
+
renderedJobs = jobsKey
|
|
282
|
+
const jobs = dialog.querySelector('.pc-jobs')
|
|
283
|
+
const knownJobs = new Set([...jobs.children].map(el => el.dataset.id))
|
|
284
|
+
if (activeJob && !knownJobs.has(activeJob.id)) dialog.querySelector('.pc-history').open = true
|
|
285
|
+
const expanded = new Set([...jobs.querySelectorAll('details[open]')].map(el => el.dataset.id))
|
|
286
|
+
jobs.replaceChildren()
|
|
287
|
+
for (const job of snapshot.operations) {
|
|
288
|
+
const el = node('details')
|
|
289
|
+
el.dataset.id = job.id; el.open = expanded.has(job.id) || !knownJobs.has(job.id) && ['queued', 'running'].includes(job.phase)
|
|
290
|
+
el.append(node('summary', (labels[job.action] || job.action) + ' ' + job.name + (job.version ? '@' + job.version : '') + ' · ' + (labels[job.phase] || job.phase)))
|
|
291
|
+
el.append(node('small', new Date(job.startedAt).toLocaleString()))
|
|
292
|
+
el.append(node('p', jobProgress(job), 'pc-job-progress'))
|
|
293
|
+
el.append(node('p', job.message || '任务在主机端执行,可关闭窗口后回来查看。'))
|
|
294
|
+
if (job.log) el.append(node('pre', job.log))
|
|
295
|
+
for (const target of job.targets || []) el.append(node('p', target.name + ' · ' + target.fromVersion + ' → ' + target.version + ' · ' + (labels[target.phase] || target.phase) + (target.message ? ' · ' + target.message : ''), 'pc-batch-result'))
|
|
296
|
+
if (job.canRestore) {
|
|
297
|
+
const restore = button('恢复更新前状态', () => reviewRestore(job))
|
|
298
|
+
restore.disabled = !snapshot.writable || snapshot.busy || pending
|
|
299
|
+
el.append(restore)
|
|
300
|
+
}
|
|
301
|
+
jobs.append(el)
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const localText = value => typeof value === 'string' ? value : value?.['zh-CN'] || value?.zh || value?.en || Object.values(value || {})[0] || ''
|
|
305
|
+
let marketIndex = '', marketCategory = '', marketSort = '', fetchedAt = null
|
|
306
|
+
const README_IMAGE_HOSTS = ['raw.githubusercontent.com','github.com','objects.githubusercontent.com','user-images.githubusercontent.com','img.shields.io','shields.io','badgen.net','cdn.jsdelivr.net']
|
|
307
|
+
function readmeControl(area, item) {
|
|
308
|
+
const content = node('section', null, 'pc-readme')
|
|
309
|
+
const action = button('阅读 README', async () => {
|
|
310
|
+
const current = generation
|
|
311
|
+
content.replaceChildren(node('p', '正在读取 README…'))
|
|
312
|
+
try {
|
|
313
|
+
const data = await api('/readme?name=' + encodeURIComponent(item.name))
|
|
314
|
+
if (current !== generation || currentArea(area.dataset.key) !== area) return
|
|
315
|
+
content.replaceChildren()
|
|
316
|
+
if (!data.available) { content.append(node('p', '该插件未提供 README')); return }
|
|
317
|
+
content.append(node('p', 'npm 当前包级 README,未按指定版本归档。' + (data.version ? ' latest 标签:' + data.version + '。' : '') + (data.truncated ? '内容已截断。' : '')))
|
|
318
|
+
const markdown = node('div', null, 'md')
|
|
319
|
+
if (window.mdToHtml) markdown.innerHTML = window.mdToHtml(data.content, { richContent: false, fileLinks: false, imageHosts: README_IMAGE_HOSTS })
|
|
320
|
+
else markdown.textContent = data.content
|
|
321
|
+
content.append(markdown)
|
|
322
|
+
} catch (_) { if (current === generation) content.replaceChildren(node('p', 'README 暂时无法读取,请重试。')) }
|
|
323
|
+
})
|
|
324
|
+
area.append(action, content)
|
|
325
|
+
}
|
|
326
|
+
function adaptedCards(list) {
|
|
327
|
+
const section = node('section', null, 'pc-adapted')
|
|
328
|
+
section.append(node('h3', 'Remote 已适配'), node('p', '仅核验列出的版本;其他版本尚未验证。插件按需选择,安装前仍需确认。'))
|
|
329
|
+
const capabilities = window.DshExtensions?.capabilitiesOf(snapshot) || {}
|
|
330
|
+
for (const feature of window.DshExtensions?.catalog || []) {
|
|
331
|
+
const installed = snapshot?.items.find(item => item.name === feature.name), el = card(feature.name, feature.summary)
|
|
332
|
+
el.append(node('p', '已核验:' + feature.verified + ' · ' + (!snapshot ? '主机安装状态未知' : !installed ? '未安装' : capabilities[feature.id] ? '可用' : '已安装,当前不可用')))
|
|
333
|
+
const area = inlineArea(feature.name), detail = button('查看详情', () => showDetails(feature.name, feature.verified, area, detail))
|
|
334
|
+
area.dataset.key += ':adapted'; area.id += '-adapted'
|
|
335
|
+
detail.className = 'pc-detail-button'; el.append(detail, area); renderInline(area, detail)
|
|
336
|
+
if (!installed) {
|
|
337
|
+
const install = button('安装已核验版本 ' + feature.verified, () => mutate('install', feature.name, feature.verified))
|
|
338
|
+
install.disabled = !snapshot?.writable || snapshot.busy || pending; el.append(install)
|
|
339
|
+
} else if (!feature.session && capabilities[feature.id] && connection.onFeature) el.append(button(feature.label, () => connection.onFeature(feature.id)))
|
|
340
|
+
section.append(el)
|
|
341
|
+
}
|
|
342
|
+
list.append(section)
|
|
343
|
+
}
|
|
344
|
+
function selection(title, values, value, changed) {
|
|
345
|
+
const select = node('select'); select.setAttribute('aria-label', title)
|
|
346
|
+
for (const row of values) { const option = node('option', row.label); option.value = row.value; option.disabled = !!row.disabled; select.append(option) }
|
|
347
|
+
select.value = value
|
|
348
|
+
const current = generation
|
|
349
|
+
select.addEventListener('change', () => { if (current !== generation) return; changed(select.value); offset = 0; void search() })
|
|
350
|
+
return select
|
|
351
|
+
}
|
|
352
|
+
async function search(forceRefresh = false) {
|
|
353
|
+
const sequence = ++searchSequence, current = generation
|
|
354
|
+
const q = dialog.querySelector('.pc-search').value.trim()
|
|
355
|
+
if (!offset) fetchedAt = null
|
|
356
|
+
const list = dialog.querySelector('.pc-list'); list.replaceChildren(); adaptedCards(list)
|
|
357
|
+
const results = node('section', null, 'pc-market-results'); list.append(results)
|
|
358
|
+
results.append(node('p', '正在读取主机官方索引…'))
|
|
359
|
+
try {
|
|
360
|
+
const state = await api('/market/indexes')
|
|
361
|
+
if (tab !== 'market' || sequence !== searchSequence || current !== generation) return
|
|
362
|
+
results.replaceChildren()
|
|
363
|
+
if (!state.available) { results.append(node('p', '当前主机未启用官方发现服务。仍可按完整包名查看详情。', 'pc-market-note')); return }
|
|
364
|
+
if (!state.indexes.length) { results.append(node('p', '未配置索引源,以上为 Remote 已适配插件。请在主机 → 插件 → 发现 → 索引源添加后搜索。', 'pc-market-note')); return }
|
|
365
|
+
if (!state.indexes.some(row => row.url === marketIndex && !row.code)) marketIndex = state.indexes.find(row => !row.code)?.url || ''
|
|
366
|
+
const sources = selection('索引源', state.indexes.map(row => ({ value: row.url, label: localText(row.title) || row.url || '索引不可用', disabled: !!row.code })), marketIndex, value => { marketIndex = value; marketCategory = '' })
|
|
367
|
+
results.append(sources)
|
|
368
|
+
if (!marketIndex) { results.append(node('p', '索引暂时不可用,请在主机检查索引源配置。', 'pc-market-note')); return }
|
|
369
|
+
const params = new URLSearchParams({ q, offset: String(offset), index: marketIndex, sort: marketSort || (q ? 'relevance' : 'index') })
|
|
370
|
+
if (marketCategory) params.set('category', marketCategory)
|
|
371
|
+
if (fetchedAt !== null) params.set('fetchedAt', String(fetchedAt))
|
|
372
|
+
if (forceRefresh) params.set('refresh', '1')
|
|
373
|
+
const data = await api('/market?' + params)
|
|
374
|
+
if (tab !== 'market' || sequence !== searchSequence || current !== generation) return
|
|
375
|
+
if (!data.available) { results.append(node('p', '官方索引暂时无法读取,请重试。', 'pc-market-note')); return }
|
|
376
|
+
fetchedAt = data.fetchedAt
|
|
377
|
+
results.append(node('p', '来源:主机官方索引(' + (localText(data.index?.title) || marketIndex) + ')。索引为第三方声明,不代表安全审核。', 'pc-market-note'))
|
|
378
|
+
const controls = node('div', null, 'pc-market-controls')
|
|
379
|
+
controls.append(selection('分类', [{ value: '', label: '全部分类' }, ...(data.categories || []).map(row => ({ value: row.id, label: localText(row.title) || row.id }))], marketCategory, value => { marketCategory = value }), selection('排序', [{ value: 'index', label: '索引顺序' }, { value: 'relevance', label: '相关性' }, { value: 'published', label: '最新发布' }], marketSort || (q ? 'relevance' : 'index'), value => { marketSort = value }))
|
|
380
|
+
results.append(controls)
|
|
381
|
+
if (!data.items.length) results.append(node('p', '没有找到插件;可输入完整包名查看详情。'))
|
|
382
|
+
for (const item of data.items) {
|
|
383
|
+
marketCompatibility.set(item.name + '@' + item.version, item.installSupported === false ? false : item.compatibility?.compatible)
|
|
384
|
+
const el = card(localText(item.title) || item.name, localText(item.description))
|
|
385
|
+
const status = { 'not-installed': '未安装', installed: '已安装', 'update-available': '有更新', 'different-version': '已安装其他版本', provided: '主机提供' }[item.installation?.status] || '安装状态未知'
|
|
386
|
+
el.append(node('p', item.name + ' · ' + item.version + ' · ' + status + ' · ' + (item.compatibility?.compatible === true ? '符合主机版本要求' : item.compatibility?.compatible === false ? '不符合主机版本要求' : '兼容性未知')))
|
|
387
|
+
if (item.installSupported === false) el.append(node('p', '此条目使用其他安装源;Remote 当前仅支持 npm 官方 registry 的安装,请在主机处理。'))
|
|
388
|
+
const area = inlineArea(item.name), detail = button('查看详情', () => showDetails(item.name, item.version, area, detail))
|
|
389
|
+
detail.className = 'pc-detail-button'; el.dataset.plugin = item.name; el.append(detail, area); renderInline(area, detail); results.append(el)
|
|
390
|
+
}
|
|
391
|
+
if (offset > 0) results.append(button('上一页', () => { offset = Math.max(0, offset - 20); return search() }))
|
|
392
|
+
if (data.nextOffset !== null) results.append(button('下一页', () => { offset = data.nextOffset; return search() }))
|
|
393
|
+
} catch (_) { if (sequence === searchSequence && current === generation && tab === 'market') results.replaceChildren(node('p', '官方索引暂时无法读取;以上适配信息仍可查看。', 'pc-market-note')) }
|
|
394
|
+
}
|
|
395
|
+
async function showDetails(name, version, area, control, force = false) {
|
|
396
|
+
if (!area) {
|
|
397
|
+
const el = card(name, ''), target = inlineArea(name)
|
|
398
|
+
const detail = button('查看详情', () => showDetails(name, version, target, detail))
|
|
399
|
+
detail.className = 'pc-detail-button'; el.append(detail, target); dialog.querySelector('.pc-detail').replaceChildren(el)
|
|
400
|
+
area = target; control = detail
|
|
401
|
+
}
|
|
402
|
+
const key = area.dataset.key
|
|
403
|
+
if (!force && expandedDetails.has(key)) { expandedDetails.delete(key); renderInline(area, control); return }
|
|
404
|
+
const current = generation, entry = { name, version, kind: 'market', loading: true }
|
|
405
|
+
expandedDetails.set(key, entry); renderInline(area, control)
|
|
406
|
+
try {
|
|
407
|
+
const { item } = await api('/details?name=' + encodeURIComponent(name) + (version ? '&version=' + encodeURIComponent(version) : ''))
|
|
408
|
+
if (current !== generation || expandedDetails.get(key) !== entry) return
|
|
409
|
+
entry.item = item; entry.loading = false
|
|
410
|
+
} catch (error) {
|
|
411
|
+
if (current !== generation || expandedDetails.get(key) !== entry) return
|
|
412
|
+
entry.loading = false; entry.error = error.message
|
|
413
|
+
}
|
|
414
|
+
const target = currentArea(key)
|
|
415
|
+
if (target) {
|
|
416
|
+
const button = (target.parentElement || target.parent).querySelector('.pc-detail-button')
|
|
417
|
+
renderInline(target, button)
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
async function updateAll() {
|
|
421
|
+
if (pending || snapshot?.busy || !snapshot?.writable || !snapshot.capabilities?.updateAll) return
|
|
422
|
+
const current = generation, sequence = ++detailSequence, area = dialog.querySelector('.pc-detail')
|
|
423
|
+
const valid = () => current === generation && sequence === detailSequence && connection.valid()
|
|
424
|
+
const skipped = [], targets = []
|
|
425
|
+
pending = true; updateAllControl(); renderInstalled(); renderedInstalled = ''
|
|
426
|
+
const status = node('p', '正在读取最新插件列表…')
|
|
427
|
+
const cancel = button('取消检查', () => {
|
|
428
|
+
detailSequence++; pending = false; updateAllControl(); area.replaceChildren(); renderInstalled(); renderedInstalled = ''
|
|
429
|
+
})
|
|
430
|
+
area.replaceChildren(status, cancel)
|
|
431
|
+
try {
|
|
432
|
+
await refresh()
|
|
433
|
+
if (!valid()) return
|
|
434
|
+
if (snapshot.busy || !snapshot.writable) throw new Error('主机已有任务或当前环境只读,请稍后重试')
|
|
435
|
+
const revision = snapshot.revision, candidates = []
|
|
436
|
+
for (const item of snapshot.items) {
|
|
437
|
+
let reason = !(item.managed && item.bundle || item.selfUpdate) ? '由主机维护或不是插件'
|
|
438
|
+
: /[:/\\]/.test(item.requested || '') || !item.requested || item.requested.startsWith('.') ? '本地、链接或自定义来源,请单独维护'
|
|
439
|
+
: compareVersions(item.version, item.version) === null ? '已装版本无法比较,请单独维护' : ''
|
|
440
|
+
if (reason) skipped.push(item.name + ':' + reason)
|
|
441
|
+
else candidates.push(item)
|
|
442
|
+
}
|
|
443
|
+
if (candidates.length > 100) throw new Error('插件超过单次批量更新的 100 项上限,请分开维护')
|
|
444
|
+
let checked = 0
|
|
445
|
+
// Each detail request has its own timeout; a large profile does not need one giant HTTP request.
|
|
446
|
+
for (let i = 0; i < candidates.length && valid(); i += 4) await Promise.all(candidates.slice(i, i + 4).map(async item => {
|
|
447
|
+
try {
|
|
448
|
+
const { item: latest } = await api('/details?name=' + encodeURIComponent(item.name))
|
|
449
|
+
if (!valid()) return
|
|
450
|
+
const order = compareVersions(latest?.version, item.version)
|
|
451
|
+
if (latest?.bundle && order !== null && order > 0) targets.push({ name: item.name, version: latest.version })
|
|
452
|
+
else skipped.push(item.name + ':' + (order !== null && order <= 0 ? '当前版本已是最新或高于 latest' : '目标不是可比较的 DSH 插件版本'))
|
|
453
|
+
} catch (error) { if (valid()) skipped.push(item.name + ':检查失败,' + error.message) }
|
|
454
|
+
finally { if (valid()) status.textContent = '正在检查更新:' + (++checked) + '/' + candidates.length }
|
|
455
|
+
}))
|
|
456
|
+
if (!valid()) return
|
|
457
|
+
await refresh()
|
|
458
|
+
if (!valid()) return
|
|
459
|
+
if (snapshot.revision !== revision || snapshot.busy) throw new Error('检查期间插件列表或任务状态已变化,请重新检查')
|
|
460
|
+
targets.sort((a, b) => (a.name === '@hyprnos/dsh-remote-plugin') - (b.name === '@hyprnos/dsh-remote-plugin') || a.name.localeCompare(b.name))
|
|
461
|
+
pending = false; updateAllControl()
|
|
462
|
+
if (!targets.length) {
|
|
463
|
+
area.replaceChildren(node('p', '没有可自动更新的插件。'))
|
|
464
|
+
for (const text of skipped.sort()) area.append(node('p', text))
|
|
465
|
+
return
|
|
466
|
+
}
|
|
467
|
+
await mutate('update-all', 'all-plugins', undefined, { targets, skipped: skipped.sort() })
|
|
468
|
+
} catch (error) {
|
|
469
|
+
if (valid()) area.replaceChildren(node('p', error.message, 'pc-detail-error'), button('重新检查全部更新', updateAll))
|
|
470
|
+
} finally {
|
|
471
|
+
if (valid()) { pending = false; updateAllControl(); renderInstalled(); renderedInstalled = '' }
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
async function mutate(action, name, version, batch) {
|
|
475
|
+
if (pending) return
|
|
476
|
+
const current = generation
|
|
477
|
+
const reviewSequence = ++detailSequence
|
|
478
|
+
// LAN HTTP is not a secure context; an idempotency key does not need WebCrypto.
|
|
479
|
+
const id = globalThis.crypto?.randomUUID?.() || `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`
|
|
480
|
+
const body = { id, action, name, ...(version ? { version } : {}), revision: snapshot.revision }
|
|
481
|
+
if (batch) body.targets = batch.targets
|
|
482
|
+
if (name === '@hyprnos/dsh-remote-plugin' && action === 'update') body.confirmSelfUpdate = true
|
|
483
|
+
if (batch?.targets.some(target => target.name === '@hyprnos/dsh-remote-plugin')) body.confirmSelfUpdate = true
|
|
484
|
+
const area = dialog.querySelector('.pc-detail')
|
|
485
|
+
let plan
|
|
486
|
+
if (['install', 'update', 'remove', 'update-all'].includes(action)) {
|
|
487
|
+
pending = true
|
|
488
|
+
updateAllControl()
|
|
489
|
+
area.replaceChildren(node('p', '正在预检目标版本、锁文件与发布年龄策略…'))
|
|
490
|
+
try {
|
|
491
|
+
const response = await api('/preflight', body)
|
|
492
|
+
if (current !== generation || reviewSequence !== detailSequence) return
|
|
493
|
+
plan = response.plan
|
|
494
|
+
if (!plan?.key) throw new Error('主机未返回可确认的预检计划,请升级主机 Remote 插件')
|
|
495
|
+
if (batch && (!Array.isArray(plan.targets) || !plan.targets.length)) throw new Error('主机未返回完整批量更新列表,请重新检查')
|
|
496
|
+
body.preflightKey = plan.key
|
|
497
|
+
} catch (error) {
|
|
498
|
+
if (current !== generation || reviewSequence !== detailSequence) return
|
|
499
|
+
area.replaceChildren(node('p', error.message, 'pc-detail-error'), button('重新预检', () => mutate(action, name, version, batch)))
|
|
500
|
+
return
|
|
501
|
+
} finally { if (current === generation) { pending = false; updateAllControl(); if (tab !== 'market') { renderInstalled(); renderedInstalled = '' } } }
|
|
502
|
+
}
|
|
503
|
+
if (current !== generation || reviewSequence !== detailSequence || !connection.valid()) return
|
|
504
|
+
const review = card('确认' + labels[action], batch ? '共 ' + plan.targets.length + ' 个插件' : name + (version ? '@' + version : ''))
|
|
505
|
+
if (batch) {
|
|
506
|
+
for (const target of plan.targets) review.append(node('p', target.name + ' · ' + target.fromVersion + ' → ' + target.version))
|
|
507
|
+
review.append(node('p', '逐个更新,遇到失败停止后续项;操作记录显示每项结果。关闭页面后主机继续执行。恢复备份会撤销整批更新。'))
|
|
508
|
+
const skipped = node('details'); skipped.append(node('summary', '未更新的项目(' + batch.skipped.length + ')'))
|
|
509
|
+
for (const text of batch.skipped) skipped.append(node('p', text))
|
|
510
|
+
review.append(skipped)
|
|
511
|
+
}
|
|
512
|
+
review.append(node('p', '目标环境:' + snapshot.profile + '。配置修改后需要重启 DSH;不会自动重启。'))
|
|
513
|
+
if (body.confirmSelfUpdate) review.append(node('p', '更新当前主机的 Remote 插件本体,先备份配置与旧包,后台执行。重启 DSH 后新版本生效,连接可能短暂中断;此操作不会升级手机 App。'))
|
|
514
|
+
const confirm = button('确认' + labels[action], () => { if (reviewSequence === detailSequence) return executeMutation(body) }); confirm.className = action === 'remove' ? 'pc-danger-confirm' : 'pc-primary'
|
|
515
|
+
if (plan) {
|
|
516
|
+
review.append(node('p', '执行前备份全部插件文件和配置;安装后核验配置、锁文件与已安装版本。失败可在操作记录恢复更新前状态。'))
|
|
517
|
+
if (plan.baselineWarning) review.append(node('p', '更新前已存在待修复状态:' + plan.baselineWarning + '。恢复备份会回到这一状态;只有安装后一致性核验通过才会报告完成。', 'pc-detail-error'))
|
|
518
|
+
if (plan.blockers.length) {
|
|
519
|
+
review.append(node('p', '以下版本尚未达到主机要求的 ' + plan.minutes + ' 分钟发布年龄;包含锁文件中可能与本次目标无关的包。'))
|
|
520
|
+
for (const item of plan.blockers) review.append(node('p', item.name + '@' + item.version + ' · 发布于 ' + new Date(item.publishedAt).toLocaleString() + ' · 无需豁免的时间:' + new Date(item.eligibleAt).toLocaleString()))
|
|
521
|
+
}
|
|
522
|
+
if (plan.ruleChanges.length) {
|
|
523
|
+
review.append(node('p', '批准后采用以下精确版本规则,并合并同名重复项:'))
|
|
524
|
+
for (const rule of plan.ruleChanges) review.append(node('p', rule, 'pc-policy-rule'))
|
|
525
|
+
}
|
|
526
|
+
if (plan.blockers.length || plan.ruleChanges.length) {
|
|
527
|
+
const label = node('label', null, 'pc-policy-consent'), checkbox = node('input')
|
|
528
|
+
checkbox.type = 'checkbox'; checkbox.checked = false
|
|
529
|
+
label.append(checkbox, node('span', '我信任以上明确版本,并批准列出的豁免与规则合并。'))
|
|
530
|
+
confirm.disabled = true
|
|
531
|
+
checkbox.addEventListener('change', () => { body.confirmReleasePolicy = checkbox.checked === true; confirm.disabled = !body.confirmReleasePolicy })
|
|
532
|
+
review.append(label, node('p', '不批准也可取消,等待上述版本达到发布年龄后重新预检。'))
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
review.append(confirm, button('取消', () => { detailSequence++; area.replaceChildren() }))
|
|
536
|
+
area.replaceChildren(review); area.scrollIntoView({ block: 'nearest' })
|
|
537
|
+
}
|
|
538
|
+
function reviewRestore(job) {
|
|
539
|
+
const id = globalThis.crypto?.randomUUID?.() || `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-restore`
|
|
540
|
+
const body = { id, action: 'restore', name: job.name, revision: snapshot.revision, restoreFrom: job.id, confirmRestore: true }
|
|
541
|
+
const review = card('确认恢复更新前状态', job.name)
|
|
542
|
+
review.append(node('p', '恢复此任务备份的全部插件文件与配置,撤销本次安装及发布年龄豁免。失败后若有新改动或文件占用,将停止恢复并保留备份。恢复成功后需重启 DSH。'))
|
|
543
|
+
review.append(button('确认恢复', () => executeMutation(body)), button('取消', () => dialog.querySelector('.pc-detail').replaceChildren()))
|
|
544
|
+
dialog.querySelector('.pc-detail').replaceChildren(review)
|
|
545
|
+
}
|
|
546
|
+
async function executeMutation(body, endpoint = '/operations') {
|
|
547
|
+
if (pending) return
|
|
548
|
+
const current = generation
|
|
549
|
+
pending = true
|
|
550
|
+
updateAllControl()
|
|
551
|
+
if (tab !== 'market') { renderInstalled(); renderedInstalled = '' }
|
|
552
|
+
for (const control of dialog.querySelector('.pc-detail').querySelectorAll('button')) control.disabled = true
|
|
553
|
+
try {
|
|
554
|
+
message('正在提交…')
|
|
555
|
+
await api(endpoint, body)
|
|
556
|
+
if (endpoint === '/operations') trackedOperation = body.id
|
|
557
|
+
message('已受理,可在操作记录查看结果。')
|
|
558
|
+
dialog.querySelector('.pc-detail').replaceChildren()
|
|
559
|
+
} catch (error) {
|
|
560
|
+
if (current !== generation) return
|
|
561
|
+
if (error.status === 409 && body.preflightKey) {
|
|
562
|
+
message(error.message)
|
|
563
|
+
dialog.querySelector('.pc-detail').replaceChildren(button('重新预检', () => body.action === 'update-all' ? updateAll() : mutate(body.action, body.name, body.version)))
|
|
564
|
+
return
|
|
565
|
+
}
|
|
566
|
+
message(error.message + ';请先查看操作记录,避免重复提交。')
|
|
567
|
+
const retry = button('重试同一请求', () => executeMutation(body, endpoint))
|
|
568
|
+
dialog.querySelector('.pc-detail').replaceChildren(retry)
|
|
569
|
+
} finally { if (current === generation) { pending = false; await refresh() } }
|
|
570
|
+
}
|
|
571
|
+
function close() {
|
|
572
|
+
window.DshSkillsCenter?.close()
|
|
573
|
+
generation++; searchSequence++; detailSequence++; clearTimeout(timer); expandedDetails.clear()
|
|
574
|
+
if (!dialog) return
|
|
575
|
+
if (dialog.tagName === 'DIALOG') dialog.close()
|
|
576
|
+
else { dialog.open = false; dialog.remove() }
|
|
577
|
+
dialog = null
|
|
578
|
+
}
|
|
579
|
+
function startPolling() {
|
|
580
|
+
clearTimeout(timer)
|
|
581
|
+
const current = generation
|
|
582
|
+
async function poll() {
|
|
583
|
+
if (current !== generation || !dialog?.open) return
|
|
584
|
+
try { await refresh() } catch (error) { if (current === generation) message(error.message) }
|
|
585
|
+
if (current === generation && dialog?.open) timer = setTimeout(poll, 4000)
|
|
586
|
+
}
|
|
587
|
+
timer = setTimeout(poll, 4000)
|
|
588
|
+
}
|
|
589
|
+
function pause() {
|
|
590
|
+
generation++; refreshSequence++; detailSequence++; clearTimeout(timer); pending = false
|
|
591
|
+
if (dialog) { dialog.open = false; dialog.querySelector('.pc-detail').replaceChildren() }
|
|
592
|
+
}
|
|
593
|
+
async function resume() {
|
|
594
|
+
if (!dialog || !connection.valid()) return
|
|
595
|
+
dialog.open = true; const current = ++generation
|
|
596
|
+
try { await refresh() } catch (error) { if (current === generation) message(error.message) }
|
|
597
|
+
if (current === generation && dialog?.open) startPolling()
|
|
598
|
+
}
|
|
599
|
+
async function open(config, target) {
|
|
600
|
+
close()
|
|
601
|
+
if (!dialog) {
|
|
602
|
+
dialog = node(target ? 'div' : 'dialog', null, 'pc-dialog' + (target ? ' pc-page' : ''))
|
|
603
|
+
const heading = node('div', null, 'pc-heading')
|
|
604
|
+
const title = node('div', null, 'pc-title'); title.append(node('h2', '插件管理'), node('p', '管理当前主机的插件与扩展', 'pc-intro')); heading.append(title)
|
|
605
|
+
if (!target) heading.append(button('关闭', close))
|
|
606
|
+
const controls = node('div', null, 'pc-controls')
|
|
607
|
+
const toolbar = node('div', null, 'pc-tabs')
|
|
608
|
+
for (const [value, title] of [['installed', '已安装'], ['market', '添加插件'], ['builtin', '内置插件']]) {
|
|
609
|
+
const control = button(title, () => {
|
|
610
|
+
window.DshSkillsCenter?.close()
|
|
611
|
+
tab = value; detailSequence++; expandedDetails.clear(); renderedInstalled = ''; dialog.querySelector('.pc-detail').replaceChildren()
|
|
612
|
+
renderTabs(); message('')
|
|
613
|
+
updateAllControl()
|
|
614
|
+
dialog.querySelector('.pc-market-tools').hidden = value !== 'market'; dialog.querySelector('.pc-filters').hidden = value === 'market'
|
|
615
|
+
if (value === 'market') { offset = 0; return search() }
|
|
616
|
+
return refresh()
|
|
617
|
+
})
|
|
618
|
+
control.dataset.pcTab = value; toolbar.append(control)
|
|
619
|
+
}
|
|
620
|
+
const refreshButton = button('刷新', () => tab === 'market' ? (offset = 0, search(true)) : refresh()); refreshButton.className = 'pc-refresh'
|
|
621
|
+
const updateAllButton = button('一键更新', updateAll); updateAllButton.className = 'pc-update-all'; updateAllButton.disabled = true
|
|
622
|
+
const toolbarActions = node('div', null, 'pc-toolbar-actions'); toolbarActions.append(updateAllButton, refreshButton)
|
|
623
|
+
const toolbarRow = node('div', null, 'pc-toolbar'); toolbarRow.append(toolbar, toolbarActions)
|
|
624
|
+
const filters = node('div', null, 'pc-filters')
|
|
625
|
+
const query = node('input'); query.placeholder = '筛选已安装插件'; query.setAttribute('aria-label', '筛选已安装插件')
|
|
626
|
+
query.addEventListener('input', () => { filter = query.value.trim(); renderInstalled() })
|
|
627
|
+
const select = node('select'); select.setAttribute('aria-label', '按配置状态筛选')
|
|
628
|
+
for (const [value, title] of [['all', '全部状态'], ['enabled', '配置启用'], ['disabled', '配置停用']]) { const option = node('option', title); option.value = value; select.append(option) }
|
|
629
|
+
select.addEventListener('change', () => { statusFilter = select.value; renderInstalled() })
|
|
630
|
+
filters.append(query, select)
|
|
631
|
+
const market = node('form', null, 'pc-market-tools'); market.hidden = true
|
|
632
|
+
const input = node('input', null, 'pc-search'); input.placeholder = '搜索插件或输入完整 npm 包名'; input.maxLength = 80; input.setAttribute('aria-label', '搜索插件或 npm 包名')
|
|
633
|
+
market.append(input, button('搜索', () => { offset = 0; return search() }), button('按包名查看', () => showDetails(input.value.trim())))
|
|
634
|
+
market.addEventListener('submit', event => {
|
|
635
|
+
event.preventDefault(); offset = 0
|
|
636
|
+
const current = generation
|
|
637
|
+
search().catch(error => { if (current === generation) message(error.message) })
|
|
638
|
+
})
|
|
639
|
+
const jobs = node('details', null, 'pc-history'); jobs.append(node('summary', '操作记录'), node('div', null, 'pc-jobs'))
|
|
640
|
+
const progress = node('section', null, 'pc-progress'); progress.hidden = true; progress.setAttribute('role', 'status'); progress.setAttribute('aria-live', 'polite')
|
|
641
|
+
const alert = node('p', null, 'pc-message'); alert.setAttribute('role', 'status')
|
|
642
|
+
const context = node('div', null, 'pc-context'); context.append(node('p', null, 'pc-profile'), node('div', null, 'pc-summary'))
|
|
643
|
+
controls.append(toolbarRow, filters, market)
|
|
644
|
+
dialog.append(heading, context, node('p', null, 'pc-status'), controls, alert, progress, node('div', null, 'pc-recovery'), node('div', null, 'pc-detail'), node('div', null, 'pc-list'), jobs)
|
|
645
|
+
const surface = dialog
|
|
646
|
+
dialog.addEventListener('close', () => {
|
|
647
|
+
if (dialog !== surface) return
|
|
648
|
+
window.DshSkillsCenter?.close()
|
|
649
|
+
generation++; clearTimeout(timer); dialog = null; surface.remove()
|
|
650
|
+
})
|
|
651
|
+
;(target || document.body).append(dialog)
|
|
652
|
+
}
|
|
653
|
+
generation++; searchSequence++; detailSequence++; marketCompatibility.clear(); marketIndex = ''; marketCategory = ''; marketSort = ''; fetchedAt = null; offset = 0; connection = config; tab = 'installed'; pending = false; snapshot = null; filter = ''; statusFilter = 'all'; trackedOperation = ''; experimentalExpanded = false
|
|
654
|
+
const current = generation
|
|
655
|
+
renderedInstalled = ''; renderedJobs = ''
|
|
656
|
+
dialog.querySelector('.pc-market-tools').hidden = true
|
|
657
|
+
dialog.querySelector('.pc-detail').replaceChildren(); dialog.querySelector('.pc-list').replaceChildren(); dialog.querySelector('.pc-jobs').replaceChildren()
|
|
658
|
+
if (target) dialog.open = true
|
|
659
|
+
else dialog.showModal()
|
|
660
|
+
message('正在读取插件状态…')
|
|
661
|
+
try { await refresh(); message('') } catch (error) { if (current === generation) message(error.message) }
|
|
662
|
+
if (current !== generation) return
|
|
663
|
+
startPolling()
|
|
664
|
+
}
|
|
665
|
+
return { open, mount: (config, target) => open(config, target), close, pause, resume }
|
|
666
|
+
})()
|