feat: Add music and sysinfo to top bar (togglable) - also a bunch of misc fixes

This commit is contained in:
ferreo 2025-07-14 20:40:43 +01:00
parent e1caf737fe
commit b4697235c0
29 changed files with 795 additions and 399 deletions

View file

@ -2,116 +2,22 @@ import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import Quickshell.Io
import "root:/Settings" as Settings
import "root:/Components" as Components
import qs.Components
import qs.Services
import qs.Settings
Rectangle {
id: systemMonitor
width: 70
height: 200
height: 250
color: "transparent"
property real cpuUsage: 0
property real memoryUsage: 0
property real diskUsage: 0
property bool isVisible: false
Timer {
id: cpuTimer
interval: 2000
repeat: true
running: isVisible
onTriggered: cpuInfo.running = true
}
Timer {
id: memoryTimer
interval: 3000
repeat: true
running: isVisible
onTriggered: memoryInfo.running = true
}
Timer {
id: diskTimer
interval: 5000
repeat: true
running: isVisible
onTriggered: diskInfo.running = true
}
// Process for getting CPU usage
Process {
id: cpuInfo
command: ["sh", "-c", "top -bn1 | grep 'Cpu(s)' | awk '{print $2}' | awk -F'%' '{print $1}'"]
running: false
stdout: SplitParser {
onRead: data => {
let usage = parseFloat(data.trim())
if (!isNaN(usage)) {
systemMonitor.cpuUsage = usage
}
cpuInfo.running = false
}
}
}
// Process for getting memory usage
Process {
id: memoryInfo
command: ["sh", "-c", "free | grep Mem | awk '{print int($3/$2 * 100)}'"]
running: false
stdout: SplitParser {
onRead: data => {
let usage = parseFloat(data.trim())
if (!isNaN(usage)) {
systemMonitor.memoryUsage = usage
}
memoryInfo.running = false
}
}
}
// Process for getting disk usage
Process {
id: diskInfo
command: ["sh", "-c", "df / | tail -1 | awk '{print int($5)}'"]
running: false
stdout: SplitParser {
onRead: data => {
let usage = parseFloat(data.trim())
if (!isNaN(usage)) {
systemMonitor.diskUsage = usage
}
diskInfo.running = false
}
}
}
// Function to start monitoring
function startMonitoring() {
isVisible = true
// Trigger initial readings
cpuInfo.running = true
memoryInfo.running = true
diskInfo.running = true
}
// Function to stop monitoring
function stopMonitoring() {
isVisible = false
cpuInfo.running = false
memoryInfo.running = false
diskInfo.running = false
}
Rectangle {
id: card
anchors.fill: parent
color: Settings.Theme.surface
color: Theme.surface
radius: 18
ColumnLayout {
@ -121,8 +27,8 @@ Rectangle {
Layout.alignment: Qt.AlignVCenter
// CPU Usage
Components.CircularProgressBar {
progress: cpuUsage / 100
CircularProgressBar {
progress: Sysinfo.cpuUsage / 100
size: 50
strokeWidth: 4
hasNotch: true
@ -131,9 +37,21 @@ Rectangle {
Layout.alignment: Qt.AlignHCenter
}
// Cpu Temp
CircularProgressBar {
progress: Sysinfo.cpuTemp / 100
size: 50
strokeWidth: 4
hasNotch: true
units: "°C"
notchIcon: "thermometer"
notchIconSize: 14
Layout.alignment: Qt.AlignHCenter
}
// Memory Usage
Components.CircularProgressBar {
progress: memoryUsage / 100
CircularProgressBar {
progress: Sysinfo.memoryUsagePer / 100
size: 50
strokeWidth: 4
hasNotch: true
@ -143,8 +61,8 @@ Rectangle {
}
// Disk Usage
Components.CircularProgressBar {
progress: diskUsage / 100
CircularProgressBar {
progress: Sysinfo.diskUsage / 100
size: 50
strokeWidth: 4
hasNotch: true