dsh-pocket 1.4.3 → 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/client/client.js +5 -2
- package/client/index.jsx +7 -3
- package/lib/index.js +5 -0
- package/lib/proxy.mjs +17 -1
- package/lib/service.mjs +3 -0
- package/package.json +1 -1
package/client/client.js
CHANGED
|
@@ -1348,7 +1348,7 @@ function PocketSettingsTab({ rpcCall }) {
|
|
|
1348
1348
|
(0, import_react2.useEffect)(() => {
|
|
1349
1349
|
if (isDesktop) return;
|
|
1350
1350
|
let alive = true;
|
|
1351
|
-
|
|
1351
|
+
const check = async () => {
|
|
1352
1352
|
try {
|
|
1353
1353
|
const v = await call(POCKET_ENDPOINTS.version, {});
|
|
1354
1354
|
const meta = await (await fetch("https://registry.npmjs.org/dsh-pocket/latest", { cache: "no-store" })).json();
|
|
@@ -1361,9 +1361,12 @@ function PocketSettingsTab({ rpcCall }) {
|
|
|
1361
1361
|
}
|
|
1362
1362
|
} catch {
|
|
1363
1363
|
}
|
|
1364
|
-
}
|
|
1364
|
+
};
|
|
1365
|
+
check();
|
|
1366
|
+
const t = setInterval(check, 5 * 60 * 1e3);
|
|
1365
1367
|
return () => {
|
|
1366
1368
|
alive = false;
|
|
1369
|
+
clearInterval(t);
|
|
1367
1370
|
};
|
|
1368
1371
|
}, [isDesktop]);
|
|
1369
1372
|
const restartPocket = async () => {
|
package/client/index.jsx
CHANGED
|
@@ -87,11 +87,13 @@ function PocketSettingsTab({ rpcCall }) {
|
|
|
87
87
|
// 版本检测:host 当前版本 vs npm registry latest(registry 带 CORS *)
|
|
88
88
|
// 两种情况显示横幅:① 有新版可更新;② 磁盘已更新但进程还是旧代码(重启生效)
|
|
89
89
|
// cache: 'no-store' —— registry 响应带缓存头,浏览器会缓存旧版本号导致「小版本不提示」
|
|
90
|
+
// 周期重查(每 5 分钟):npm registry 的 /latest 走 CDN 边缘缓存,刚发布后打开页面
|
|
91
|
+
// 可能拿到旧版本号——周期性重查让更新提示在缓存刷新后自动出现,不用重开页面。
|
|
90
92
|
// 桌面端(isDesktop):更新/重启由 DSH Desktop 管理,这里不做版本检测、不显示更新横幅
|
|
91
93
|
useEffect(() => {
|
|
92
94
|
if (isDesktop) return;
|
|
93
95
|
let alive = true;
|
|
94
|
-
|
|
96
|
+
const check = async () => {
|
|
95
97
|
try {
|
|
96
98
|
const v = await call(POCKET_ENDPOINTS.version, {});
|
|
97
99
|
const meta = await (await fetch('https://registry.npmjs.org/dsh-pocket/latest', { cache: 'no-store' })).json();
|
|
@@ -104,8 +106,10 @@ function PocketSettingsTab({ rpcCall }) {
|
|
|
104
106
|
setUpdateInfo({ current: v.current, latest: v.current, updating: false, result: 'ok', updated: true });
|
|
105
107
|
}
|
|
106
108
|
} catch { /* 网络失败静默 */ }
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
+
};
|
|
110
|
+
check();
|
|
111
|
+
const t = setInterval(check, 5 * 60 * 1000);
|
|
112
|
+
return () => { alive = false; clearInterval(t); };
|
|
109
113
|
}, [isDesktop]);
|
|
110
114
|
|
|
111
115
|
// 重启宿主(更新生效必需:刷新页面不会重载服务端代码)
|
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