feat(electron-shell): 1.10.9 新增选文件接口 /api/dialog/file,通知 WS 补连与秒达
本机接口 POST /api/dialog/file:插件 UI 调原生选择文件对话框,只回绝对路径(默认过滤 xlsx/xlsm),补 /api/dialog/directory 只能选目录的缺口。 通知 WS:启动时未登录不再永久连不上(随 60s 轮询补连),旧连接 close 不再顶掉新连接;配套中心机 /ws/notifications 后通知秒达,轮询继续兜底。
This commit is contained in:
@@ -96,15 +96,16 @@ function connectWs(account) {
|
||||
wsAccount = account;
|
||||
try {
|
||||
const { WebSocket } = require("ws");
|
||||
ws = new WebSocket(wsUrl(account), {
|
||||
const sock = new WebSocket(wsUrl(account), {
|
||||
headers: cp.machineHeaders(),
|
||||
handshakeTimeout: 8000,
|
||||
});
|
||||
ws.on("open", () => {
|
||||
ws = sock;
|
||||
sock.on("open", () => {
|
||||
wsRetry = 0;
|
||||
logger.info(`通知 WebSocket 已连接(${account})`);
|
||||
});
|
||||
ws.on("message", (data) => {
|
||||
sock.on("message", (data) => {
|
||||
try {
|
||||
const msg = JSON.parse(String(data));
|
||||
if (msg.type === "notify" && msg.notification) {
|
||||
@@ -114,11 +115,15 @@ function connectWs(account) {
|
||||
/* 忽略坏帧 */
|
||||
}
|
||||
});
|
||||
ws.on("ping", () => {
|
||||
try { ws.pong(); } catch (e) { /* 忽略 */ }
|
||||
sock.on("ping", () => {
|
||||
try { sock.pong(); } catch (e) { /* 忽略 */ }
|
||||
});
|
||||
ws.on("close", () => { scheduleWsReconnect(wsAccount); });
|
||||
ws.on("error", (e) => { logger.warning(`通知 WS 错误:${e.message}`); });
|
||||
// 只有「当前这一条」连接关闭才安排重连,避免旧连接把新连接顶掉(重复连接/定时器抖动)
|
||||
sock.on("close", () => {
|
||||
if (ws !== sock) return;
|
||||
scheduleWsReconnect(wsAccount);
|
||||
});
|
||||
sock.on("error", (e) => { logger.warning(`通知 WS 错误:${e.message}`); });
|
||||
} catch (e) {
|
||||
logger.warning(`通知 WS 连接失败:${e.message}`);
|
||||
scheduleWsReconnect(account);
|
||||
@@ -143,6 +148,8 @@ async function pollOnce() {
|
||||
const active = config.CONTROLPLANE_ACCOUNT || session.sessActiveAccount();
|
||||
if (active) accts.add(active);
|
||||
if (!accts.size) return;
|
||||
// 启动时可能还没登录(connectWs 无账号直接返回),随轮询补连;已连/连接中幂等返回
|
||||
if (active) connectWs(active);
|
||||
|
||||
for (const account of accts) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user