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:
2026-11-10 16:38:05 +08:00
parent 066bbe4989
commit b891f07fd2
3 changed files with 24 additions and 9 deletions
+9 -1
View File
@@ -1,6 +1,6 @@
# 更新日志
## 未发布(本地改动,待发版时并入下一个版本)
## 1.10.9(2026-11-10)
### 新增
@@ -9,6 +9,14 @@
默认过滤 Excel `xlsx/xlsm`)。用于「台账模板 / 数据源文件」这类**单文件**参数,
`/api/dialog/directory` 只能选目录、选不了文件
### 修复
- 通知推送 WebSocket 连接更稳:启动时尚未登录的话,登录后随 60 秒轮询自动补连
(原来不重建连接,只能靠重启壳子才恢复);旧连接的关闭事件不再把新连接顶掉,
避免重复连接与重连抖动
- 配套中心机新增 `WS /ws/notifications` 实时通道:通知从"最长 60 秒延迟"变为秒达,
原 `GET /api/notifications` 轮询继续作为兜底(中心机未升级时仍按轮询工作)
## 1.10.2(2026-11-06)
### 新增
+14 -7
View File
@@ -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 {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "37du-electron-shell",
"productName": "37du 自动化工作台",
"version": "1.10.8",
"version": "1.10.9",
"description": "37du 执行机 Node/Electron 客户端(替代 Python webhost 底座,插件保持 Python 子进程执行)",
"main": "electron/main.js",
"private": true,