core: add more data fields

This commit is contained in:
Vaxry 2024-10-13 21:15:37 +01:00
parent 5b8deaaad0
commit 6a8260e134
4 changed files with 109 additions and 2 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 71 KiB

View file

@ -151,6 +151,26 @@ ApplicationWindow {
Layout.leftMargin: 60 Layout.leftMargin: 60
Layout.rightMargin: 60 Layout.rightMargin: 60
Text {
visible: hsi.getUserAt().length() > 0
text: "User: " + hsi.getUserAt()
Layout.maximumWidth: _width - 120
color: system.windowText
elide: Text.ElideRight
textFormat: Text.PlainText
wrapMode: Text.NoWrap
}
Text {
visible: hsi.getModel().length() > 0
text: "Model: " + hsi.getModel()
Layout.maximumWidth: _width - 120
color: system.windowText
elide: Text.ElideRight
textFormat: Text.PlainText
wrapMode: Text.NoWrap
}
Text { Text {
text: "CPU: " + hsi.getCPUInfo() text: "CPU: " + hsi.getCPUInfo()
Layout.maximumWidth: _width - 120 Layout.maximumWidth: _width - 120
@ -185,6 +205,33 @@ ApplicationWindow {
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
} }
Text {
text: "DE: " + hsi.getDE()
Layout.maximumWidth: _width - 120
color: system.windowText
elide: Text.ElideRight
textFormat: Text.PlainText
wrapMode: Text.NoWrap
}
Text {
text: "Uptime: " + hsi.getUptime()
Layout.maximumWidth: _width - 120
color: system.windowText
elide: Text.ElideRight
textFormat: Text.PlainText
wrapMode: Text.NoWrap
}
Text {
text: "Displays: " + hsi.getDisplays()
Layout.maximumWidth: _width - 120
color: system.windowText
elide: Text.ElideRight
textFormat: Text.PlainText
wrapMode: Text.NoWrap
}
} }
Rectangle { Rectangle {

View file

@ -23,6 +23,8 @@ class CSystemInternals : public QObject {
QString hlSystemInfo = "[error]", hlSystemVersion = "[error]"; QString hlSystemInfo = "[error]", hlSystemVersion = "[error]";
QString uptime = "unknown", DE = "Unknown", screens = "unknown", board = "", user = "";
Q_INVOKABLE bool hasSystemLogoName() { Q_INVOKABLE bool hasSystemLogoName() {
return systemLogoName.size() > 0; return systemLogoName.size() > 0;
} }
@ -73,6 +75,26 @@ class CSystemInternals : public QObject {
return ramInfo; return ramInfo;
} }
Q_INVOKABLE QString getDE() {
return DE;
}
Q_INVOKABLE QString getUptime() {
return uptime;
}
Q_INVOKABLE QString getDisplays() {
return screens;
}
Q_INVOKABLE QString getModel() {
return board;
}
Q_INVOKABLE QString getUserAt() {
return user;
}
Q_INVOKABLE void copySystemInfo(); Q_INVOKABLE void copySystemInfo();
Q_INVOKABLE void copyVersion(); Q_INVOKABLE void copyVersion();
}; };

View file

@ -4,6 +4,7 @@
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QQmlContext> #include <QQmlContext>
#include <QQuickStyle> #include <QQuickStyle>
#include <QScreen>
#include <fstream> #include <fstream>
#include <format> #include <format>
#include "util/Utils.hpp" #include "util/Utils.hpp"
@ -12,7 +13,19 @@
#include <hyprutils/string/String.hpp> #include <hyprutils/string/String.hpp>
using namespace Hyprutils::String; using namespace Hyprutils::String;
static void getSystemInfo(CSystemInternals* hsi) { static std::string readFile(const std::string& filename) {
try {
std::ifstream ifs(filename);
if (ifs.good()) {
std::string data(std::istreambuf_iterator<char>{ifs}, {});
ifs.close();
return trim(data);
}
} catch (...) { return "[error]"; }
return "[error]";
}
static void getSystemInfo(CSystemInternals* hsi, QGuiApplication* app) {
// gather data from os-release // gather data from os-release
std::ifstream osInfo("/etc/os-release"); std::ifstream osInfo("/etc/os-release");
@ -147,6 +160,31 @@ static void getSystemInfo(CSystemInternals* hsi) {
hsi->ramInfo = std::format("{} / {}", ramIntToReadable(props[2]), ramIntToReadable(props[1])).c_str(); hsi->ramInfo = std::format("{} / {}", ramIntToReadable(props[2]), ramIntToReadable(props[1])).c_str();
} }
} }
// other, misc
if (const auto DE = getenv("XDG_CURRENT_DESKTOP"); DE)
hsi->DE = DE;
if (const auto UPTIME = execAndGet("uptime -p"); !UPTIME.empty())
hsi->uptime = trim(UPTIME.find("up ") == 0 ? UPTIME.substr(3) : UPTIME).c_str();
{
std::string screens;
for (auto& s : app->screens()) {
screens += std::format("{} ({}x{}), ", s->name().toStdString(), s->geometry().width(), s->geometry().height());
}
if (!screens.empty())
screens = screens.substr(0, screens.length() - 2);
hsi->screens = screens.c_str();
}
hsi->user = std::format("{}@{}", trim(execAndGet("whoami")), readFile("/etc/hostname")).c_str();
if (const auto BOARD = readFile("/sys/devices/virtual/dmi/id/board_name"); BOARD != "[error]")
hsi->board = BOARD.c_str();
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
@ -158,7 +196,7 @@ int main(int argc, char* argv[]) {
auto systemInternals = new CSystemInternals; auto systemInternals = new CSystemInternals;
getSystemInfo(systemInternals); getSystemInfo(systemInternals, &app);
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("hsi", systemInternals); engine.rootContext()->setContextProperty("hsi", systemInternals);