feat: 快速发送列表持久化到本地文件 frost-mqtt-data.json
This commit is contained in:
@@ -35,6 +35,7 @@ class MqttManager {
|
||||
this.listeners = new Set(); // IPC callback functions
|
||||
this.msgIdCounter = 0; // 用于生成唯一消息 id
|
||||
this.dataPath = join(app.getPath('userData'), 'frost-mqtt-data.json');
|
||||
this.quickSendList = [];
|
||||
this.loadData();
|
||||
}
|
||||
|
||||
@@ -101,6 +102,12 @@ class MqttManager {
|
||||
});
|
||||
}
|
||||
|
||||
if (Array.isArray(data.quickSendList)) {
|
||||
this.quickSendList = data.quickSendList.filter((item) => {
|
||||
return item && typeof item.id === 'string' && typeof item.topic === 'string';
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
this.initDefaultServers();
|
||||
}
|
||||
@@ -124,6 +131,7 @@ class MqttManager {
|
||||
})),
|
||||
messages: Object.fromEntries(this.messages),
|
||||
publishHistory: Object.fromEntries(this.publishHistory),
|
||||
quickSendList: this.quickSendList,
|
||||
};
|
||||
|
||||
writeFileSync(this.dataPath, JSON.stringify(data, null, 2), 'utf-8');
|
||||
@@ -409,6 +417,30 @@ class MqttManager {
|
||||
return this.getServers();
|
||||
}
|
||||
|
||||
// ==================== 快速发送 ====================
|
||||
|
||||
/**
|
||||
* 获取快速发送列表
|
||||
* @returns {QuickSendItem[]} 快速发送项数组
|
||||
*/
|
||||
getQuickSendList() {
|
||||
return this.quickSendList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存快速发送列表
|
||||
* @param {QuickSendItem[]} list - 快速发送项数组
|
||||
*/
|
||||
saveQuickSendList(list) {
|
||||
if (!Array.isArray(list)) {
|
||||
return;
|
||||
}
|
||||
this.quickSendList = list.filter((item) => {
|
||||
return item && typeof item.id === 'string' && typeof item.topic === 'string';
|
||||
});
|
||||
this.saveData();
|
||||
}
|
||||
|
||||
// ==================== 连接管理 ====================
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user