From 9c2a469e4d3864313d4ad449a359374470036fd5 Mon Sep 17 00:00:00 2001 From: Frost-ZX Date: Sat, 18 Jul 2026 21:57:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=87=BA=E7=8E=B0=E8=AD=A6=E5=91=8A=20`Dupli?= =?UTF-8?q?cate=20keys=20found=20during=20update`=20=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/mqtt-manager.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/mqtt-manager.js b/app/src/main/mqtt-manager.js index 7c62636..a296c3c 100644 --- a/app/src/main/mqtt-manager.js +++ b/app/src/main/mqtt-manager.js @@ -10,11 +10,17 @@ class MqttManager { this.messages = new Map() // serverId -> message[] this.publishHistory = new Map() // serverId -> publishHistory[] this.listeners = new Set() // IPC callback functions + this.msgIdCounter = 0 // 用于生成唯一消息 id this.dataPath = join(app.getPath('userData'), 'frost-mqtt-data.json') this.loadData() } + nextMsgId() { + this.msgIdCounter = (this.msgIdCounter + 1) % Number.MAX_SAFE_INTEGER + return 'msg_' + Date.now() + '_' + this.msgIdCounter + } + // ==================== 数据持久化 ==================== getDataDir() { const dir = app.getPath('userData') @@ -269,9 +275,9 @@ class MqttManager { qos: packet.qos, retain: packet.retain, direction: 'sub', - id: 'msg_' + Date.now() - } - const msgs = this.messages.get(id) || [] + id: this.nextMsgId() + } + const msgs = this.messages.get(id) || [] msgs.unshift(msg) if (msgs.length > 500) msgs.pop() this.messages.set(id, msgs) @@ -479,10 +485,11 @@ class MqttManager { this.publishHistory.set(serverId, history) // 同时添加到消息日志 + const pubMsgId = this.nextMsgId() const msgs = this.messages.get(serverId) || [] msgs.unshift({ ...pubEntry, - id: 'msg_' + Date.now() + id: pubMsgId }) if (msgs.length > 500) msgs.pop() this.messages.set(serverId, msgs) @@ -491,7 +498,7 @@ class MqttManager { serverId, message: { ...pubEntry, - id: 'msg_' + Date.now() + id: pubMsgId } })