mirror of
https://github.com/hyprwm/hyprsysteminfo.git
synced 2024-11-24 09:15:59 +01:00
core: use c++ instead of uptime
This commit is contained in:
parent
3ead3bf94e
commit
e901bb17ce
1 changed files with 17 additions and 2 deletions
19
src/main.cpp
19
src/main.cpp
|
@ -165,8 +165,23 @@ static void getSystemInfo(CSystemInternals* hsi, QGuiApplication* app) {
|
||||||
if (const auto DE = getenv("XDG_CURRENT_DESKTOP"); DE)
|
if (const auto DE = getenv("XDG_CURRENT_DESKTOP"); DE)
|
||||||
hsi->DE = DE;
|
hsi->DE = DE;
|
||||||
|
|
||||||
if (const auto UPTIME = execAndGet("uptime -p"); !UPTIME.empty())
|
if (const auto UPTIME = readFile("/proc/uptime"); UPTIME != "[error]") {
|
||||||
hsi->uptime = trim(UPTIME.find("up ") == 0 ? UPTIME.substr(3) : UPTIME).c_str();
|
CVarList data(UPTIME, 0, 's', true);
|
||||||
|
try {
|
||||||
|
int uptimeSeconds = std::round(std::stof(data[0]));
|
||||||
|
int uptimeDays = std::floor(uptimeSeconds / 3600.0 / 24.0);
|
||||||
|
int uptimeHours = std::floor((uptimeSeconds % (3600 * 24)) / 3600.0);
|
||||||
|
int uptimeMinutes = std::floor((uptimeSeconds % (3600)) / 60.0);
|
||||||
|
|
||||||
|
auto upStr = std::format("{}{}{}", (uptimeDays > 0 ? std::format("{} days, ", uptimeDays) : ""), (uptimeHours > 0 ? std::format("{} hours, ", uptimeHours) : ""),
|
||||||
|
(uptimeMinutes > 0 ? std::format("{} minutes, ", uptimeMinutes) : ""));
|
||||||
|
|
||||||
|
if (!upStr.empty())
|
||||||
|
upStr = upStr.substr(0, upStr.length() - 2);
|
||||||
|
|
||||||
|
hsi->uptime = upStr.c_str();
|
||||||
|
} catch (...) { ; }
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::string screens;
|
std::string screens;
|
||||||
|
|
Loading…
Reference in a new issue