dsh-folia 3.2.0 → 3.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 (2) hide show
  1. package/lib/index.js +74 -1
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -94,7 +94,7 @@ import { registerPropsRoutes } from './routes/props.js';
94
94
  import { registerLiveFrameRoutes } from './routes/live-frame.js';
95
95
  import { registerSettingsRoutes } from './routes/settings.js';
96
96
  import { registerCacheDirRoutes } from './routes/cache-dir.js';
97
- import { registerSkinRoutes } from './routes/skins.js';
97
+ import { registerSkinRoutes, harnessRoot as foliaHarnessRoot } from './routes/skins.js';
98
98
  // C8′/C6 出户的组件行(P2-1 / P2-2):组件入口**静态** import(不是动态)—— `test/verify-reachability.mjs`
99
99
  // 只从 ENTRY 沿 import 边走,动态加载的组件入口会被判定为不可达,棘轮当场变红。
100
100
  // 组件名 → 实现表的登记在 `applyComponent` **函数体内**(P2-1b 起;模块级常量会让门面求值期
@@ -504,6 +504,13 @@ export function apply(ctx) {
504
504
  disposers, base: BASE, log,
505
505
  });
506
506
 
507
+ // 皮肤中心自动挂载(可选,默认关闭)。它是标准 cordis 插件(name / inject / apply),
508
+ // 所以能被动态挂上 —— 用户不必再装 @linxin666/dsh-web-all 才有皮肤渲染能力。
509
+ // 默认关闭的原因:DSH 对"同一插件挂两次"没有保护,我们踩过(重复行 → 安全模式)。
510
+ try { maybeMountSkinCenter(ctx, log); } catch (err) {
511
+ try { log('[folia] 皮肤中心自动挂载失败(忽略):' + (err && err.message ? err.message : err)); } catch { /* ignore */ }
512
+ }
513
+
507
514
  // fiber disposer 的语义(先逐个 disposer、再 releaseKernelLease(hostKernel)——内核引用计数
508
515
  // 归零才 `transcodeKit.dispose()`——再 destroy 在途流、清 activeStreams / mediaMap)
509
516
  // 逐字搬进 lib/kernel/host-session.js 的 `dispose()`。
@@ -587,6 +594,72 @@ function componentProbe() {
587
594
  * —— 那条纪律写在组件入口文件头,并由 `test/verify-bundle-rows.mjs` 的判据钉住;彻底解耦(拆环)
588
595
  * 留给 P2-2b。
589
596
  */
597
+ /**
598
+ * 是否已经有别的 bundle 把皮肤中心挂上了(默认假设"有",避免重复挂载)。
599
+ *
600
+ * 判据落在磁盘上的 patch 行:从 harness 根出发,扫每个 profile 的 package.json
601
+ * dsh.profile.bundles,把每个 bundle 包的 cordis.patch.yml 读出来,看有没有行指向
602
+ * @linxin666/dsh-client-ui-skin-center。有 ⇒ 别人挂了,我们不插手。
603
+ * 读不到 / 结构不认识 ⇒ 同样按"已挂载"处理(宁可少挂一次,也不能挂两次)。
604
+ */
605
+ function skinCenterPatchedElsewhere(harnessRoot) {
606
+ try {
607
+ const { readdirSync, readFileSync, existsSync } = require('node:fs');
608
+ const { join } = require('node:path');
609
+ const profilesDir = join(harnessRoot, 'profiles');
610
+ if (!existsSync(profilesDir)) return true;
611
+ const SKIN_CENTER = '@linxin666/dsh-client-ui-skin-center';
612
+ for (const name of readdirSync(profilesDir)) {
613
+ if (name.startsWith('.')) continue;
614
+ const pkgPath = join(profilesDir, name, 'package.json');
615
+ if (!existsSync(pkgPath)) continue;
616
+ let prof;
617
+ try { prof = JSON.parse(readFileSync(pkgPath, 'utf8')); } catch { continue; }
618
+ const bundles = (prof && prof.dsh && prof.dsh.profile && prof.dsh.profile.bundles) || [];
619
+ for (const b of bundles) {
620
+ const patchPath = join(profilesDir, name, 'node_modules', b, 'cordis.patch.yml');
621
+ if (!existsSync(patchPath)) continue;
622
+ let text = '';
623
+ try { text = readFileSync(patchPath, 'utf8'); } catch { continue; }
624
+ if (text.includes(SKIN_CENTER)) return true;
625
+ }
626
+ }
627
+ return false;
628
+ } catch {
629
+ return true;
630
+ }
631
+ }
632
+
633
+ /**
634
+ * 按需动态挂载皮肤中心。默认关闭,用 DSH_FOLIA_MOUNT_SKIN_CENTER=1 开启。
635
+ * 开启后仍先查"别人挂了吗",已挂则跳过 —— 重复挂载是能让 DSH 起不来的事故。
636
+ */
637
+ function maybeMountSkinCenter(ctx, log) {
638
+ const flag = String(process.env.DSH_FOLIA_MOUNT_SKIN_CENTER || '').trim().toLowerCase();
639
+ if (flag !== '1' && flag !== 'on' && flag !== 'true') return;
640
+
641
+ const harness = (() => { try { return foliaHarnessRoot(); } catch { return null; } })();
642
+ if (!harness) {
643
+ try { log('[folia] 皮肤中心自动挂载跳过:找不到 harness 根目录'); } catch { /* ignore */ }
644
+ return;
645
+ }
646
+ if (skinCenterPatchedElsewhere(harness)) {
647
+ try { log('[folia] 皮肤中心已由其它 bundle 挂载,跳过自动挂载'); } catch { /* ignore */ }
648
+ return;
649
+ }
650
+ import('@linxin666/dsh-client-ui-skin-center').then((mod) => {
651
+ try {
652
+ if (!mod || typeof mod.apply !== 'function') { log('[folia] 皮肤中心模块形态不对,跳过'); return; }
653
+ ctx.plugin(mod);
654
+ log('[folia] 已自动挂载皮肤中心(DSH_FOLIA_MOUNT_SKIN_CENTER=1)');
655
+ } catch (err) {
656
+ try { log('[folia] 自动挂载皮肤中心失败:' + (err && err.message ? err.message : err)); } catch { /* ignore */ }
657
+ }
658
+ }).catch((err) => {
659
+ try { log('[folia] 找不到皮肤中心(可选依赖),跳过:' + (err && err.message ? err.message : err)); } catch { /* ignore */ }
660
+ });
661
+ }
662
+
590
663
  export function applyComponent(root, rawConfig, component) {
591
664
  const impls = componentImpls();
592
665
  const impl = impls.get(component);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-folia",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "Folia 壁纸引擎:把本机 Wallpaper Engine 壁纸搬进 DSH 界面(场景实时渲染 / 视频 / 网页),内置液态玻璃与 Folia 吉祥物,并可从自建站点拉取壁纸。单包形态(组件已合并)。",
5
5
  "type": "module",
6
6
  "engines": {