Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/features/launcher/fixtures/services/Launcher.qml

Raw
import QtQuick

Item {
    property int activations: 0
    property int actionActivations: 0
    // No installed apps at all, e.g. before desktop entries load.
    property bool empty: false
    // Adversarial entry: its name is its desktop id, with no generic name or comment.
    property bool machineNames: false
    readonly property var machineRow: ({
            "id": "nautilus",
            "title": "org.gnome.Nautilus",
            "subtitle": "",
            "genericName": "",
            "desktopId": "org.gnome.Nautilus.desktop",
            "glyph": "\uF07B",
            "actions": [],
            "details": []
        })

    function setMachineNames(value) {
        machineNames = !!value;
    }
    // Launches per row id, app and desktop-action launches alike: the production
    // frecency stand-in. Launched rows lead; the rest keep title order.
    property var launches: ({})
    property var rows: [
        {
            "id": "editor",
            "title": "fixture editor",
            "subtitle": "editor app",
            "genericName": "editor",
            "desktopId": "fixture-editor.desktop",
            "glyph": "",
            "actions": [],
            "details": []
        },
        {
            "id": "terminal",
            "title": "fixture terminal",
            "subtitle": "terminal app",
            "genericName": "terminal",
            "desktopId": "fixture-terminal.desktop",
            "glyph": "",
            "actions": [
                {
                    "id": "new",
                    "title": "new terminal"
                }
            ],
            "details": [
                {
                    "label": "category",
                    "value": "fixture"
                }
            ]
        }
    ]

    function viewRows(query) {
        const needle = String(query || "").toLowerCase();
        return empty ? [] : rows.concat(machineNames ? [machineRow] : []).filter(row => needle.length === 0 || String(row.title).toLowerCase().indexOf(needle) >= 0).map((row, index) => ({
                    "row": row,
                    "index": index
                })).sort((a, b) => (launchCount(b.row.id) - launchCount(a.row.id)) || (a.index - b.index)).map(entry => entry.row);
    }

    function setEmpty(value) {
        empty = !!value;
    }

    function launchCount(id) {
        return Number(launches[id] || 0);
    }

    function recordLaunch(row) {
        const id = String(row.id);
        const next = Object.assign({}, launches);
        next[id] = launchCount(id) + 1;
        launches = next;
    }

    function activate(row) {
        activations++;
        recordLaunch(row);
    }

    function activateAction(row, index) {
        actionActivations++;
        recordLaunch(row);
    }

    function fixtureState() {
        return {
            "rows": rows.length,
            "launches": launches,
            "empty": empty,
            "activations": activations,
            "actionActivations": actionActivations
        };
    }
}