@karoy/dsh-wsl-desktop 0.1.2 → 0.1.3

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 CHANGED
@@ -13,7 +13,8 @@
13
13
  启用的 → 安装并启用;禁用的 → 安装但保持禁用;配置行(id/name/enabled/config)同步;
14
14
  3. **不启动应用**。
15
15
  - **点左下角「从WSL打开」**:启动 proxy 版桌面窗口(环境已就绪,秒级)。
16
- - **副本已在 WSL 模式运行时**:入口变为不可点击的「WSL模式」(依据副本启动时写入的 `.dsh-wsl-running.json` 标记 + 进程存活、24h 内判定,而不是只看进程名)。
16
+ - **副本已在运行时**:入口显示「WSL 窗口运行中」,仍可点击——点击会把已打开的 WSL 窗口带到前台
17
+ (副本再次启动触发 Electron 单实例聚焦)。当前窗口本身不会变成 WSL,切换只发生在副本里。
17
18
  - 之后每次启动都不再同步,**WSL 侧手动启停的插件一直保持**。
18
19
 
19
20
  命令只作兜底:
@@ -26,7 +27,10 @@
26
27
  | `/wsl-desktop-setup` | 手动重建副本 |
27
28
  | `/wsl-desktop-remove` | 删除副本与独立 Electron profile |
28
29
 
29
- ## 配置(profile patch 的 `config`,留空按默认)
30
+ ## 配置
31
+
32
+ 安装后可在 Web 侧栏 **Plugins → `@karoy/dsh-wsl-desktop` → 行 `wsl-desktop` 的「配置」** 里改;保存会写回
33
+ profile 的 `cordis.patch.yml`,改动会重启插件。也可以直接写 profile patch 的 `config`(留空按默认)。
30
34
 
31
35
  - `mode`: `"proxy"`(默认,保留桌面外壳)|`"direct"`(主窗口直接加载 WSL 页面)
32
36
  - `installDir`:可选覆盖;默认 `%LOCALAPPDATA%\DeepSeek Harness WSL Desktop`(不写死盘符)
@@ -61,6 +65,9 @@
61
65
 
62
66
  ## 限制
63
67
 
68
+ - 「从WSL打开」不会把当前窗口切换成 WSL:原窗口的 Host 地址在启动时就固定了(`app.asar/lib/main.js`
69
+ 的模块作用域变量),插件改不了它;只有另起的补丁副本是 WSL 的。副本运行后入口显示
70
+ 「WSL 窗口运行中」,点击只负责把它带到前台。
64
71
  - proxy 模式的工作区选择等目录操作走 WSL Host 的 browse 选择器(外壳的原生目录对话框
65
72
  未接到 WSL 侧);「应用/编辑」菜单与窗口外壳保留。
66
73
  - 会话、凭据、工作区都是 WSL 自己的;WSL 的 `~/.dsh` 与 Windows 的互不相干。
package/bin/auto.mjs CHANGED
@@ -106,11 +106,12 @@ try {
106
106
  steps.push('environment already initialized (no sync)')
107
107
  }
108
108
 
