dsh-lazy-mount 1.2.0 → 1.3.0

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.
Files changed (3) hide show
  1. package/client.js +8 -54
  2. package/index.js +16 -37
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -2,8 +2,8 @@
2
2
  * dsh-lazy-mount — Client 端
3
3
  *
4
4
  * Settings 里的「懒加载」页:
5
- * Tab 1「插件」 — 未排除的插件,可开关懒加载,每行有排除按钮
6
- * Tab 2「已排除」 — 被排除的插件,可恢复
5
+ * Tab 1「插件」 — 可开关懒加载
6
+ * Tab 2「白名单」 — 不能懒加载的插件,可解除,也可手动输入包名加入
7
7
  *
8
8
  * 开关后列表位置不变(Host 端用 config.order 保序)。
9
9
  */
@@ -253,7 +253,7 @@ window.__ModuleLoader__.load({
253
253
 
254
254
  const [loading, setLoading] = useState(true)
255
255
  const [error, setError] = useState('')
256
- const [config, setConfig] = useState({ lazyPackages: [], excludedPackages: [] })
256
+ const [config, setConfig] = useState({ lazyPackages: [] })
257
257
  const [bundles, setBundles] = useState([])
258
258
  const [installed, setInstalled] = useState([])
259
259
  const [busy, setBusy] = useState('')
@@ -270,7 +270,7 @@ window.__ModuleLoader__.load({
270
270
  setError('')
271
271
  try {
272
272
  const data = await apiGet('/state')
273
- setConfig(data.config ?? { lazyPackages: [], excludedPackages: [] })
273
+ setConfig(data.config ?? { lazyPackages: [] })
274
274
  setBundles(Array.isArray(data.bundles) ? data.bundles : [])
275
275
  setInstalled(Array.isArray(data.installed) ? data.installed : [])
276
276
  setKnownIncompatible(Array.isArray(data.knownIncompatible) ? data.knownIncompatible : [])
@@ -318,23 +318,6 @@ window.__ModuleLoader__.load({
318
318
  [reload],
319
319
  )
320
320
 
321
- const exclude = useCallback(
322
- async (pkgName, wantExcluded) => {
323
- setBusy(pkgName)
324
- setError('')
325
- try {
326
- const r = await apiPost('/exclude', { package: pkgName, excluded: wantExcluded })
327
- setToast(r.message ?? '已保存')
328
- await reload()
329
- } catch (e) {
330
- setError(String(e?.message ?? e))
331
- } finally {
332
- setBusy('')
333
- }
334
- },
335
- [reload],
336
- )
337
-
338
321
  const lazySet = useMemo(
339
322
  () => new Set(Array.isArray(config.lazyPackages) ? config.lazyPackages : []),
340
323
  [config.lazyPackages],
@@ -382,9 +365,6 @@ window.__ModuleLoader__.load({
382
365
  }, [draftPkg, noLazySet, setNoLazy])
383
366
  const bundleSet = useMemo(() => new Set(bundles), [bundles])
384
367
 
385
- // 按 excluded 分组,保持 Host 给的顺序(= config.order 稳定序)
386
- const mainRows = useMemo(() => installed.filter((p) => !p.excluded), [installed])
387
- const excludedRows = useMemo(() => installed.filter((p) => p.excluded), [installed])
388
368
  // 白名单页签:既包含已装插件里被拉黑的,也包含只存在于配置里的包名
389
369
  // (后者可能已卸载或不在 bundles,仍要能看到并解除)
390
370
  const noLazyRows = useMemo(() => {
@@ -399,7 +379,7 @@ window.__ModuleLoader__.load({
399
379
  if (loading) return h('div', { style: S.wrap }, '加载中…')
400
380
 
401
381
  const delaySec = Math.round((config.delayMs ?? 5000) / 1000)
402
- const rows = tab === 'main' ? mainRows : tab === 'excluded' ? excludedRows : noLazyRows
382
+ const rows = tab === 'main' ? installed : noLazyRows
403
383
 
404
384
  const renderRow = (p) => {
405
385
  const isLazy = lazySet.has(p.name)
@@ -421,7 +401,6 @@ window.__ModuleLoader__.load({
421
401
  else if (inBundles) meta = '正常启动 · 未加载'
422
402
  else meta = '未启用'
423
403
  }
424
- const isExcludedTab = tab === 'excluded'
425
404
  const isNoLazyTab = tab === 'noLazy'
426
405
 
427
406
  const initial = String(p.displayName || p.name).replace(/^@/, '').charAt(0).toUpperCase()
@@ -473,20 +452,6 @@ window.__ModuleLoader__.load({
473
452
  )
474
453
  : null,
475
454
  ),
476
- // 排除 / 恢复按钮(白名单页签不显示,那里只有「解除」)
477
- isNoLazyTab
478
- ? null
479
- : h(
480
- 'button',
481
- {
482
- type: 'button',
483
- disabled: isBusy,
484
- style: S.iconBtn,
485
- title: isExcludedTab ? '恢复到常用列表' : '从常用列表排除',
486
- onClick: () => void exclude(p.name, !isExcludedTab),
487
- },
488
- isExcludedTab ? '恢复' : '排除',
489
- ),
490
455
  // 白名单按钮:把「此插件不能懒加载」的结论写进 config.noLazyPackages
491
456
  noLazySet.has(p.name)
492
457
  ? h(
@@ -545,7 +510,7 @@ window.__ModuleLoader__.load({
545
510
  'p',
546
511
  { style: S.hint },
547
512
  `打开开关的插件不在启动时加载,DSH 启动后 ${delaySec} 秒自动挂载,改动需重启 DSH 生效。` +
548
- `「排除」只是不在这里显示;「禁止懒加载」是硬约束,写进白名单后该插件永远不会被设为懒加载。`,
513
+ `「禁止懒加载」是硬约束,写进白名单后该插件永远不会被设为懒加载。`,
549
514
  ),
550
515
 
551
516
  // Tab
@@ -559,16 +524,7 @@ window.__ModuleLoader__.load({
559
524
  style: tab === 'main' ? S.tabActive : S.tab,
560
525
  onClick: () => setTab('main'),
561
526
  },
562
- `插件 (${mainRows.length})`,
563
- ),
564
- h(
565
- 'button',
566
- {
567
- type: 'button',
568
- style: tab === 'excluded' ? S.tabActive : S.tab,
569
- onClick: () => setTab('excluded'),
570
- },
571
- `已排除 (${excludedRows.length})`,
527
+ `插件 (${installed.length})`,
572
528
  ),
573
529
  h(
574
530
  'button',
@@ -633,9 +589,7 @@ window.__ModuleLoader__.load({
633
589
  { style: S.empty },
634
590
  tab === 'main'
635
591
  ? '没有插件'
636
- : tab === 'excluded'
637
- ? '没有已排除的插件'
638
- : '白名单为空 —— 可在上方输入包名,或在插件页签点「禁止懒加载」',
592
+ : '白名单为空 —— 可在上方输入包名,或在插件页签点「禁止懒加载」',
639
593
  )
640
594
  : rows.map(renderRow),
641
595
  ),
package/index.js CHANGED
@@ -104,14 +104,18 @@ function logDir(profileDir) {
104
104
 
105
105
  /**
106
106
  * 懒加载配置。
107
- * 结构:{ version: 1, lazyPackages: string[], delayMs, timeoutMs, logRetainDays }
107
+ * 结构:{ version: 2, lazyPackages: string[], noLazyPackages: string[],
108
+ * everLazyPackages: string[], order: string[], delayMs, timeoutMs,
109
+ * logRetainDays, logEnabled, applyTraceEnabled }
110
+ *
111
+ * 只认识这里的字段:旧版本遗留的键(如已移除的 `excludedPackages`)不会被透传,
112
+ * 下次写盘就自然从 config.json 里消失。
108
113
  */
109
114
  function readConfig(profileDir) {
110
115
  const p = configPath(profileDir)
111
116
  const defaults = {
112
117
  version: 2,
113
118
  lazyPackages: [],
114
- excludedPackages: [],
115
119
  order: [],
116
120
  delayMs: 5000,
117
121
  timeoutMs: 30000,
@@ -132,14 +136,19 @@ function readConfig(profileDir) {
132
136
  try {
133
137
  const raw = JSON.parse(readFileSync(p, 'utf8'))
134
138
  const strArr = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === 'string') : [])
139
+ const num = (v, fallback) => (typeof v === 'number' && Number.isFinite(v) ? v : fallback)
140
+ const bool = (v, fallback) => (typeof v === 'boolean' ? v : fallback)
135
141
  return {
136
- ...defaults,
137
- ...raw,
142
+ version: 2,
138
143
  lazyPackages: strArr(raw.lazyPackages),
139
- excludedPackages: strArr(raw.excludedPackages),
140
144
  order: strArr(raw.order),
141
145
  everLazyPackages: strArr(raw.everLazyPackages),
142
146
  noLazyPackages: strArr(raw.noLazyPackages),
147
+ delayMs: num(raw.delayMs, defaults.delayMs),
148
+ timeoutMs: num(raw.timeoutMs, defaults.timeoutMs),
149
+ logRetainDays: num(raw.logRetainDays, defaults.logRetainDays),
150
+ logEnabled: bool(raw.logEnabled, defaults.logEnabled),
151
+ applyTraceEnabled: bool(raw.applyTraceEnabled, defaults.applyTraceEnabled),
143
152
  }
144
153
  } catch {
145
154
  return defaults
@@ -999,9 +1008,6 @@ function mountRoutes(ctx, profileDir, getRuntime) {
999
1008
  const rank = new Map(nextOrder.map((n, i) => [n, i]))
1000
1009
  installed.sort((a, b) => (rank.get(a.name) ?? 1e9) - (rank.get(b.name) ?? 1e9))
1001
1010
 
1002
- const excluded = new Set(cfg.excludedPackages ?? [])
1003
- for (const p of installed) p.excluded = excluded.has(p.name)
1004
-
1005
1011
  // 真实运行状态(懒加载仅存在于 patch 的 disabled 表达式里,不能从 bundles 推)
1006
1012
  const runtime = readRuntimeState(ctx, profileDir, installed.map((p) => p.name))
1007
1013
  for (const p of installed) p.runtime = runtime[p.name] ?? null
@@ -1031,6 +1037,8 @@ function mountRoutes(ctx, profileDir, getRuntime) {
1031
1037
  const pkg = typeof payload.package === 'string' ? payload.package : ''
1032
1038
  const wantLazy = payload.lazy === true
1033
1039
  if (pkg === '') return jsonResponse(res, 400, { ok: false, error: 'package required' })
1040
+
1041
+ const cfg = readConfig(profileDir)
1034
1042
  if (!isManageable(pkg, cfg.noLazyPackages)) {
1035
1043
  const known = KNOWN_INCOMPATIBLE.find((x) => x.name === pkg)
1036
1044
  return jsonResponse(res, 400, {
@@ -1041,7 +1049,6 @@ function mountRoutes(ctx, profileDir, getRuntime) {
1041
1049
  })
1042
1050
  }
1043
1051
 
1044
- const cfg = readConfig(profileDir)
1045
1052
  let bundles = getBundles(profileDir)
1046
1053
  const inLazy = cfg.lazyPackages.includes(pkg)
1047
1054
  const inBundles = bundles.includes(pkg)
@@ -1083,34 +1090,6 @@ function mountRoutes(ctx, profileDir, getRuntime) {
1083
1090
  }
1084
1091
  }
1085
1092
 
1086
- // POST /api/dsh-lazy-mount/exclude { package, excluded: boolean }
1087
- if (path === ROUTE_PREFIX + '/exclude' && req.method === 'POST') {
1088
- const body = await readBody(req)
1089
- let payload
1090
- try {
1091
- payload = JSON.parse(body || '{}')
1092
- } catch {
1093
- return jsonResponse(res, 400, { ok: false, error: 'invalid json' })
1094
- }
1095
- const pkg = typeof payload.package === 'string' ? payload.package : ''
1096
- const wantExcluded = payload.excluded === true
1097
- if (pkg === '') return jsonResponse(res, 400, { ok: false, error: 'package required' })
1098
-
1099
- const cfg = readConfig(profileDir)
1100
- const set = new Set(cfg.excludedPackages ?? [])
1101
- if (wantExcluded) set.add(pkg)
1102
- else set.delete(pkg)
1103
- cfg.excludedPackages = [...set]
1104
- writeConfig(profileDir, cfg)
1105
-
1106
- return jsonResponse(res, 200, {
1107
- ok: true,
1108
- excluded: wantExcluded,
1109
- message: wantExcluded ? '已排除,不再显示在常用列表' : '已恢复显示',
1110
- config: cfg,
1111
- })
1112
- }
1113
-
1114
1093
  // POST /api/dsh-lazy-mount/noLazy { package, blocked: boolean }
1115
1094
  // 维护用户白名单:把「这个插件不能懒加载」的结论存进 config.noLazyPackages,
1116
1095
  // 同时会把它从当前的懒加载名单里摘掉。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lazy-mount",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "description": "Defer heavy plugin activation until after the window is usable. Pick which plugins load late, from a settings page. · DSH 插件懒加载管理器:把重型插件的加载推迟到窗口可用之后,面板可选延迟哪些插件。",
6
6
  "keywords": [