pragma Singleton

// What this machine is: model, processor, memory, disk, OS, kernel.
//
// Read once, on demand. None of it changes while the desktop is running except
// free disk space, and About is not a monitor -- the vitals readout on the Home
// page is where live figures belong.
//
// Graphics is not here. GraphicsDevices already enumerates GPUs for the vitals
// readout, and naming them again would be a second source of truth that could
// disagree with the first; the About page joins the two instead.

import Quickshell
import Quickshell.Io
import QtQuick

Singleton {
    id: root

    readonly property string helperPath: Quickshell.shellDir + "/scripts/panama-about"

    // [{ label, value }] in display order.
    property var facts: []
    property bool scanned: false

    function refresh(): void {
        if (!query.running)
            query.running = true;
    }

    Process {
        id: query
        command: [root.helperPath]
        stdout: StdioCollector {
            onStreamFinished: {
                try {
                    const parsed = JSON.parse(this.text);
                    root.facts = Array.isArray(parsed) ? parsed : [];
                } catch (error) {
                    root.facts = [];
                    console.warn("MachineInfo: could not parse helper output:", error);
                }
                root.scanned = true;
            }
        }
    }
}
