Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/features/power/fixtures/services/Power.qml

Raw
import QtQuick

Item {
    // Inputs the registry forwards to the production service.
    property var upower: null
    property var lockService: null
    property var niriService: null
    property bool batteryPresent: true
    property int batteryPercent: 72
    property string batteryState: "discharging"
    readonly property string batteryRole: batteryPercent <= 10 ? "error" : (batteryPercent <= 25 ? "warning" : "ui.accent")
    readonly property string batteryTimeEstimate: "3 hours"
    readonly property real batteryHealth: 94
    readonly property bool isLaptopBattery: batteryPresent
    readonly property string batteryStatus: !isLaptopBattery ? "" : batteryState === "charging" || batteryState === "pendingcharge" ? "charging" : batteryState === "full" ? "full" : lowPowerMode ? "on battery" : ""
    readonly property bool lowPowerMode: batteryState === "discharging" || batteryState === "pendingdischarge"
    // The production rule: a low or critical main battery that is not charging.
    readonly property string batteryAttention: batteryPresent && batteryState === "discharging" ? (batteryPercent <= 10 ? "error" : (batteryPercent <= 25 ? "warning" : "")) : ""
    property var externalDevices: []
    readonly property int externalDeviceCount: externalDevices.length
    readonly property var sessionActions: ["lock", "suspend", "monitor-off", "logout", "reboot", "poweroff"]
    property string pendingConfirmation: ""
    property int armCount: 0
    property int confirmCount: 0
    property int cancelCount: 0
    property int immediateCount: 0

    function sessionAction(kind) {
        const action = String(kind);
        if (action === "logout" || action === "reboot" || action === "poweroff") {
            pendingConfirmation = action;
            armCount++;
        } else {
            pendingConfirmation = "";
            immediateCount++;
        }
    }

    function confirmAction(kind) {
        if (pendingConfirmation === String(kind))
            confirmCount++;
        pendingConfirmation = "";
    }

    function cancelAction() {
        pendingConfirmation = "";
        cancelCount++;
    }

    function setBattery(present) {
        batteryPresent = !!present;
    }

    function setBatteryLevel(percent, state) {
        batteryPercent = Number(percent);
        batteryState = String(state);
    }

    function setDevices(names) {
        externalDevices = names.map((name, index) => ({
                    "name": name,
                    "percent": 40 + index * 10
                }));
    }

    function fixtureState() {
        return {
            "armed": pendingConfirmation,
            "arms": armCount,
            "confirms": confirmCount,
            "cancels": cancelCount,
            "immediate": immediateCount,
            "attention": batteryAttention
        };
    }
}