feat: 连接配置支持「启动时自动连接」
- ConnectionConfig 新增 auto_connect 字段(serde default,旧数据兼容) - 连接表单「认证与心跳」区新增开关,随保存持久化 - 应用启动时对勾选的连接逐个拉起(遗嘱模板注入后 connect)
This commit is contained in:
@@ -168,6 +168,9 @@ pub struct ConnectionConfig {
|
||||
/// 断线自动重连
|
||||
#[serde(default = "default_true")]
|
||||
pub auto_reconnect: bool,
|
||||
/// 应用启动时自动连接该连接
|
||||
#[serde(default)]
|
||||
pub auto_connect: bool,
|
||||
|
||||
#[serde(default)]
|
||||
pub last_will: Option<LastWill>,
|
||||
@@ -227,6 +230,7 @@ impl ConnectionConfig {
|
||||
topic_alias_maximum: None,
|
||||
auto_resubscribe: true,
|
||||
auto_reconnect: true,
|
||||
auto_connect: false,
|
||||
last_will: None,
|
||||
created_at: chrono::Local::now().timestamp(),
|
||||
group: None,
|
||||
|
||||
@@ -135,6 +135,17 @@ impl MqttXApp {
|
||||
// OTA:清理上次自更新遗留文件;开启自动检查则后台静默检查并下载,
|
||||
// 下载完成后弹对话框征得同意再安装(不自动重启)。
|
||||
update::cleanup_old();
|
||||
// 自动连接:勾选「启动时自动连接」的连接逐个拉起(引擎异步建连)
|
||||
for cfg in connections
|
||||
.iter()
|
||||
.filter(|c| c.auto_connect)
|
||||
.cloned()
|
||||
.collect::<Vec<_>>()
|
||||
{
|
||||
let mut cfg = cfg;
|
||||
crate::model::render_will_templates(&mut cfg, &variables);
|
||||
engine.connect(cfg);
|
||||
}
|
||||
if settings.auto_check_update {
|
||||
let rx = engine.run_blocking(update::check_and_download);
|
||||
let weak = cx.entity().downgrade();
|
||||
|
||||
@@ -74,6 +74,7 @@ pub struct ConnectionForm {
|
||||
clean_start: bool,
|
||||
auto_resubscribe: bool,
|
||||
auto_reconnect: bool,
|
||||
auto_connect: bool,
|
||||
will_enabled: bool,
|
||||
will_retain: bool,
|
||||
ssl_ignore_ca: bool,
|
||||
@@ -323,6 +324,7 @@ impl ConnectionForm {
|
||||
clean_start: c.clean_start,
|
||||
auto_resubscribe: c.auto_resubscribe,
|
||||
auto_reconnect: c.auto_reconnect,
|
||||
auto_connect: c.auto_connect,
|
||||
will_enabled,
|
||||
will_retain,
|
||||
ssl_ignore_ca: c.ssl.ignore_ca,
|
||||
@@ -566,6 +568,7 @@ impl ConnectionForm {
|
||||
topic_alias_maximum,
|
||||
auto_resubscribe: self.auto_resubscribe,
|
||||
auto_reconnect: self.auto_reconnect,
|
||||
auto_connect: self.auto_connect,
|
||||
last_will,
|
||||
created_at: self.created_at,
|
||||
group,
|
||||
@@ -629,6 +632,7 @@ impl ConnectionForm {
|
||||
match id {
|
||||
"clean_start" => this.clean_start = v,
|
||||
"auto_resubscribe" => this.auto_resubscribe = v,
|
||||
"auto_connect" => this.auto_connect = v,
|
||||
"auto_reconnect" => this.auto_reconnect = v,
|
||||
"will_enabled" => this.will_enabled = v,
|
||||
"will_retain" => this.will_retain = v,
|
||||
@@ -807,7 +811,8 @@ impl Render for ConnectionForm {
|
||||
)
|
||||
.child(self.switch_row("clean_start", "Clean Start / Clean Session", self.clean_start, cx))
|
||||
.child(self.switch_row("auto_reconnect", "断线自动重连", self.auto_reconnect, cx))
|
||||
.child(self.switch_row("auto_resubscribe", "连接后自动恢复订阅", self.auto_resubscribe, cx)),
|
||||
.child(self.switch_row("auto_resubscribe", "连接后自动恢复订阅", self.auto_resubscribe, cx))
|
||||
.child(self.switch_row("auto_connect", "启动时自动连接", self.auto_connect, cx)),
|
||||
cx,
|
||||
))
|
||||
// ── SSL/TLS(仅 TLS/WSS 显示) ──
|
||||
|
||||
Reference in New Issue
Block a user