summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/Services/Privacy.qml
blob: 9c813e49d4316d7b5bbcbaf4aae1d4e29658fbc4 (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
58
59
60
61
62
63
pragma Singleton

import QtQml
import Quickshell
import Quickshell.Services.Pipewire

Singleton {
  id: root

  PwObjectTracker {
    objects: Pipewire.nodes.values
  }

  enum Item {
    Microphone,
    Screensharing
  }

  readonly property list<var> activeItems: {
    var items = [];
    if (microphoneActive)
      items.push(Privacy.Item.Microphone);
    if (screensharingActive)
      items.push(Privacy.Item.Screensharing);
    return items;
  }

  readonly property bool microphoneActive: {
    if (!Pipewire.ready || !Pipewire.nodes?.values) {
      return false
    }

    for (const node of Pipewire.nodes.values) {
      if (!node || (node.type & PwNodeType.AudioInStream) != PwNodeType.AudioInStream)
        continue;

      if (node.properties?.["stream.monitor"] === "true")
        continue;

      if (node.audio?.muted)
        continue;

      return true;
    }

    return false;
  }

  readonly property bool screensharingActive: {
    if (!Pipewire.ready || !Pipewire.nodes?.values) {
      return false
    }

    for (const node of Pipewire.nodes.values) {
      if (!node || (node.type & PwNodeType.VideoInStream) != PwNodeType.VideoInStream)
        continue;

      return true;
    }

    return false;
  }
}