2026-02-24 15:39:48 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
import org.kde.plasma.plasmoid 2.0
|
|
|
|
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
2026-02-24 19:20:25 +00:00
|
|
|
import org.kde.plasma.components 2.0 as PlasmaComponents
|
2026-02-24 16:19:31 +00:00
|
|
|
import "logic/CpuReader.js" as Reader
|
|
|
|
|
import "logic/CpuWriter.js" as Writer
|
2026-02-24 15:39:48 +00:00
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: root
|
|
|
|
|
|
2026-02-24 16:19:31 +00:00
|
|
|
property int temperature: 0
|
|
|
|
|
property int currentPerf: 100
|
2026-02-24 15:39:48 +00:00
|
|
|
|
|
|
|
|
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
|
|
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
|
interval: 3000
|
|
|
|
|
running: true
|
|
|
|
|
repeat: true
|
|
|
|
|
triggeredOnStart: true
|
2026-02-24 16:19:31 +00:00
|
|
|
onTriggered: statusSource.connectSource(Reader.buildReadCommand())
|
2026-02-24 15:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlasmaCore.DataSource {
|
2026-02-24 16:19:31 +00:00
|
|
|
id: statusSource
|
2026-02-24 15:39:48 +00:00
|
|
|
engine: "executable"
|
|
|
|
|
onNewData: {
|
2026-02-24 16:19:31 +00:00
|
|
|
var result = Reader.parseOutput(data["stdout"])
|
|
|
|
|
if (result.valid) {
|
|
|
|
|
root.temperature = result.tempC
|
|
|
|
|
root.currentPerf = result.perf
|
2026-02-24 15:39:48 +00:00
|
|
|
}
|
|
|
|
|
disconnectSource(sourceName)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlasmaCore.DataSource {
|
2026-02-24 16:19:31 +00:00
|
|
|
id: writeSource
|
2026-02-24 15:39:48 +00:00
|
|
|
engine: "executable"
|
|
|
|
|
onNewData: {
|
|
|
|
|
disconnectSource(sourceName)
|
2026-02-24 16:19:31 +00:00
|
|
|
statusSource.connectSource(Reader.buildReadCommand())
|
2026-02-24 15:39:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 16:19:31 +00:00
|
|
|
function setPerf(value) {
|
|
|
|
|
var cmd = Writer.buildSetCommand(value)
|
|
|
|
|
if (cmd) writeSource.connectSource(cmd)
|
2026-02-24 15:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-24 19:20:25 +00:00
|
|
|
Plasmoid.compactRepresentation: MouseArea {
|
|
|
|
|
implicitWidth: compactRow.implicitWidth
|
|
|
|
|
implicitHeight: compactRow.implicitHeight
|
2026-02-24 16:19:31 +00:00
|
|
|
onClicked: plasmoid.expanded = !plasmoid.expanded
|
2026-02-24 19:20:25 +00:00
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
id: compactRow
|
|
|
|
|
spacing: 4
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
|
|
|
|
|
PlasmaCore.IconItem {
|
|
|
|
|
source: "cpu"
|
|
|
|
|
width: units.iconSizes.small
|
|
|
|
|
height: units.iconSizes.small
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlasmaComponents.Label {
|
|
|
|
|
text: root.temperature + "°C"
|
|
|
|
|
color: Reader.tempColor(root.temperature)
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-24 15:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-24 16:19:31 +00:00
|
|
|
Plasmoid.fullRepresentation: FullView {
|
|
|
|
|
temperature: root.temperature
|
|
|
|
|
currentPerf: root.currentPerf
|
|
|
|
|
onPerfChangeRequested: root.setPerf(newValue)
|
2026-02-24 15:39:48 +00:00
|
|
|
}
|
|
|
|
|
}
|