Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/features/noko/fixtures/services/Noko.qml

Raw
import QtQuick

Item {
    property bool starting: false
    property bool listening: false
    property bool transcribing: false
    property bool finished: false
    property bool failed: false
    property string captureError: ""
    property string lastInsertError: ""
    property string liveText: ""
    property bool installing: false
    property bool maintenance: false
    // Fixture switches: no engine installed, or the engine's models missing, as
    // production reports them; an update held until its models are installed.
    property bool engineMissing: false
    property bool missingAssets: false
    property bool updateHeld: false
    readonly property bool statusKnown: true
    readonly property string engineRevision: engineMissing ? "" : "a"
    readonly property string pendingRevision: updateHeld ? "b" : ""
    readonly property bool currentAssetsMissing: missingAssets && !engineMissing
    readonly property bool pendingAssetsMissing: updateHeld
    readonly property real assetBytes: currentAssetsMissing || updateHeld ? 463945198 : 0
    readonly property real latestSize: 98123456
    readonly property bool updating: false
    readonly property string updateError: ""
    readonly property bool typingReady: true
    readonly property bool ready: !engineMissing && !currentAssetsMissing
    readonly property bool dictating: starting || listening || transcribing
    readonly property string status: !ready ? "blocked" : (installing ? "installing" : (starting || listening ? "listening" : (transcribing ? "transcribing" : "ready")))
    property string lastError: ""
    property bool wakeEnabled: false
    property string wakePhrase: "hello computer"
    property string wakePhraseError: ""
    property string wakeError: ""
    property string hotwordsText: "Nuguland\nniri"
    property string hotwordsError: ""
    readonly property bool wakeListening: wakeEnabled && ready && !dictating && !installing
    // Chip and overlay state derive exactly as in production Noko.qml.
    readonly property bool blocked: status === "blocked" || status === "error"
    readonly property bool active: blocked || dictating || installing || wakeListening
    readonly property bool strong: blocked || installing
    readonly property string role: blocked || installing ? "warning" : (dictating || finished || wakeListening ? "ui.accent" : "ui.focus")
    readonly property string overlayState: starting ? "starting" : (listening ? "capturing" : (transcribing ? "transcribing" : (finished ? "finished" : (failed ? "failed" : ""))))
    property string installLabel: ""
    property real installProgress: 0
    property string copiedTranscript: ""
    property int triggers: 0
    property int installs: 0
    property int clears: 0
    property int hotwordEdits: 0
    property int phraseEdits: 0
    // Setup checks requested, e.g. by each popup opening.
    property int checks: 0
    property var historyEntries: Array.from({
        length: 12
    }, (_, i) => ({
                transcript: `synthetic capture ${i}`,
                duration: 2
            }))

    function copyTranscript(text) {
        copiedTranscript = String(text);
    }

    function stateJson() {
        return JSON.stringify(fixtureState());
    }

    function refresh() {
        checks++;
        return stateJson();
    }

    function clearHistory() {
        clears++;
        historyEntries = [];
    }

    function install() {
        if (installing || dictating)
            return stateJson();
        installs++;
        installing = true;
        maintenance = !engineMissing;
        return stateJson();
    }

    // A download in progress, labelled as the setup service reports it.
    function setInstalling(label) {
        installLabel = String(label);
        installing = installLabel.length > 0;
        installProgress = 0.4;
    }

    function completeInstall() {
        installing = false;
        maintenance = false;
        engineMissing = false;
        missingAssets = false;
        updateHeld = false;
    }

    function trigger() {
        if (installing || transcribing || !ready)
            return stateJson();
        if (starting || listening) {
            starting = false;
            listening = false;
        } else {
            starting = true;
            failed = false;
            captureError = "";
            lastInsertError = "";
            liveText = "";
        }
        triggers++;
        return stateJson();
    }

    function startCapture() {
        return starting || listening ? stateJson() : trigger();
    }

    function stopCapture() {
        return starting || listening ? trigger() : stateJson();
    }

    function setWakeEnabled(enabled) {
        wakeEnabled = !!enabled;
    }

    function editWakePhrase(text) {
        phraseEdits++;
        wakePhrase = String(text);
        wakePhraseError = /[\/@:#]/.test(wakePhrase) ? "drop / @ : #" : "";
    }

    function editHotwords(text) {
        hotwordEdits++;
        hotwordsText = String(text);
        hotwordsError = /[\/@:#]/.test(hotwordsText) ? "line 1: drop / @ : #" : "";
    }

    function beginStarting() {
        starting = true;
        listening = false;
        transcribing = false;
        finished = false;
        liveText = "";
        return stateJson();
    }

    function beginListening() {
        starting = false;
        listening = true;
        transcribing = false;
        finished = false;
        return stateJson();
    }

    // A revisable partial as the engine streams it; long dictations elide at the start.
    function hear(text) {
        liveText = String(text);
        return stateJson();
    }

    function beginTranscribing() {
        starting = false;
        listening = false;
        transcribing = true;
        finished = false;
        return stateJson();
    }

    // Production shows "finished" briefly after a transcript lands, with the typed text.
    function completeTranscription() {
        starting = false;
        listening = false;
        transcribing = false;
        finished = true;
        liveText = "Typed into the window you were in.";
        return stateJson();
    }

    // Production says why a dictation gave no text, briefly in the overlay and
    // until the next capture in the panel.
    function failTranscription() {
        starting = false;
        listening = false;
        transcribing = false;
        finished = false;
        failed = true;
        liveText = "";
        captureError = "no speech heard";
        return stateJson();
    }

    // Typing into the focused app failed after a transcript landed.
    function failTyping() {
        lastInsertError = "fixture";
    }

    function finish() {
        starting = false;
        listening = false;
        transcribing = false;
        finished = false;
        failed = false;
        installing = false;
        liveText = "";
        return stateJson();
    }

    function setMissingAssets(missing) {
        missingAssets = !!missing;
    }

    function setEngineMissing(missing) {
        engineMissing = !!missing;
    }

    function setUpdateHeld(held) {
        updateHeld = !!held;
    }

    function setLastError(text) {
        lastError = String(text);
    }

    function fixtureState() {
        return {
            "status": status,
            "ready": ready,
            "starting": starting,
            "listening": listening,
            "transcribing": transcribing,
            "overlayState": overlayState,
            "triggers": triggers,
            "installs": installs,
            "installing": installing,
            "clears": clears,
            "historyCount": historyEntries.length,
            "checks": checks,
            "copiedTranscript": copiedTranscript,
            "wakeEnabled": wakeEnabled,
            "wakeListening": wakeListening,
            "hotwordEdits": hotwordEdits,
            "phraseEdits": phraseEdits
        };
    }
}