dsh-multipane 1.0.55 → 1.1.9

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/lib/index.js CHANGED
@@ -340,6 +340,7 @@ function ensureMarketInstallable() {
340
340
  */
341
341
  const UPDATE_ROUTE = "/dsh-multipane/update";
342
342
  const STATUS_ROUTE = "/dsh-multipane/status";
343
+ const DIAG_ROUTE = "/dsh-multipane/diag";
343
344
 
344
345
  /**
345
346
  * Install one published version straight from the npm registry.
@@ -474,16 +475,127 @@ export function apply(ctx) {
474
475
  } catch {
475
476
  /* 忽略 */
476
477
  }
478
+ /* 管理器里禁用插件时,宿主不一定会 dispose 插件:路由可能一直活着,客户端就没法靠"路由消失"判断死活。
479
+ 所以直接把宿主自己的答案带上。三条判据,任意一条明确说"没了/关了"就返回 false:
480
+ ① profile 的 package.json 里 dsh.profile.bundles 是否还列着本插件 —— 管理器禁用就是从这里删的;
481
+ ② cordis.patch.yml 里是否有指向本插件、disabled: true 的条目;
482
+ ③ pluginManager.listPlugins() 里本行的 enabled 字段。
483
+ 全部说在才返回 true,都说不准就 null(客户端会退化成只用"路由消失"判断)。 */
484
+ let managerService;
485
+ try {
486
+ ctx.inject(["pluginManager"], (scope) => {
487
+ try {
488
+ managerService = scope.pluginManager;
489
+ } catch {
490
+ managerService = void 0;
491
+ }
492
+ return () => {
493
+ managerService = void 0;
494
+ };
495
+ });
496
+ } catch {
497
+ /* 拿不到管理器就只能是 null */
498
+ }
499
+ /* 客户端每 2.5s 探一次,这些判据每次都要读盘 —— 加个 1.5s 的短缓存,别把 IO 打满。 */
500
+ let enabledAt = 0;
501
+ let enabledValue = null;
502
+ /* 只有"曾经见过"才允许把"现在不在"当成禁用证据:有的装法本来就不写进 bundles,
503
+ 一上来就不在,不能误判成被禁用。 */
504
+ let seenInBundles = false;
505
+ let seenInManager = false;
506
+ const profileDirOf = () => join(homedir(), ".dsh", "profiles", "desktop");
507
+ /* 手动清场开关:~/.dsh/.dsv-disabled 存在就等同于"宿主已禁用"。
508
+ 用途一:管理器禁用路径不方便复现时,可以手工造一次 enabled:false 验证清场链路;
509
+ 用途二:插件真出问题时,用户建这个空文件就能让页面立刻恢复官方外观。 */
510
+ const disabledMarker = () => {
511
+ try {
512
+ return existsSync(join(homedir(), ".dsh", ".dsv-disabled"));
513
+ } catch {
514
+ return false;
515
+ }
516
+ };
517
+ const bundlesSay = () => {
518
+ try {
519
+ const pkg = JSON.parse(readFileSync(join(profileDirOf(), "package.json"), "utf8"));
520
+ const bundles = pkg?.dsh?.profile?.bundles;
521
+ if (!Array.isArray(bundles)) return null;
522
+ const present = bundles.some((item) => item === PKG_NAME || item === name);
523
+ if (present === true) {
524
+ seenInBundles = true;
525
+ return true;
526
+ }
527
+ return seenInBundles === true ? false : null;
528
+ } catch {
529
+ return null;
530
+ }
531
+ };
532
+ /* 加载时先记一笔"它确实在 bundles 里":这样即使第一次状态查询发生在用户禁用之后,
533
+ 也能把"现在不在"判成禁用,而不是"从来没在过"。 */
534
+ try {
535
+ bundlesSay();
536
+ } catch {
537
+ /* 忽略 */
538
+ }
539
+ const patchSaysDisabled = () => {
540
+ try {
541
+ const text = readFileSync(join(profileDirOf(), "cordis.patch.yml"), "utf8");
542
+ /* 粗匹配 YAML 条目:按行首 "- " 切块,块里提到本插件、又带 disabled: true 才算。 */
543
+ for (const block of text.split(/\n(?=- )/)) {
544
+ if (block.indexOf(PKG_NAME) < 0 && block.indexOf("split-view") < 0) continue;
545
+ if (/^\s*disabled:\s*true\s*$/m.test(block)) return true;
546
+ }
547
+ return null;
548
+ } catch {
549
+ return null;
550
+ }
551
+ };
552
+ const selfEnabled = async () => {
553
+ const now = Date.now();
554
+ if (now - enabledAt < 1500) return enabledValue;
555
+ enabledAt = now;
556
+ let managerSays = null;
557
+ try {
558
+ const manager = managerService;
559
+ if (manager !== void 0 && manager !== null && typeof manager.listPlugins === "function") {
560
+ const listed = await manager.listPlugins();
561
+ const rows = Array.isArray(listed) ? listed : Array.isArray(listed?.plugins) ? listed.plugins : [];
562
+ const own = rows.find((row) => row !== null && typeof row === "object" && (row.moduleName === PKG_NAME || row.name === "dsh-split-view" || row.id === "split-view"));
563
+ if (own !== void 0) {
564
+ seenInManager = true;
565
+ managerSays = own.enabled !== false;
566
+ } else if (seenInManager === true) {
567
+ /* 之前明明在列表里,现在整行没了:管理器把它移除了。 */
568
+ managerSays = false;
569
+ }
570
+ }
571
+ } catch {
572
+ managerSays = null;
573
+ }
574
+ const bundleSays = bundlesSay();
575
+ const patchDisabled = patchSaysDisabled();
576
+ const marker = disabledMarker();
577
+ if (marker === true || managerSays === false || bundleSays === false || patchDisabled === true) enabledValue = false;
578
+ else if (managerSays === true || bundleSays === true) enabledValue = true;
579
+ else enabledValue = null;
580
+ return enabledValue;
581
+ };
477
582
  try {
478
583
  ctx.inject(["webServer"], (host) => {
479
- const profileDirOf = () => join(homedir(), ".dsh", "profiles", "desktop");
480
584
  const routes = [
481
585
  {
482
586
  kind: "exact",
483
587
  path: STATUS_ROUTE,
484
588
  handler: (request, response) => {
485
- response.writeHead(200, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
486
- response.end(JSON.stringify({ version: readOwnVersion(), profile: profileDirOf() }));
589
+ selfEnabled().then((enabled) => {
590
+ const body = { version: readOwnVersion(), profile: profileDirOf() };
591
+ if (enabled !== null) body.enabled = enabled;
592
+ try {
593
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
594
+ response.end(JSON.stringify(body));
595
+ } catch {
596
+ /* 连接已经断了 */
597
+ }
598
+ });
487
599
  }
488
600
  },
489
601
  {
@@ -513,15 +625,60 @@ export function apply(ctx) {
513
625
  });
514
626
  });
515
627
  }
628
+ },
629
+ {
630
+ /* 诊断通道:客户端把会话行的真实几何/计算样式 POST 上来,这里原样落盘。
631
+ 侧栏是宿主的 DOM,插件在外面看不到它渲染成什么样,只靠猜改 CSS 已经错过三次;
632
+ 有这条通道,取一次真实数据就能定位缝隙出在哪一层。 */
633
+ kind: "exact",
634
+ path: DIAG_ROUTE,
635
+ handler: (request, response) => {
636
+ if (request.method !== "POST") {
637
+ response.writeHead(405, { allow: "POST" });
638
+ response.end("");
639
+ return;
640
+ }
641
+ readJsonBody(request, 262144, (body) => {
642
+ let ok = false;
643
+ try {
644
+ writeFileSync(join(homedir(), ".dsh", ".dsv-diag.json"), body, "utf8");
645
+ ok = true;
646
+ } catch {
647
+ ok = false;
648
+ }
649
+ response.writeHead(ok ? 200 : 500, { "content-type": "application/json; charset=utf-8" });
650
+ response.end(JSON.stringify({ ok }));
651
+ });
652
+ }
516
653
  }
517
654
  ];
