dsh-pocket 1.4.4 → 1.4.6

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/client.js CHANGED
@@ -427,6 +427,16 @@ var MOBILE_CSS = `
427
427
  padding-top: env(safe-area-inset-top, 0px) !important;
428
428
  }
429
429
 
430
+ /* \u4E3B\u5185\u5BB9\u5217\uFF08\u7B2C 2 \u4E2A\u7F51\u683C\u5B50\u5143\u7D20\uFF09\u5728\u5B98\u65B9\u6837\u5F0F\u91CC\u6709\u663E\u5F0F grid-column: 2\u2014\u2014
431
+ \u7F51\u683C\u88AB\u538B\u7F29\u6210 [1fr, 0, 0] \u540E\u5B83\u4F1A\u843D\u5728 0px \u7684\u7B2C 2 \u8F68\uFF0C\u6574\u4E2A\u4E3B\u754C\u9762\u88AB\u6324\u51FA
432
+ \u89C6\u53E3\uFF08\u53EA\u5269\u80CC\u666F\u56FE\uFF09\u3002\u5FC5\u987B\u663E\u5F0F\u628A\u5B83\u62C9\u56DE\u7B2C 1 \u8F68\uFF08issue #5\uFF09\u3002
433
+ \u7B2C 3 \u5217\uFF08details\uFF09\u4FDD\u6301 0 \u8F68\u5373\u53EF\uFF0C\u65E0\u9700\u5904\u7406\u3002 */
434
+ [data-mobile-nav="frame"] > :nth-child(2) {
435
+ grid-column: 1 !important;
436
+ grid-row: 1 !important;
437
+ min-width: 0 !important;
438
+ }
439
+
430
440
  /* The sidebar column (first grid child) becomes a left drawer. The drawer
431
441
  hugs the sidebar content exactly (the wide sidebar carries an inline
432
442
  width, ~280px): a fixed 92vw box would leave a white strip where the
@@ -175,6 +175,16 @@ export const MOBILE_CSS = `
175
175
  padding-top: env(safe-area-inset-top, 0px) !important;
176
176
  }
177
177
 
