Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/test-fixtures/ui/services/Resources.qml

Raw
import QtQuick

Item {
    required property var upower
    required property var powerProfiles
    required property var brightnessService
    property bool popoutOpen: false
    property int opens: 0
    property int closes: 0
    onPopoutOpenChanged: {
        if (popoutOpen)
            opens++;
        else
            closes++;
    }
    property var identity: ({
            host: "fixture-host",
            model: "synthetic machine",
            distro: "fixture linux",
            kernel: "test kernel",
            wm: "nested niri",
            packages: 123,
            shell: "fixture",
            uptime: "2 hours"
        })
    property var failedUnits: ["fixture.service"]
    property var incidents: []
    property var extraIssues: []
    property string incidentStatus: "ready"
    property string agentIssueId: ""
    property bool agentPending: false
    property string agentError: ""
    property int agentActions: 0
    signal agentDispatched
    property real cpuTemperatureC: 52
    property real diskUsage: 0.3
    property int updateCount: 0
    property real memoryUsage: 0.4
    property bool swapGrowing: false
    property real loadOne: 0.5
    property real loadFive: 0.3
    property real loadFifteen: 0.2
    property int cores: 4
    property real healthPercentage: 95
    property bool isLaptopBattery: true
    property int batteryPercent: 80
    property string batteryStatus: "charging"
    property real cpuUsage: 0.25
    property real memTotal: 8000000000
    property real memAvailable: 4800000000
    property real swapTotal: 0
    property real swapFree: 0
    property real swapUsage: 0
    property real fanRpm: 1200
    property real tempHighC: 90
    property real networkRxRate: 1024
    property real networkTxRate: 512
    property real diskReadRate: 2048
    property real diskWriteRate: 1024
    property var cpuRing: [0.1, 0.4, 0.2, 0.25]
    property var memRing: [0.2, 0.3, 0.4]
    property var tempRing: [40, 48, 52]
    property var netRing: [1000, 2000, 1536]
    property var netTxRing: [100, 800, 512]
    property var netRxRing: [900, 1200, 1024]
    property var diskRing: [1000, 4000, 3072]
    property var diskReadRing: [500, 3000, 2048]
    property var diskWriteRing: [500, 1000, 1024]
    property var processes: [
        {
            name: "fixture-worker",
            cpu: 25
        }
    ]
    property int actions: 0
    property string lastAction: ""

    function issues() {
        return (failedUnits.length ? [
                {
                    id: "fixture-unit",
                    severity: "error",
                    label: "fixture service failed",
                    detail: "synthetic issue action",
                    action: true
                }
            ] : []).concat(extraIssues, incidents);
    }

    function runIssueAgent(id) {
        if (agentPending)
            return;
        agentIssueId = id;
        agentPending = true;
        agentError = "";
        agentActions++;
    }

    function agentResult(success) {
        agentPending = false;
        if (success)
            agentDispatched();
        else
            agentError = "pi or wezterm unavailable in session path";
    }

    function showIncidents() {
        const latest = {
            source: "crash",
            bootId: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            cursor: "s=fixture-crash",
            timestamp: new Date(Date.now() - 720000).toISOString(),
            metadata: {
                comm: "fixture editor",
                executable: "/usr/bin/fixture-editor",
                uid: "1000",
                signal: "SIGSEGV",
                pid: "123"
            }
        };
        const earlier = Object.assign({}, latest, {
            cursor: "s=fixture-earlier",
            timestamp: new Date(Date.now() - 1440000).toISOString(),
            metadata: Object.assign({}, latest.metadata, {
                signal: "SIGABRT",
                pid: "100"
            })
        });
        const oldest = Object.assign({}, earlier, {
            cursor: "s=fixture-oldest",
            timestamp: new Date(Date.now() - 1800000).toISOString()
        });
        incidents = [
            {
                id: "crashes:[\"1000\",\"/usr/bin/fixture-editor\"]",
                severity: "warning",
                icon: "",
                label: "process crashed",
                detail: "synthetic crash",
                context: latest,
                events: [latest, earlier, oldest],
                action: {
                    kind: "journal-event"
                }
            },
            {
                id: "fixture-oom",
                severity: "warning",
                icon: "",
                label: "process killed by kernel oom",
                detail: "synthetic oom",
                context: {
                    timestamp: new Date(Date.now() - 960000).toISOString(),
                    metadata: {
                        comm: "fixture worker with a very long process name <b>literal markup</b> and additional identifying text",
                        signal: "SIGKILL",
                        pid: "456"
                    }
                },
                action: {
                    kind: "journal-event"
                }
            }
        ];
        extraIssues = [
            {
                id: "battery-health",
                severity: "warning",
                label: "battery wear",
                detail: "72% health",
                action: null
            },
            {
                id: "updates",
                severity: "info",
                label: "3 updates available",
                detail: "pending packages",
                action: {
                    kind: "update"
                }
            }
        ];
        // Touch an existing dependency just as production metrics do.
        failedUnits = failedUnits.slice();
    }

    function addCrash() {
        const group = incidents[0];
        const latest = Object.assign({}, group.context, {
            cursor: "s=fixture-new",
            timestamp: new Date().toISOString(),
            metadata: Object.assign({}, group.context.metadata, {
                pid: "200"
            })
        });
        incidents = [Object.assign({}, group, {
                context: latest,
                events: [latest].concat(group.events)
            })].concat(incidents.slice(1));
    }

    function runIssueAction(id) {
        actions++;
        lastAction = id;
    }

    function clear() {
        failedUnits = [];
        incidents = [];
        extraIssues = [];
        processes = [];
    }
}