skeledance/plugin/contents/ui/main.qml
2026-06-07 10:45:58 -03:00

56 lines
1.6 KiB
QML

import QtQuick 2.0
import QtWebEngine 1.10
import org.kde.plasma.core
import org.kde.plasma.plasmoid
import org.kde.plasma.plasma5support as Plasma5Support
WallpaperItem {
id: root
WebEngineView {
id: webView
anchors.fill: parent
url: Qt.resolvedUrl("dancer.html")
backgroundColor: "#000814"
settings {
javascriptEnabled: true
localContentCanAccessFileUrls: true
localContentCanAccessRemoteUrls: true
localStorageEnabled: false
}
onContextMenuRequested: function(request) {
request.accepted = true
}
}
// Start CAVA on load
Plasma5Support.DataSource {
id: cavaStarter
engine: "executable"
connectedSources: ["bash " + Qt.resolvedUrl("cava-start.sh").toString().replace("file://", "") + " &"]
interval: 0
}
// Polls playerctl every 2s and injects music info into the page
Plasma5Support.DataSource {
id: musicSource
engine: "executable"
connectedSources: ["playerctl metadata --format '{{status}}||{{artist}}||{{title}}' 2>/dev/null || echo '||'"]
interval: 2000
onNewData: function(sourceName, data) {
var raw = data["stdout"].trim()
var parts = raw.split("||")
var status = parts[0] || ""
var artist = status === "Playing" ? (parts[1] || "") : ""
var title = status === "Playing" ? (parts[2] || "") : ""
webView.runJavaScript(
"updateMusic(" + JSON.stringify(artist) + "," + JSON.stringify(title) + ")"
)
}
}
}