@andy.ian/dsh-homing 2.0.0 → 2.0.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/client.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * dsh-homing 的浏览器端:在侧边栏底部放一组守护进程控制按钮。
3
+ *
4
+ * 为什么放在客户端:用户要求用按钮代替命令行,且不要用 PowerShell。
5
+ * 按钮直接调用本机守护进程的控制接口(http://127.0.0.1:8790),
6
+ * 该接口已在 supervisor.mjs 里放行跨端口请求(CORS)。
7
+ *
8
+ * 契约参考 DSH 客户端插件(window.__ModuleLoader__.load + slots 注册)。
9
+ */
10
+ window.__ModuleLoader__.load({
11
+ id: '@andy.ian/dsh-homing',
12
+ factory(require) {
13
+ const React = require('react')
14
+ const h = React.createElement
15
+
16
+ const CONTROL = 'http://127.0.0.1:8790'
17
+
18
+ async function call(pathname) {
19
+ const res = await fetch(CONTROL + pathname, { method: 'POST' })
20
+ return res.json()
21
+ }
22
+
23
+ function Controls() {
24
+ const [notice, setNotice] = React.useState('')
25
+ const [busy, setBusy] = React.useState(false)
26
+
27
+ async function run(pathname, text) {
28
+ if (busy) return
29
+ setBusy(true)
30
+ try {
31
+ await call(pathname)
32
+ setNotice(text)
33
+ } catch (error) {
34
+ setNotice('守护进程未运行')
35
+ } finally {
36
+ setBusy(false)
37
+ setTimeout(() => setNotice(''), 4000)
38
+ }
39
+ }
40
+
41
+ const button = (label, title, pathname, text) => h('button', {
42
+ type: 'button',
43
+ title,
44
+ disabled: busy,
45
+ onClick: () => void run(pathname, text),
46
+ style: {
47
+ background: 'transparent',
48
+ border: '1px solid rgba(255,255,255,.18)',
49
+ borderRadius: '6px',
50
+ color: 'inherit',
51
+ cursor: busy ? 'default' : 'pointer',
52
+ fontSize: '12px',
53
+ padding: '4px 8px',
54
+ },
55
+ }, label)
56
+
57
+ return h('div', { style: { display: 'flex', gap: '6px', alignItems: 'center', padding: '4px 8px' } },
58
+ button('⏻', '重启 DSH(等空闲)', '/restart?mode=default', '已请求重启'),
59
+ button('⚡', '立即重启 DSH', '/restart?mode=immediate', '已请求立即重启'),
60
+ button('⏸', '暂停自动拉起 30 分钟', '/pause?minutes=30', '已暂停 30 分钟'),
61
+ button('▶', '恢复自动拉起', '/resume', '已恢复'),
62
+ button('⏹', '停止守护进程(不再拉起)', '/stop', '守护进程已退出'),
63
+ notice ? h('span', { style: { fontSize: '11px', opacity: 0.7 } }, notice) : null,
64
+ )
65
+ }
66
+
67
+ return {
68
+ name: 'ui-dsh-homing',
69
+ inject: ['slots'],
70
+ apply(ctx) {
71
+ const dispose = ctx.slots.inject('sidebar.footer.action', () => ctx.slots.register(
72
+ { name: 'sidebar.footer.action', id: 'dsh-homing', order: 11 },
73
+ Controls,
74
+ ))
75
+ if (typeof ctx.effect === 'function') ctx.effect(() => dispose, 'dsh-homing: sidebar controls')
76
+ },
77
+ }
78
+ },
79
+ })
package/cordis.patch.yml CHANGED
@@ -1,4 +1,4 @@
1
- # dsh-mobile:把本机 DSH 开放给手机/微信(随 DSH 启动)
1
+ # dsh-homing:把本机 DSH 开放给手机/微信(随 DSH 启动)
2
2
  #
3
3
  # 配置说明:
4
4
  # serverHost 云服务器 IP(留空则只在本机/局域网提供服务,不起隧道)
@@ -9,14 +9,14 @@
9
9
  # bindAddress 本机监听地址;'::' 表示局域网 + 回环都监听(默认)
10
10
  # publicUrl 手机通过公网访问的入口,只用于启动日志
11
11
  # funcValue 入口暗号:必须带 ?func=<这个值>,留空则关闭该闸门
12
- # login 是否要求用户名密码登录(账号密码存在 $DSH_HOME/integrations/dsh-mobile/auth.json)
12
+ # login 是否要求用户名密码登录(账号密码存在 $DSH_HOME/integrations/dsh-homing/auth.json)
13
13
  # tls 'auto' = 自动生成自签证书(局域网也是 HTTPS);'files' = 用 tlsCert/tlsKey;'off' = 明文(仅本机调试)
14
14
  # tlsCert/tlsKey tls=files 时的证书与私钥路径
15
15
  - insert:
16
- - id: dsh-mobile
16
+ - id: dsh-homing
17
17
  name: '@andy.ian/dsh-homing'
18
18
  config:
19
- serverHost: '' # 服务器地址建议写在 $DSH_HOME/integrations/dsh-mobile/settings.json,改完自动重连
19
+ serverHost: '' # 服务器地址建议写在 $DSH_HOME/integrations/dsh-homing/settings.json,改完自动重连
20
20
  sshUser: ubuntu
21
21
  sshPort: 22
22
22
  sshKey: ''