109
- if (config.autoLaunch !== false && !running) {
109
+ if (config.autoLaunch !== false) {
110
+ // Launching while the copy already runs hits its single-instance lock and
111
+ // focuses the existing window; that is how the footer brings an open WSL
112
+ // window back to the foreground.
110
113
  const pid = spawnCopy(config)
111
- steps.push('launched pid=' + String(pid))
112
- } else if (config.autoLaunch !== false && running) {
113
- steps.push('launch skipped: copy is running')
114
+ steps.push((running ? 'focused existing copy pid=' : 'launched pid=') + String(pid))
114
115
  } else {
115
116
  steps.push('copy not started (start it from the button or /wsl-desktop-launch)')
116
117
  }
package/client.js CHANGED
@@ -2,9 +2,11 @@
2
2
  * Client half: a bottom-left footer entry (above Settings) that asks the Host to
3
3
  * build/refresh the WSL Desktop proxy copy and launch it.
4
4
  *
5
- * Once the copy reports it is actually bound to the WSL Host (marker written by
6
- * its patched main.js), the entry shows the disabled "WSL模式" label. While the
7
- * copy is still starting it shows "启动中…" and stays disabled.
5
+ * Once the copy is actually running, the entry shows "WSL 窗口运行中" and stays
6
+ * clickable: a second launch of the copy hits its single-instance lock and
7
+ * brings the open WSL window to the front. The current window never becomes the
8
+ * WSL one — its Host address is fixed at startup — so the entry must not claim
9
+ * "WSL mode" for it.
8
10
  *
9
11
  * @module @karoy/dsh-wsl-desktop/client
10
12
  */
@@ -20,8 +22,7 @@ window.__ModuleLoader__.load({
20
22
  cursor:pointer;opacity:.85;white-space:nowrap;transition:opacity .12s,background .12s}
21
23
  .dsh-wsl-desktop-footer[data-wide=true]{justify-content:flex-start;padding:0 10px}
22
24
  .dsh-wsl-desktop-footer:hover{opacity:1;background:color-mix(in srgb,currentColor 10%,transparent)}
23
- .dsh-wsl-desktop-footer[data-state=mode]{opacity:.6;cursor:default;background:transparent}
24
- .dsh-wsl-desktop-footer[data-state=starting]{opacity:.6;cursor:default;background:transparent}
25
+ .dsh-wsl-desktop-footer[data-state=running]{opacity:.9}
25
26
  .dsh-wsl-desktop-footer:focus-visible{outline:2px solid color-mix(in srgb,currentColor 45%,transparent);outline-offset:2px}
26
27
  .dsh-wsl-desktop-footer:disabled{opacity:.45;cursor:default}
27
28
  .dsh-wsl-desktop-footer[data-state=error]{color:#e5534b}
@@ -37,14 +38,11 @@ window.__ModuleLoader__.load({
37
38
  h('path', { d: 'M4.4 5.2l1.8 1.5-1.8 1.5M7.8 8.2h2.6' }))
38
39
  }
39
40
 
40
- /** Host state: `running` = copy process alive, `wslMode` = it proved WSL binding. */
41
+ /** Host state: `running` = the copy process is alive (a separate WSL window). */
41
42
  async function readState() {
42
43
  const res = await fetch('/wsl-desktop/state', { headers: { accept: 'application/json' } })
43
44
  const data = await res.json().catch(() => null)
44
- return {
45
- running: data?.ok === true && data.running === true,
46
- wslMode: data?.ok === true && data.wslMode === true,
47
- }
45
+ return { running: data?.ok === true && data.running === true }
48
46
  }
49
47
 
50
48
  async function openDesktop() {
@@ -65,10 +63,10 @@ window.__ModuleLoader__.load({
65
63
  function WslDesktopFooter({ wide }) {
66
64
  const [state, setState] = React.useState('idle')
67
65
  const [detail, setDetail] = React.useState('')
68
- const [copy, setCopy] = React.useState({ running: false, wslMode: false })
66
+ const [copy, setCopy] = React.useState({ running: false })
69
67
 
70
68
  const reveal = () => {
71
- readState().then(setCopy, () => setCopy({ running: false, wslMode: false }))
69
+ readState().then(setCopy, () => setCopy({ running: false }))
72
70
  }
73
71
 
74
72
  React.useEffect(() => {
@@ -82,7 +80,7 @@ window.__ModuleLoader__.load({
82
80
  }
83
81
  }, [])
84
82
 
85
- const busy = state === 'busy' || copy.running
83
+ const busy = state === 'busy'
86
84
  const onClick = () => {
87
85
  if (busy) return
88
86
  setState('busy')
@@ -101,23 +99,19 @@ window.__ModuleLoader__.load({
101
99
  )
102
100
  }
103
101
 
104
- const label = copy.wslMode
105
- ? 'WSL模式'
106
- : copy.running
107
- ? '启动中…'
108
- : state === 'busy'
109
- ? '准备中'
110
- : state === 'error'
111
- ? '启动失败'
112
- : '从WSL打开'
113
- const title = copy.wslMode
114
- ? '当前 WSL 桌面已在运行(WSL 模式)'
115
- : copy.running
116
- ? 'WSL 桌面正在启动…'
102
+ const label = copy.running
103
+ ? 'WSL 窗口运行中'
104
+ : state === 'busy'
105
+ ? '准备中'
117
106
  : state === 'error'
118
- ? `启动失败:${detail}`
119
- : '在 WSL 中打开 DSH 桌面窗口(构建/同步 WSL Host 并启动副本)'
120
- const buttonState = copy.wslMode ? 'mode' : copy.running ? 'starting' : state === 'error' ? 'error' : state
107
+ ? '启动失败'
108
+ : '从WSL打开'
109
+ const title = copy.running
110
+ ? 'WSL 窗口已在运行,点击把它带到前台'
111
+ : state === 'error'
112
+ ? `启动失败:${detail}`
113
+ : '在 WSL 中打开 DSH 桌面窗口(另起副本;当前窗口不会切换)'
114
+ const buttonState = copy.running ? 'running' : state === 'error' ? 'error' : state
121
115
 
122
116
  return h(React.Fragment, null,
123
117
  h('style', null, CSS),
@@ -133,6 +127,122 @@ window.__ModuleLoader__.load({
133
127
  }, h(DesktopIcon, { size: 15 }), wide ? h('span', null, label) : null))
134
128
  }
135
129
 
130
+ const SETTINGS_CSS = `
131
+ .dsh-wsl-settings{display:flex;flex-direction:column;gap:14px;font-size:13px}
132
+ .dsh-wsl-settings-row{display:flex;align-items:center;justify-content:space-between;gap:16px}
133
+ .dsh-wsl-settings-label{display:flex;flex-direction:column;gap:2px}
134
+ .dsh-wsl-settings-label small{color:color-mix(in srgb,currentColor 60%,transparent);font-size:12px}
135
+ .dsh-wsl-settings input[type=text],.dsh-wsl-settings input[type=number],.dsh-wsl-settings select{width:220px;padding:4px 8px;border-radius:6px;border:1px solid color-mix(in srgb,currentColor 25%,transparent);background:transparent;color:inherit;font:inherit}
136
+ .dsh-wsl-settings-actions{display:flex;gap:8px;justify-content:flex-end}
137
+ .dsh-wsl-settings button{padding:4px 12px;border-radius:6px;border:1px solid color-mix(in srgb,currentColor 25%,transparent);background:transparent;color:inherit;font:inherit;cursor:pointer}
138
+ .dsh-wsl-settings button[data-primary=true]{background:color-mix(in srgb,currentColor 12%,transparent)}
139
+ .dsh-wsl-settings button:disabled{opacity:.45;cursor:default}
140
+ .dsh-wsl-settings .dsh-wsl-settings-note{color:#e5534b;font-size:12px;margin:0}
141
+ `
142
+
143
+ const SETTINGS_FIELDS = [
144
+ { key: 'mode', label: '模式', help: 'proxy 保留桌面外壳;direct 主窗口直接加载 WSL 页面', kind: 'select', options: [['proxy', 'proxy'], ['direct', 'direct']] },
145
+ { key: 'port', label: '端口', help: 'WSL 内 DSH Host 的端口', kind: 'number', min: 1, max: 65535 },
146
+ { key: 'distro', label: '发行版', help: '留空使用 WSL 默认发行版', kind: 'text' },
147
+ { key: 'autoInstall', label: '自动安装运行时', help: 'WSL 缺少 Node/DSH 时自动安装', kind: 'boolean' },
148
+ { key: 'autoSetup', label: '自动准备副本', help: '副本缺失、模式变化或 Desktop 升级时重建', kind: 'boolean' },
149
+ { key: 'autoRun', label: '启动时自动准备', help: 'DSH 启动后自动跑一次准备(不启动窗口)', kind: 'boolean' },
150
+ { key: 'autoLaunch', label: '准备后自动启动', help: '准备完成后直接打开 WSL 窗口', kind: 'boolean' },
151
+ { key: 'syncWslPlugins', label: '同步插件', help: '首次初始化时把 Windows 插件镜像到 WSL', kind: 'boolean' },
152
+ { key: 'syncLinked', label: '同步 link 插件', help: '包含 link: 安装的插件(默认跳过)', kind: 'boolean' },
153
+ { key: 'autoDelayMs', label: '准备延迟 (ms)', help: 'DSH 启动后等待多久开始准备', kind: 'number', min: 0 },
154
+ { key: 'installDir', label: '副本目录', help: '留空使用 %LOCALAPPDATA%\\DeepSeek Harness WSL Desktop', kind: 'text' },
155
+ { key: 'userDataDirName', label: 'Electron profile 名', help: '副本使用的独立 userData 目录名', kind: 'text' },
156
+ ]
157
+
158
+ const SETTINGS_ROW_KEY = '@karoy/dsh-wsl-desktop#wsl-desktop'
159
+
160
+ /**
161
+ * The row's configuration page on the Plugins page: the Host owns the values
162
+ * and writes them into the profile patch through the form it hands over.
163
+ */
164
+ function WslDesktopSettings(props) {
165
+ const form = props.form
166
+ const state = form?.state
167
+ const value = state?.value
168
+ const [draft, setDraft] = React.useState(null)
169
+ const [saving, setSaving] = React.useState(false)
170
+ const [error, setError] = React.useState('')
171
+
172
+ React.useEffect(() => {
173
+ if (value !== undefined) setDraft({ ...value })
174
+ }, [value])
175
+
176
+ if (props.view === 'summary') return 'WSL 桌面配置:模式、端口、自动准备与插件同步'
177
+
178
+ if (form === undefined || state === undefined) {
179
+ return h('p', { className: 'dsh-wsl-settings-note' }, '配置暂不可用:Host 没有提供 wsl-desktop 命名空间')
180
+ }
181
+ if (state.status === 'loading' || draft === null || value === undefined) return h('p', null, '读取配置…')
182
+
183
+ const writable = state.writable
184
+ const dirty = JSON.stringify(draft) !== JSON.stringify(value)
185
+ const disabled = !writable || saving
186
+ const ops = []
187
+ for (const key of Object.keys(value)) {
188
+ if (JSON.stringify(draft[key]) !== JSON.stringify(value[key])) ops.push({ op: 'set', path: [key], value: draft[key] })
189
+ }
190
+
191
+ const save = async () => {
192
+ if (ops.length === 0) return
193
+ setSaving(true)
194
+ setError('')
195
+ try {
196
+ const accepted = await form.mutate(ops, state.revision)
197
+ if (!accepted) setError('保存被宿主拒绝:值未通过校验,或配置在读取后被改动')
198
+ } catch (thrown) {
199
+ setError(thrown instanceof Error ? thrown.message : String(thrown))
200
+ } finally {
201
+ setSaving(false)
202
+ }
203
+ }
204
+
205
+ const rows = SETTINGS_FIELDS.map((field) => {
206
+ const current = draft[field.key]
207
+ const id = 'wsl-desktop-' + field.key
208
+ let control
209
+ if (field.kind === 'boolean') {
210
+ control = h('input', {
211
+ id, type: 'checkbox', checked: current === true, disabled,
212
+ onChange: (event) => setDraft({ ...draft, [field.key]: event.target.checked }),
213
+ })
214
+ } else if (field.kind === 'select') {
215
+ control = h('select', {
216
+ id, value: current ?? '', disabled,
217
+ onChange: (event) => setDraft({ ...draft, [field.key]: event.target.value }),
218
+ }, field.options.map(([option, label]) => h('option', { key: option, value: option }, label)))
219
+ } else {
220
+ control = h('input', {
221
+ id, type: field.kind === 'number' ? 'number' : 'text',
222
+ value: current ?? '', disabled, min: field.min, max: field.max,
223
+ onChange: (event) => setDraft({
224
+ ...draft,
225
+ [field.key]: field.kind === 'number' ? Number(event.target.value) : event.target.value,
226
+ }),
227
+ })
228
+ }
229
+ return h('div', { className: 'dsh-wsl-settings-row', key: field.key },
230
+ h('label', { className: 'dsh-wsl-settings-label', htmlFor: id },
231
+ h('span', null, field.label),
232
+ field.help ? h('small', null, field.help) : null),
233
+ control)
234
+ })
235
+
236
+ return h('div', { className: 'dsh-wsl-settings' },
237
+ h('style', null, SETTINGS_CSS),
238
+ ...rows,
239
+ error === '' ? null : h('p', { className: 'dsh-wsl-settings-note' }, error),
240
+ writable ? null : h('p', { className: 'dsh-wsl-settings-note' }, '当前 profile 的配置是只读的'),
241
+ h('div', { className: 'dsh-wsl-settings-actions' },
242
+ h('button', { type: 'button', disabled: disabled || !dirty, onClick: () => setDraft({ ...value }) }, '还原'),
243
+ h('button', { type: 'button', 'data-primary': 'true', disabled: disabled || !dirty, onClick: save }, saving ? '保存中…' : '保存')))
244
+ }
245
+
136
246
  return {
137
247
  inject: ['slots'],
138
248
  apply(ctx) {
@@ -141,6 +251,10 @@ window.__ModuleLoader__.load({
141
251
  id: 'wsl-desktop',
142
252
  order: 4,
143
253
  }, WslDesktopFooter))
254
+ ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
255
+ name: 'plugins.row.config',
256
+ key: SETTINGS_ROW_KEY,
257
+ }, WslDesktopSettings))
144
258
  },
145
259
  }
146
260
  },
package/index.js CHANGED
@@ -12,6 +12,7 @@ import fs from 'node:fs'
12
12
  import os from 'node:os'
13
13
  import path from 'node:path'
14
14
  import { fileURLToPath } from 'node:url'
15
+ import z from '@deepseek-ai/schemastery'
15
16
  import { remove, resolveConfig, setup, status } from './lib/setup.js'
16
17
  import { needsBuild, readStatus } from './lib/state.js'
17
18
  import { spawnCopy } from './lib/launch.js'
@@ -20,6 +21,26 @@ import { syncPlugins } from './lib/sync.js'
20
21
 
21
22
  export const inject = ['commands', 'webServer']
22
23
 
24
+ /**
25
+ * Row configuration, editable from the Plugins page (settings namespace
26
+ * `wsl-desktop`). The profile patch supplies the defaults below; a saved edit
27
+ * restarts this plugin, so `apply` re-reads the new values.
28
+ */
29
+ export const Config = z.object({
30
+ mode: z.union([z.const('proxy'), z.const('direct')]).default('proxy'),
31
+ port: z.number().default(3080),
32
+ distro: z.string().default(''),
33
+ autoInstall: z.boolean().default(true),
34
+ autoRun: z.boolean().default(true),
35
+ autoSetup: z.boolean().default(true),
36
+ autoLaunch: z.boolean().default(false),
37
+ syncWslPlugins: z.boolean().default(true),
38
+ syncLinked: z.boolean().default(false),
39
+ autoDelayMs: z.number().default(4000),
40
+ installDir: z.string().default(''),
41
+ userDataDirName: z.string().default('DeepSeek Harness WSL'),
42
+ })
43
+
23
44
  let scheduled = false
24
45
  let runningCache = { at: 0, value: false }
25
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karoy/dsh-wsl-desktop",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Install and launch a DSH Desktop copy whose Electron shell proxies its Host connection to a DSH Host running inside WSL",
5
5
  "keywords": [
6
6
  "dsh",
@@ -61,6 +61,7 @@
61
61
  "@deepseek-ai/cordis": "*"
62
62
  },
63
63
  "dependencies": {
64
+ "@deepseek-ai/schemastery": "^3.19.0",
64
65
  "@electron/asar": "^4.0.1",
65
66
  "yaml": "^2.8.1"
66
67
  }