summaryrefslogtreecommitdiff
path: root/services/Network.qml
blob: a65ab1e7e5ec3738576be8a79acb41bdf8b888bb (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
pragma Singleton

import Quickshell
import Quickshell.Io
import QtQuick

Singleton {
    id: root

    readonly property AccessPoint active: AccessPoint {
        active: true
    }

    reloadableId: "network"

    Process {
        running: true
        command: ["nmcli", "m"]
        stdout: SplitParser {
            onRead: getNetworks.running = true
        }
    }

    Process {
        id: getNetworks
        running: true
        command: ["nmcli", "-g", "ACTIVE,SIGNAL,FREQ,SSID", "d", "w"]
        stdout: SplitParser {
            onRead: data => {
                const [active, strength, frequency, ssid] = data.split(":");
                if (active === "yes") {
                    root.active.ssid = ssid;
                    root.active.strength = parseInt(strength);
                    root.active.frequency = parseInt(frequency);
                }
            }
        }
    }

    component AccessPoint: QtObject {
        property string ssid
        property int strength
        property int frequency
        property bool active
    }
}