aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/island/Privacy.qml
blob: c09a8d14c46c140f9d1ad149c31b9badd1d39ffb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

pragma Singleton

import Quickshell
import Quickshell.Io
import QtQuick
import "Logic.js" as Logic

// What is capturing: microphone, camera, location, screen. Polled every 2s
// from privacy.sh, the same cadence class as the waybar module it replaces.
Singleton {
    id: root

    property bool mic: false
    property bool cam: false
    property bool loc: false
    property bool scr: false

    // Theme property names of the active kinds, fixed order.
    readonly property var roles: Logic.privacyRoles(mic, cam, loc, scr)

    Process {
        id: proc
        command: ["sh", `${Quickshell.shellDir}/island/privacy.sh`]
        stdout: StdioCollector {
            onStreamFinished: {
                const b = text.trim().split(" ");
                // Anything but four fields is a broken run, not "nothing is
                // capturing": keep the last good reading.
                if (b.length !== 4) return;
                root.mic = b[0] === "1";
                root.cam = b[1] === "1";
                root.loc = b[2] === "1";
                root.scr = b[3] === "1";
            }
        }
    }

    Timer {
        interval: 2000
        running: true
        repeat: true
        triggeredOnStart: true
        // A Process already running ignores running = true (AGENTS.md).
        onTriggered: { proc.running = false; proc.running = true; }
    }
}