178
+ /* 主内容列(第 2 个网格子元素)在官方样式里有显式 grid-column: 2——
179
+ 网格被压缩成 [1fr, 0, 0] 后它会落在 0px 的第 2 轨,整个主界面被挤出
180
+ 视口(只剩背景图)。必须显式把它拉回第 1 轨(issue #5)。
181
+ 第 3 列(details)保持 0 轨即可,无需处理。 */
182
+ [data-mobile-nav="frame"] > :nth-child(2) {
183
+ grid-column: 1 !important;
184
+ grid-row: 1 !important;
185
+ min-width: 0 !important;
186
+ }
187
+
178
188
  /* The sidebar column (first grid child) becomes a left drawer. The drawer
179
189
  hugs the sidebar content exactly (the wide sidebar carries an inline
180
190
  width, ~280px): a fixed 92vw box would leave a white strip where the
package/lib/index.js CHANGED
@@ -19,6 +19,7 @@ import { homedir } from 'node:os';
19
19
  import { createPocketService } from './service.mjs';
20
20
  import { installPocketRpc } from './web-rpc.js';
21
21
  import { restartHost } from './restart.js';
22
+ import { desktopEnvPatchScript, DEFAULT_INJECT } from './proxy.mjs';
22
23
 
23
24
  const name = 'dsh-pocket';
24
25
  const inject = ['connection', 'webServer'];
@@ -127,6 +128,10 @@ export function apply(ctx, config = {}, internals = {}) {
127
128
  port: internals.port ?? config.port ?? 3081,
128
129
  home: internals.home,
129
130
  internals,
131
+ // 桌面端:手机扫码访问的页面缺 dsh-desktop-mode/platform 参数会让 dsh-plugin-desktop
132
+ // client 崩溃(issue #3/#4)。给代理注入「桌面参数补丁」(history.replaceState 补齐参数,
133
+ // 无跳转;compatibility 模式不套桌面布局,避免移动端按钮叠加)。保留默认 polyfill。
134
+ injectHtml: isDesktop ? DEFAULT_INJECT + desktopEnvPatchScript(process.platform) : undefined,
130
135
  });
131
136
 
132
137
  const disposers = [];
package/lib/proxy.mjs CHANGED
@@ -27,13 +27,29 @@ const RANDOM_UUID_POLYFILL = `<script data-dsh-pocket-polyfill="1">!function(){t
27
27
 
28
28
  const INJECT_MARK = 'data-dsh-pocket-polyfill="1"';
29
29
 
30
+ /**
31
+ * DSH Desktop(桌面版)渲染进程兼容补丁。
32
+ *
33
+ * 桌面版 profile 里的 dsh-plugin-desktop client 会在页面加载时从 URL query 读
34
+ * `dsh-desktop-mode` 与 `dsh-desktop-platform`,缺失即抛
35
+ * "invalid or missing dsh-desktop-mode null" → 页面崩(手机扫码访问桌面版时正是如此,
36
+ * 见 issue #3/#4)。本脚本在页面加载前用 history.replaceState 把这两个参数补上
37
+ * (无跳转、不重载),取最轻的 `compatibility` 模式——不激活桌面布局,避免与
38
+ * 移动端适配叠加。
39
+ * 仅宿主在桌面版(isDesktop)时由 lib/index.js 追加进 injectHtml。
40
+ */
41
+ export function desktopEnvPatchScript(platform) {
42
+ const p = ['darwin', 'win32', 'linux'].includes(platform) ? platform : 'linux';
43
+ return `<script data-dsh-pocket-desktop-patch="1">!function(){try{var s=new URLSearchParams(location.search);if(!s.has('dsh-desktop-mode')||!s.has('dsh-desktop-platform')){s.set('dsh-desktop-mode','compatibility');s.set('dsh-desktop-platform','${p}');var u=new URL(location.href);u.search=s.toString();history.replaceState(null,'',u);}}catch(e){}}();</script>`;
44
+ }
45
+
30
46
  /** 上游响应是否压缩过(压缩流不能做文本注入,会损坏页面)。 */
31
47
  function isCompressed(headers) {
32
48
  return /(^|,\s*)(gzip|br|deflate)(\s*,|$)/i.test(String(headers['content-encoding'] ?? ''));
33
49
  }
34
50
 
35
51
  /** 默认注入到经代理的 HTML 文档里:crypto.randomUUID polyfill(非安全上下文必需)。 */
36
- const DEFAULT_INJECT = RANDOM_UUID_POLYFILL;
52
+ export const DEFAULT_INJECT = RANDOM_UUID_POLYFILL;
37
53
 
38
54
  /** 把浏览器可见的权威改写成 loopback 权威(Host 和 Origin 都改)。 */
39
55
  function loopbackAuthority(headers, upstream) {
package/lib/service.mjs CHANGED
@@ -82,6 +82,8 @@ export function createPocketService({
82
82
  port = 3081,
83
83
  home,
84
84
  internals = {},
85
+ /** 代理注入 HTML 的内容(桌面端补丁等由 lib/index.js 传入;默认 randomUUID polyfill) */
86
+ injectHtml,
85
87
  } = {}) {
86
88
  const createProxy = internals.createProxy ?? createPocketProxy;
87
89
  const startTunnel = internals.startTunnel ?? startQuickTunnel;
@@ -119,6 +121,7 @@ export function createPocketService({
119
121
  port,
120
122
  host: '0.0.0.0',
121
123
  upstream: { host: '127.0.0.1', port: dshPort },
124
+ ...(injectHtml ? { injectHtml } : {}),
122
125
  });
123
126
  return proxy;
124
127
  },
package/package.json CHANGED
@@ -76,5 +76,5 @@
76
76
  "access": "public",
77
77
  "registry": "https://registry.npmjs.org/"
78
78
  },
79
- "version": "1.4.4"
79
+ "version": "1.4.6"
80
80
  }