fix:修复弹出两次导出通知的问题

This commit is contained in:
2025-09-25 08:25:25 +08:00
parent 642f658230
commit 4951fc7dd1

View File

@@ -24,8 +24,8 @@ SettingsPage::SettingsPage(QWidget *parent)
configCanSave = false; configCanSave = false;
initConfig(); initConfig();
// 连接导出日志按钮的点击信号 // 移除了手动连接导出日志按钮的点击信号
connect(ui->pushButton_exportLog, &QPushButton::clicked, this, &SettingsPage::on_pushButton_exportLog_clicked); // connect(ui->pushButton_exportLog, &QPushButton::clicked, this, &SettingsPage::on_pushButton_exportLog_clicked);
} }
void SettingsPage::setTheme(bool dark) void SettingsPage::setTheme(bool dark)
@@ -283,29 +283,25 @@ void SettingsPage::on_checkBox_disableSandbox_clicked(bool checked)
// 修改导出日志按钮的点击事件处理函数 // 修改导出日志按钮的点击事件处理函数
void SettingsPage::on_pushButton_exportLog_clicked() void SettingsPage::on_pushButton_exportLog_clicked()
{ {
auto future = QtConcurrent::run([=]() { // 禁用按钮防止重复点击
// 禁用按钮防止重复点击 ui->pushButton_exportLog->setEnabled(false);
QMetaObject::invokeMethod(ui->pushButton_exportLog, "setEnabled", Qt::QueuedConnection, Q_ARG(bool, false));
QString targetPath = QString::fromUtf8(TMP_PATH);
QString targetPath = QString::fromUtf8(TMP_PATH); bool success = Utils::exportLogs(targetPath);
bool success = Utils::exportLogs(targetPath);
// 显示导出结果通知
// 显示导出结果通知 QString message;
QString message; if (success) {
if (success) { message = tr("Logs exported successfully to: %1").arg(targetPath);
message = tr("Logs exported successfully to: %1").arg(targetPath); Utils::writeLog("INFO", "User exported logs via settings page");
Utils::writeLog("INFO", "User exported logs via settings page"); } else {
} else { message = tr("Failed to export logs");
message = tr("Failed to export logs"); Utils::writeLog("ERROR", "User failed to export logs via settings page");
Utils::writeLog("ERROR", "User failed to export logs via settings page"); }
}
// 只发送一次系统通知
// 在主线程显示消息框 Utils::sendNotification("spark-store", tr("Export Logs"), message);
QMetaObject::invokeMethod(this, [message, this]() {
// 使用系统通知代替QMessageBox弹窗避免重复通知 // 重新启用按钮
Utils::sendNotification("spark-store", tr("Export Logs"), message); ui->pushButton_exportLog->setEnabled(true);
// 重新启用按钮
ui->pushButton_exportLog->setEnabled(true);
}, Qt::QueuedConnection);
});
} }