nova-shell/modules/Bluetooth.qml
2026-04-12 10:57:48 +02:00

45 lines
1.2 KiB
QML

import QtQuick
import Quickshell.Io
import "." as M
M.BarSection {
id: root
spacing: M.Theme.moduleSpacing
tooltip: root.status === "connected" ? "Bluetooth: " + root.device : "Bluetooth: on"
property string status: "off"
property string device: ""
Process {
id: proc
running: true
command: ["sh", "-c", "bluetoothctl info 2>/dev/null | awk -F': ' '/Name/ {n=$2} /Connected: yes/ {c=1} END {if (c) print n; else print \"\"}'"]
stdout: StdioCollector {
onStreamFinished: {
const t = text.trim();
root.device = t;
root.status = t ? "connected" : "on";
}
}
}
Timer {
interval: 10000
running: true
repeat: true
onTriggered: proc.running = true
}
M.BarIcon {
visible: root.status === "connected"
icon: "\uF294"
anchors.verticalCenter: parent.verticalCenter
}
Text {
visible: root.status === "connected"
text: root.device
color: M.Theme.base05
font.pixelSize: M.Theme.fontSize + 1
font.family: M.Theme.fontFamily
anchors.verticalCenter: parent.verticalCenter
}
}