mirror of
https://github.com/hyprwm/hyprsysteminfo.git
synced 2024-11-21 16:15:59 +01:00
core: add more data fields
This commit is contained in:
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 |
47
qml/main.qml
47
qml/main.qml
|
@ -151,6 +151,26 @@ ApplicationWindow {
|
|||
Layout.leftMargin: 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: "CPU: " + hsi.getCPUInfo()
|
||||
Layout.maximumWidth: _width - 120
|
||||
|
@ -185,6 +205,33 @@ ApplicationWindow {
|
|||
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 {
|
||||
|
|
|
@ -23,6 +23,8 @@ class CSystemInternals : public QObject {
|
|||
|
||||
QString hlSystemInfo = "[error]", hlSystemVersion = "[error]";
|
||||
|
||||
QString uptime = "unknown", DE = "Unknown", screens = "unknown", board = "", user = "";
|
||||
|
||||
Q_INVOKABLE bool hasSystemLogoName() {
|
||||
return systemLogoName.size() > 0;
|
||||
}
|
||||
|
@ -73,6 +75,26 @@ class CSystemInternals : public QObject {
|
|||
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 copyVersion();
|
||||
};
|
||||
|
|
42
src/main.cpp
42
src/main.cpp
|
@ -4,6 +4,7 @@
|
|||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickStyle>
|
||||
#include <QScreen>
|
||||
#include <fstream>
|
||||
#include <format>
|
||||
#include "util/Utils.hpp"
|
||||
|
@ -12,7 +13,19 @@
|
|||
#include <hyprutils/string/String.hpp>
|
||||
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
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// 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[]) {
|
||||
|
@ -158,7 +196,7 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
auto systemInternals = new CSystemInternals;
|
||||
|
||||
getSystemInfo(systemInternals);
|
||||
getSystemInfo(systemInternals, &app);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
engine.rootContext()->setContextProperty("hsi", systemInternals);
|
||||
|
|
Loading…
Reference in a new issue