Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: optimize gdbus call process in system monitor #394

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions deepin-system-monitor-daemon/src/systemmonitorservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ bool SystemMonitorService::checkCpuAlarm()
process.start("gdbus", args);
process.waitForFinished(5000);
if (process.exitCode() != 0) {
QProcess::startDetached(cmd);
process.start("gdbus", args);
process.waitForFinished(5000);
}
});
}
Expand All @@ -314,7 +315,8 @@ bool SystemMonitorService::checkMemoryAlarm()
process.start("gdbus", args);
process.waitForFinished(5000);
if (process.exitCode() != 0) {
QProcess::startDetached(cmd);
process.start("gdbus", args);
process.waitForFinished(5000);
}
});
}
Expand Down
46 changes: 24 additions & 22 deletions deepin-system-monitor-main/gui/dialog/systemprotectionsetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,36 +529,38 @@ void SystemProtectionSetting::onSettingItemChanged(const QString &key, const QVa

//QString cmd("qdbus org.deepin.SystemMonitorDaemon /org/deepin/SystemMonitorDaemon org.deepin.SystemMonitorDaemon.");
//qdbus 改为gdbus
QString cmd("gdbus call -e -d org.deepin.SystemMonitorDaemon -o /org/deepin/SystemMonitorDaemon -m org.deepin.SystemMonitorDaemon.");
bool needCall = false;
QString program = "gdbus";
QStringList arguments;
arguments << "call" << "-e" << "-d" << "org.deepin.SystemMonitorDaemon"
<< "-o" << "/org/deepin/SystemMonitorDaemon"
<< "-m" << "org.deepin.SystemMonitorDaemon.";

// 拼接dbus调用命令字串
// 根据不同的key添加对应的方法名和参数
if (key == AlarmStatusOptionName) {
cmd.append("setSystemProtectionStatus "); // Method Name
cmd.append(value.toString()); // value
needCall = true;
arguments.last().append("setSystemProtectionStatus");
arguments << value.toString();
} else if (key == AlarmCpuUsageOptionName) {
cmd.append("setAlarmUsageOfCpu "); // Method Name
cmd.append(value.toString()); // value
needCall = true;
arguments.last().append("setAlarmUsageOfCpu");
arguments << value.toString();
} else if (key == AlarmMemUsageOptionName) {
cmd.append("setAlarmUsageOfMemory "); // Method Name
cmd.append(value.toString()); // value
needCall = true;
arguments.last().append("setAlarmUsageOfMemory");
arguments << value.toString();
} else if (key == AlarmIntervalOptionName) {
cmd.append("setAlarmMsgInterval "); // Method Name
cmd.append(value.toString()); // value
needCall = true;
arguments.last().append("setAlarmMsgInterval");
arguments << value.toString();
} else if (key == AlarmLastTimeOptionName) {
cmd.append("setAlarmLastTimeInterval "); // Mehthod Name
cmd.append(value.toString());
needCall = true;
arguments.last().append("setAlarmLastTimeInterval");
arguments << value.toString();
} else {
return;
}

if (needCall) {
qCDebug(app) << __FUNCTION__ << __LINE__ << ",dbus cmd:" << cmd;
QTimer::singleShot(100, this, [=]() { QProcess::startDetached(cmd); });
}
QTimer::singleShot(100, this, [=]() {
qCDebug(app) << __FUNCTION__ << __LINE__ << ",dbus cmd:" << program << arguments;
QProcess process;
process.start(program, arguments);
process.waitForFinished(5000);
});
}

DSettings *SystemProtectionSetting::getDSettingPointor()
Expand Down