dsh-pocket 1.4.4 → 1.4.5
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 +5 -0
- package/lib/proxy.mjs +17 -1
- package/lib/service.mjs +3 -0
- package/package.json +1 -1
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