#pragma once #include "tickingservice.hpp" #include "config/enums.hpp" #include #include #include namespace ZShell::services { using GpuType = config::GpuType::Enum; struct VramFiles { QString used; QString total; }; class Gpu : public TickingService { Q_OBJECT QML_ELEMENT QML_SINGLETON Q_PROPERTY(GpuType type READ type NOTIFY typeChanged) Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(bool detecting READ detecting NOTIFY detectingChanged) Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged) Q_PROPERTY(qreal temperature READ temperature NOTIFY temperatureChanged) Q_PROPERTY(qreal memoryUsed READ memoryUsed NOTIFY memoryUsedChanged) Q_PROPERTY(qreal memoryTotal READ memoryTotal NOTIFY memoryTotalChanged) public: explicit Gpu(QObject* parent = nullptr); ~Gpu() override; [[nodiscard]] GpuType type() const; [[nodiscard]] QString name() const; [[nodiscard]] bool detecting() const; [[nodiscard]] qreal percentage() const; [[nodiscard]] qreal temperature() const; [[nodiscard]] qreal memoryUsed() const; [[nodiscard]] qreal memoryTotal() const; signals: void typeChanged(); void nameChanged(); void detectingChanged(); void percentageChanged(); void temperatureChanged(); void memoryUsedChanged(); void memoryTotalChanged(); protected: void tick() override; void onStopped() override; private: void resolveGpu(); [[nodiscard]] int probeEnd() const; void tryNameSource(int index, int generation); void finishNameSource(int index, int generation, QString name); void readGenericUsage(); void stopNvidiaUsage(); void startNvidiaUsage(); void readGpuTemperature(); void readGenericMemory(); void resetUsage(); void runProcess( const QString& program, const QStringList& args, std::function callback); void setType(GpuType value); void setName(QString value); void setDetecting(bool value); void setMemoryUsed(qreal value); void setMemoryTotal(qreal value); void refreshSysfsCache(); GpuType m_userType = GpuType::Auto; GpuType m_type = GpuType::None; QString m_name; bool m_detecting = false; qreal m_percentage = 0.0; qreal m_temperature = 0.0; qreal m_memoryUsed = 0.0; qreal m_memoryTotal = 0.0; QStringList m_busyFiles; QList m_vramFiles; int m_generation = 0; bool m_nvidiaQuerying = false; QProcess* m_nvidiaProc = nullptr; QTimer* m_restartTimer = nullptr; }; } // namespace ZShell::services