summaryrefslogtreecommitdiff
path: root/utils/SysInfo.qml
blob: 968dc5225079f03c5b5ed2101d52b4832f6a9375 (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
pragma Singleton

import Quickshell
import Quickshell.Io

Singleton {
    id: root

    property string osName
    property string osPrettyName
    property string osId
    property list<string> osIdLike
    property string logo
    property string osIcon: ""

    readonly property string user: Quickshell.env("USER")
    readonly property string wm: Quickshell.env("XDG_CURRENT_DESKTOP") || Quickshell.env("XDG_SESSION_DESKTOP")
    readonly property string shell: Quickshell.env("SHELL").split("/").pop()

    FileView {
        id: osRelease

        path: "/etc/os-release"
        onLoaded: {
            const lines = text().split("\n");

            const fd = key => lines.find(l => l.startsWith(`${key}=`))?.split("=")[1].replace(/"/g, "") ?? "";

            root.osName = fd("NAME");
            root.osPrettyName = fd("PRETTY_NAME");
            root.osId = fd("ID");
            root.osIdLike = fd("ID_LIKE").split(" ");
            root.logo = fd("LOGO");

            const osIcons = Icons.osIcons;
            if (osIcons.hasOwnProperty(root.osId)) {
                root.osIcon = osIcons[root.osId];
            } else {
                for (const id of root.osIdLike) {
                    if (osIcons.hasOwnProperty(id)) {
                        root.osIcon = osIcons[id];
                    }
                }
            }
        }
    }
}