518
- for (const route of routes) {
519
- try {
520
- host.webServer.register(route);
521
- } catch {
522
- /* 单个路由失败不影响另一个 */
655
+ /* 两个路由都用 host.effect 注册:插件被宿主插件管理「禁用」时,这个 effect 的
656
+ cleanup 会把路由一起注销。客户端半身正是拿 /dsh-multipane/status 当存活信号
657
+ (路由消失 = 已被禁用 → 立刻清掉页面上的样式与行标记),所以这里**必须**
658
+ 跟着插件生命周期回收,不能让禁用后的进程还留着这条路由。
659
+ 宿主没有 effect(理论上不会)时退回直接注册,行为与旧版一致、不会更差。 */
660
+ const registerRoutes = () => {
661
+ const disposers = [];
662
+ for (const route of routes) {
663
+ try {
664
+ const dispose = host.webServer.register(route);
665
+ if (typeof dispose === "function") disposers.push(dispose);
666
+ } catch {
667
+ /* 单个路由失败不影响另一个 */
668
+ }
523
669
  }
524
- }
670
+ return () => {
671
+ for (const dispose of disposers.splice(0)) {
672
+ try {
673
+ dispose();
674
+ } catch {
675
+ /* 忽略:宿主可能已经拆掉了 webServer */
676
+ }
677
+ }
678
+ };
679
+ };
680
+ if (typeof host.effect === "function") host.effect(registerRoutes);
681
+ else registerRoutes();
525
682
  });
526
683
  } catch {
527
684
  /* 拿不到 webServer 就只是没有设置页内的更新入口,插件本身照常工作 */
package/locale/en.json CHANGED
File without changes
package/locale/zh.json CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-multipane",
3
- "version": "1.0.55",
3
+ "version": "1.1.9",
4
4
  "description": "Split the DSH main area into up to four panes, each with its own tab strip, composer and view switcher. Drag a tab to a pane edge to split. Bilingual (zh/en).",
5
5
  "displayName": "多栏视图",
6
6
  "dshhub": {