dsh-pick 0.3.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-pick",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "帮你在 DSH 生态里选对插件:说需求 → 找候选 → 多维比较 → 出结论。下载量是证据,AI 是推理。",
5
5
  "type": "module",
6
6
  "main": "./plugin/index.js",
package/plugin/client.js CHANGED
@@ -59,6 +59,36 @@ window.__ModuleLoader__.load({
59
59
  }, children)
60
60
  }
61
61
 
62
+ /** 一条给用户自己在终端执行的命令:等宽显示,旁边一个「复制」 */
63
+ function CommandLine({ command }) {
64
+ const [copied, setCopied] = useState(false)
65
+ const copy = async () => {
66
+ try {
67
+ await navigator.clipboard.writeText(command)
68
+ } catch {
69
+ // 剪贴板不让用(非安全上下文等):退回到选中后 execCommand
70
+ const ta = document.createElement('textarea')
71
+ ta.value = command
72
+ ta.style.position = 'fixed'
73
+ ta.style.opacity = '0'
74
+ document.body.appendChild(ta)
75
+ ta.select()
76
+ try { document.execCommand('copy') } catch { /* 实在不行用户还能手动选 */ }
77
+ ta.remove()
78
+ }
79
+ setCopied(true)
80
+ setTimeout(() => setCopied(false), 2000)
81
+ }
82
+ return h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, marginTop: 6, flexWrap: 'wrap' } },
83
+ h('code', {
84
+ style: {
85
+ flex: '1 1 auto', minWidth: 0, padding: '4px 8px', borderRadius: 6, fontSize: 12, color: C.text,
86
+ border: '1px solid ' + C.border, userSelect: 'all', overflowWrap: 'anywhere',
87
+ },
88
+ }, command),
89
+ h(Btn, { onClick: copy }, copied ? L('已复制', 'Copied') : L('复制', 'Copy')))
90
+ }
91
+
62
92
  /** 标题行:dsh-pick · 版本号 · 更新 ……(最右)卸载 */
63
93
  function HeaderBar() {
64
94
  const [info, setInfo] = useState(null)
@@ -132,7 +162,7 @@ window.__ModuleLoader__.load({
132
162
  ),
133
163
  msg ? h('div', { style: { fontSize: 12, color: C.danger, marginTop: 6, lineHeight: 1.6 } },
134
164
  msg.text,
135
- msg.command ? h('code', { style: { display: 'block', marginTop: 4, color: C.text, userSelect: 'all' } }, msg.command) : null,
165
+ msg.command ? h(CommandLine, { command: msg.command }) : null,
136
166
  ) : null,
137
167
  )
138
168
  }
package/plugin/index.js CHANGED
@@ -95,6 +95,20 @@ function pluginCommand(args, profile) {
95
95
  }
96
96
 
97
97
  /** 插件管理器的失败结果 → 一行人话(取诊断输出的最后几行) */
98
+ /** 插件管理器失败结果里的错误码(没失败返回空串) */
99
+ function managerCode(result) {
100
+ if (!(result && (result.application === 'failed' || result.application === 'cancelled' || result.error))) return ''
101
+ return (result.error && result.error.code) || result.application || 'failed'
102
+ }
103
+
104
+ /**
105
+ * 官方桌面版(0.2.1-rc.2 实测)的插件管理器不能在运行中升级已装的插件:installBundle 一律答
106
+ * already-installed(插件市场的「更新」也栽在这里)。只能退出 DSH、在终端用 dsh plugin 装
107
+ */
108
+ const ALREADY_INSTALLED_HINT =
109
+ '这个版本的 DSH 不能在运行中升级已装的插件。请完全退出 DSH(Mac 上按 Cmd+Q,不是关窗口),' +
110
+ '在终端执行下面的命令,再重新打开 DSH。如果提示版本太新(发布不满 1 天),过一天再执行。'
111
+
98
112
  function managerError(result) {
99
113
  if (!(result && (result.application === 'failed' || result.application === 'cancelled' || result.error))) return ''
100
114
  const code = (result.error && result.error.code) || result.application || 'failed'
@@ -265,10 +279,12 @@ export function apply(ctx) {
265
279
  }
266
280
  try {
267
281
  const result = await pluginManager.installBundle(`${PACKAGE}@${latest}`, { enabled: true })
282
+ if (managerCode(result) === 'already-installed') return sendJson(res, 200, { ok: false, message: ALREADY_INSTALLED_HINT, command })
268
283
  const err = managerError(result)
269
284
  if (err) return sendJson(res, 200, { ok: false, message: `更新失败(${err})`, command })
270
285
  return sendJson(res, 200, { ok: true, version: latest })
271
286
  } catch (e) {
287
+ if (e && e.code === 'already-installed') return sendJson(res, 200, { ok: false, message: ALREADY_INSTALLED_HINT, command })
272
288
  return sendJson(res, 200, { ok: false, message: `更新失败:${e.message}`, command })
273
289
  }
274
290
  },