dsh-jiuling-remote-mobile 1.0.16 → 1.0.17
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/client.js +58 -1
- package/lib/index.js +7 -3
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -230,6 +230,37 @@ window.__ModuleLoader__.load({
|
|
|
230
230
|
document.head.appendChild(styleTag);
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
/**
|
|
234
|
+
* 电脑目录的**访问缓存**:`电脑路径 → listing`(模块级,跨对话框开关存活)。
|
|
235
|
+
*
|
|
236
|
+
* ## 为什么必须有(用户报障原文)
|
|
237
|
+
*
|
|
238
|
+
* 「为什么我点击添加工作区的时候,每次点击电脑都要重新加载一遍目录,
|
|
239
|
+
* 这就算了,我加载好之后,随便点击一个文件夹,文件夹里面的内容还要重新加载
|
|
240
|
+
* 一遍」—— 同一个电脑目录,每次进「电脑」页签、每次点进同一个文件夹,
|
|
241
|
+
* 都要重走一趟「手机 → Cloudflare 隧道 → 电脑」,一个来回 1~3 秒。
|
|
242
|
+
* 用户要的是「加载一次,后续直接从本地读」。
|
|
243
|
+
*
|
|
244
|
+
* ## 为什么放模块级而不是组件内 ref
|
|
245
|
+
*
|
|
246
|
+
* 对话框每次打开都是**新挂载的组件**,组件内的 ref 一关就没了 —— 那样
|
|
247
|
+
* 「关掉再打开又转一遍圈」,正是用户抱怨的第一个现象。放模块级则一次加载
|
|
248
|
+
* 整条会话内都命中。
|
|
249
|
+
*
|
|
250
|
+
* ⚠️ 键是**电脑路径**原样(`C:\Users\...`),`''` 表示根目录 —— 与
|
|
251
|
+
* `bridge('listDesktop')` 的入参完全一致,不做任何改写。
|
|
252
|
+
*
|
|
253
|
+
* ⚠️ **失效只有两条路**:用户点「刷新」(见 `refreshAll`),
|
|
254
|
+
* 或者那一次加载失败(见下面的 catch)。不做 TTL 轮询 —— 用户明确要的是
|
|
255
|
+
* 「加载一次就直接从本地读」。
|
|
256
|
+
*/
|
|
257
|
+
var desktopDirCache = {};
|
|
258
|
+
|
|
259
|
+
/** 清掉访问缓存(配对 / 解绑 / 切页签时调用,避免跨电脑串味)。 */
|
|
260
|
+
function clearDesktopDirCache() {
|
|
261
|
+
desktopDirCache = {};
|
|
262
|
+
}
|
|
263
|
+
|
|
233
264
|
/**
|
|
234
265
|
* 调宿主桥的一条 RPC(令牌只在引擎进程里,浏览器侧不持有)。
|
|
235
266
|
*
|
|
@@ -424,6 +455,16 @@ window.__ModuleLoader__.load({
|
|
|
424
455
|
patch({ loading: false, listing: null, error: null });
|
|
425
456
|
return undefined;
|
|
426
457
|
}
|
|
458
|
+
// ⚠️ **电脑目录命中缓存就直接铺回去,不打桥**(用户报障:来回点文件夹
|
|
459
|
+
// 每次都重新加载)。缓存键用 `''` 表示根,与 `listDesktop` 的入参一致。
|
|
460
|
+
if (tab === 'desktop') {
|
|
461
|
+
var key = path === null ? '' : path;
|
|
462
|
+
var hit = desktopDirCache[key];
|
|
463
|
+
if (hit !== undefined) {
|
|
464
|
+
patch({ loading: false, listing: hit, error: null });
|
|
465
|
+
return undefined;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
427
468
|
patch({ loading: true, error: null });
|
|
428
469
|
var load =
|
|
429
470
|
tab === 'desktop'
|
|
@@ -432,10 +473,16 @@ window.__ModuleLoader__.load({
|
|
|
432
473
|
load.then(
|
|
433
474
|
function (listing) {
|
|
434
475
|
if (!aliveRef.current) return;
|
|
476
|
+
if (tab === 'desktop') {
|
|
477
|
+
desktopDirCache[path === null ? '' : path] = listing;
|
|
478
|
+
}
|
|
435
479
|
patch({ loading: false, listing: listing });
|
|
436
480
|
},
|
|
437
481
|
function (reason) {
|
|
438
482
|
if (!aliveRef.current) return;
|
|
483
|
+
// ⚠️ 失败**要清掉这一格缓存**:留着的话用户再点进来会看到
|
|
484
|
+
// 上一次的旧内容,而以为自己看的是电脑现状。
|
|
485
|
+
if (tab === 'desktop') delete desktopDirCache[path === null ? '' : path];
|
|
439
486
|
patch({
|
|
440
487
|
loading: false,
|
|
441
488
|
listing: null,
|
|
@@ -488,6 +535,9 @@ window.__ModuleLoader__.load({
|
|
|
488
535
|
code: '',
|
|
489
536
|
message: { kind: 'ok', text: '配对成功,正在连接电脑…' },
|
|
490
537
|
});
|
|
538
|
+
// ⚠️ 换了一台电脑,旧缓存里的路径完全无效(甚至同名不同机)——
|
|
539
|
+
// 必须作废,否则用户会看到上一台电脑的目录。
|
|
540
|
+
clearDesktopDirCache();
|
|
491
541
|
patch({ path: null, listing: null });
|
|
492
542
|
},
|
|
493
543
|
function (reason) {
|
|
@@ -520,6 +570,8 @@ window.__ModuleLoader__.load({
|
|
|
520
570
|
code: '',
|
|
521
571
|
message: { kind: 'ok', text: '已解绑,请到电脑上生成新的配对码' },
|
|
522
572
|
});
|
|
573
|
+
// 解绑后旧凭据作废,缓存里的目录不该再露出来。
|
|
574
|
+
clearDesktopDirCache();
|
|
523
575
|
patch({ path: null, listing: null });
|
|
524
576
|
},
|
|
525
577
|
function (reason) {
|
|
@@ -611,11 +663,16 @@ window.__ModuleLoader__.load({
|
|
|
611
663
|
if (pairState.refreshing) return;
|
|
612
664
|
patchPair({ refreshing: true, refreshNote: null });
|
|
613
665
|
var target = state.tab === 'desktop' ? loc.path : '';
|
|
666
|
+
// ⚠️ **「刷新」必须清掉访问缓存**,否则新列表铺回 `listing` 之后,
|
|
667
|
+
// 用户一离开再回来又命中旧的那一格,看起来就是「刷新没生效」。
|
|
668
|
+
// 连同整棵已缓存的树一起作废:电脑上的目录可能已经变了。
|
|
669
|
+
clearDesktopDirCache();
|
|
614
670
|
bridge('refreshAll', target === '' ? {} : { path: target }).then(
|
|
615
671
|
function (result) {
|
|
616
672
|
if (!aliveRef.current) return;
|
|
617
|
-
//
|
|
673
|
+
// 目录树:直接把新列表铺回去(正在看的这一层),并写回缓存。
|
|
618
674
|
if (result && result.directory && result.directory.ok) {
|
|
675
|
+
desktopDirCache[target === '' ? '' : target] = result.directory.value;
|
|
619
676
|
patch({ listing: result.directory.value });
|
|
620
677
|
}
|
|
621
678
|
// 模型:让官方目录失效重载,下一次打开菜单就是电脑的。
|
package/lib/index.js
CHANGED
|
@@ -1379,6 +1379,10 @@ export function apply(ctx) {
|
|
|
1379
1379
|
// 解绑要能停掉全部旧连接、清掉全部搬运状态(见 `unpair`)。
|
|
1380
1380
|
follows,
|
|
1381
1381
|
mirrorStates,
|
|
1382
|
+
// ⚠️ **必须显式传进来**:`handleBridge` 是模块级函数,作用域里
|
|
1383
|
+
// 没有 `apply()` 的闭包变量;漏传就是 `workspaceMap is not defined`,
|
|
1384
|
+
// 用户点「在此新建对话」时必然失败(1.0.16 的真实报障)。
|
|
1385
|
+
workspaceMap,
|
|
1382
1386
|
persist: () => saveRemoteSessions(remoteSessions, ctx.logger),
|
|
1383
1387
|
// 模型/预设的静默缓存:配对后预拉、刷新按钮回写(见 desktopCache)。
|
|
1384
1388
|
desktopCache,
|
|
@@ -1556,7 +1560,7 @@ function desktopPathOfMirror(workspaceMap, dir) {
|
|
|
1556
1560
|
*
|
|
1557
1561
|
* @param ctx - Cordis 上下文。
|
|
1558
1562
|
* @param config - 远程配置。
|
|
1559
|
-
* @param io - `{ remoteSessions, follow, follows, mirrorStates, persist, body }`。
|
|
1563
|
+
* @param io - `{ remoteSessions, follow, follows, mirrorStates, persist, workspaceMap, body }`。
|
|
1560
1564
|
*/
|
|
1561
1565
|
async function handleBridge(ctx, config, io) {
|
|
1562
1566
|
const params = io.body?.params ?? {};
|
|
@@ -1640,7 +1644,7 @@ async function handleBridge(ctx, config, io) {
|
|
|
1640
1644
|
// 这里给它一个**电脑目录专属的镜像工作区**(标题 = 电脑目录末段),
|
|
1641
1645
|
// 而不是手机的「默认工作区」—— 否则所有远程会话都堆在「默认工作区」
|
|
1642
1646
|
// 底下,看起来就像「建完又回到默认工作去了」(见 `ensureDesktopWorkspace`)。
|
|
1643
|
-
const workspace = await ensureDesktopWorkspace(ctx, params.path, workspaceMap);
|
|
1647
|
+
const workspace = await ensureDesktopWorkspace(ctx, params.path, io.workspaceMap);
|
|
1644
1648
|
const cwd = workspace.path;
|
|
1645
1649
|
// ⚠️ **必须走 `sessionController.create`,不能走 `ctx.sessions.create`。**
|
|
1646
1650
|
//
|
|
@@ -1770,4 +1774,4 @@ async function handleBridge(ctx, config, io) {
|
|
|
1770
1774
|
}
|
|
1771
1775
|
}
|
|
1772
1776
|
|
|
1773
|
-
export { callRemote, mirrorEvent, loadConfig, DEFAULT_ENDPOINT, CONFIG_PATH, PAIR_ENDPOINT, claimPairing };
|
|
1777
|
+
export { callRemote, mirrorEvent, loadConfig, DEFAULT_ENDPOINT, CONFIG_PATH, PAIR_ENDPOINT, claimPairing, handleBridge };
|