106 lines
2.7 KiB
QML
106 lines
2.7 KiB
QML
import QtQuick
|
|
import QtQuick.Layouts
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
import "../core"
|
|
|
|
RowLayout {
|
|
spacing: 8
|
|
|
|
// State properties
|
|
property string wifiSsid: ""
|
|
property bool btConnected: false
|
|
property string batteryPct: ""
|
|
property bool isCharging: false
|
|
|
|
// Visibility
|
|
property var monitor: null
|
|
property bool exclusiveToScreen: false
|
|
|
|
// Poller
|
|
Timer {
|
|
interval: 3000
|
|
running: true
|
|
repeat: true
|
|
triggeredOnStart: true
|
|
onTriggered: {
|
|
wifiProcess.running = true
|
|
btProcess.running = true
|
|
batProcess.running = true
|
|
}
|
|
}
|
|
|
|
// Wifi
|
|
Process {
|
|
id: wifiProcess
|
|
command: ["sh", "-c", "nmcli -t -f active,ssid dev wifi | grep '^yes' | cut -d: -f2"]
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
wifiSsid = text.trim();
|
|
}
|
|
}
|
|
onExited: function(code, status) {
|
|
if (code !== 0) wifiSsid = "";
|
|
}
|
|
}
|
|
|
|
// Bluetooth
|
|
Process {
|
|
id: btProcess
|
|
command: ["sh", "-c", "bluetoothctl info | grep 'Connected: yes'"]
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
btConnected = text.trim().length > 0;
|
|
}
|
|
}
|
|
onExited: function(code, status) {
|
|
if (code !== 0) btConnected = false;
|
|
}
|
|
}
|
|
|
|
// Battery
|
|
Process {
|
|
id: batProcess
|
|
command: ["sh", "-c", "if ls /sys/class/power_supply/BAT* >/dev/null 2>&1; then cat /sys/class/power_supply/BAT*/capacity | head -n1; cat /sys/class/power_supply/BAT*/status | head -n1; fi"]
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
var lines = text.trim().split("\n");
|
|
if (lines.length >= 2) {
|
|
batteryPct = lines[0];
|
|
isCharging = (lines[1] === "Charging");
|
|
} else {
|
|
batteryPct = "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// UI Elements
|
|
ModuleContainer {
|
|
monitor: parent.monitor
|
|
exclusiveToScreen: parent.exclusiveToScreen
|
|
active: wifiSsid !== ""
|
|
pillColor: Theme.primary
|
|
icon: ""
|
|
text: wifiSsid
|
|
}
|
|
|
|
ModuleContainer {
|
|
monitor: parent.monitor
|
|
exclusiveToScreen: parent.exclusiveToScreen
|
|
active: btConnected
|
|
pillColor: Theme.primary
|
|
icon: ""
|
|
text: "Connected"
|
|
}
|
|
|
|
ModuleContainer {
|
|
monitor: parent.monitor
|
|
exclusiveToScreen: parent.exclusiveToScreen
|
|
active: batteryPct !== ""
|
|
pillColor: Theme.accent
|
|
icon: isCharging ? "" : ""
|
|
text: batteryPct + "%"
|
|
}
|
|
}
|