From 4d343d5de3b7033eafe20c641cdacf3d497f2593 Mon Sep 17 00:00:00 2001 From: zhaolei <256168157@qq.com> Date: Wed, 21 Oct 2026 17:35:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20portable=20=E7=89=88=203D=20=E6=8B=93?= =?UTF-8?q?=E6=89=91=E8=AE=BE=E5=A4=87=E4=BD=8D=E7=BD=AE=20fallback=20?= =?UTF-8?q?=E5=88=B0=E4=B8=BB=E8=BF=9B=E7=A8=8B=20JSON?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit renderer 原来只读 localStorage 的 monitoring-topology-positions, portable 版 userData 是全新空目录,Local Storage 里没有这个 key, 导致设备布局 fallback 到大圆圈自动布局。 加主进程 inspection-data.json 的同步 fallback: - preload/api.cjs 新增 getTopologyPositionsSync(ipcRenderer.sendSync) - index.cjs 新增 ipcMain.on 同步 handler(与 handle 并存) - MonitoringTopologyView.tsx localStorage 找不到时 fallback 读主进程 JSON --- .../monitoring/MonitoringTopologyView.tsx | 18 ++++++++++++++---- electron/bridges/inspection/index.cjs | 7 +++++++ electron/preload/api.cjs | 4 ++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/components/monitoring/MonitoringTopologyView.tsx b/components/monitoring/MonitoringTopologyView.tsx index e9373eb..6164d0d 100644 --- a/components/monitoring/MonitoringTopologyView.tsx +++ b/components/monitoring/MonitoringTopologyView.tsx @@ -1,4 +1,4 @@ -/** +/** * 运行监控 - 3D 拓扑大屏 * * 移植自 ITYUNWEI TopologyView.vue @@ -2306,10 +2306,20 @@ export function MonitoringTopologyView({ hosts, keys }: Props) { } } catch { /* ignore */ } } - // 本地 Electron:从 localStorage 读 + // 本地 Electron:从 localStorage 读,找不到则从主进程 inspection-data.json 读 try { - const saved = localStorage.getItem('monitoring-topology-positions'); - return saved ? JSON.parse(saved) : null; + let saved = localStorage.getItem('monitoring-topology-positions'); + if (saved) return JSON.parse(saved); + // portable 版 localStorage 为空 → fallback 主进程 JSON(sendSync 同步) + try { + const nc = (window as any).netcatty; + const fromMain = nc?.inspection?.getTopologyPositionsSync?.(); + if (fromMain && typeof fromMain === 'object' && Object.keys(fromMain).length > 0) { + console.info('[Monitoring] localStorage 无位置,从主进程 inspection-data.json 加载'); + return fromMain; + } + } catch { /* ignore */ } + return null; } catch { return null; } })(); diff --git a/electron/bridges/inspection/index.cjs b/electron/bridges/inspection/index.cjs index ac6fb4e..b0d7d3a 100644 --- a/electron/bridges/inspection/index.cjs +++ b/electron/bridges/inspection/index.cjs @@ -1544,6 +1544,13 @@ function registerInspectionHandlers(ipcMain, options) { } catch { return {}; } }); + // sendSync 同步版本 — renderer 3D 布局 fallback 读取用 + ipcMain.on("inspection:getTopologyPositions", (event) => { + try { + event.returnValue = readStorage("_topology_positions") || {}; + } catch { event.returnValue = {}; } + }); + // 监控大屏标题同步(Electron localStorage → 远程浏览器可读) ipcMain.handle("inspection:saveDashboardTitle", (_e, title) => { if (!title || typeof title !== "string") return { ok: false }; diff --git a/electron/preload/api.cjs b/electron/preload/api.cjs index d6762fd..1021957 100644 --- a/electron/preload/api.cjs +++ b/electron/preload/api.cjs @@ -2122,6 +2122,10 @@ function createPreloadApi(ctx) { // 拓扑位置持久化(供远程浏览器同步读取) saveTopologyPositions: (positions) => ipcRenderer.invoke("inspection:saveTopologyPositions", positions), getTopologyPositions: () => ipcRenderer.invoke("inspection:getTopologyPositions"), + // 同步版本 — renderer 3D 布局同步加载位置时用(portable 版 localStorage 为空时 fallback 读主进程 JSON) + getTopologyPositionsSync: () => { + try { return ipcRenderer.sendSync("inspection:getTopologyPositions"); } catch { return null; } + }, // 监控大屏标题同步 saveDashboardTitle: (title) => ipcRenderer.invoke("inspection:saveDashboardTitle", title), getDashboardTitle: () => ipcRenderer.invoke("inspection:getDashboardTitle"),