aboutsummaryrefslogtreecommitdiff
path: root/.config/ags/widget/quicksettings/widgets/Network.ts
blob: eb14ab4e314c1bc1172e9d050876cb66564e2a9c (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
import { Menu, ArrowToggleButton } from "../ToggleButton"
import icons from "lib/icons.js"
import { dependencies, sh } from "lib/utils"
import options from "options"
const { wifi } = await Service.import("network")

export const NetworkToggle = () => ArrowToggleButton({
    name: "network",
    icon: wifi.bind("icon_name"),
    label: wifi.bind("ssid").as(ssid => ssid || "Not Connected"),
    connection: [wifi, () => wifi.enabled],
    deactivate: () => wifi.enabled = false,
    activate: () => {
        wifi.enabled = true
        wifi.scan()
    },
})

export const WifiSelection = () => Menu({
    name: "network",
    icon: wifi.bind("icon_name"),
    title: "Wifi Selection",
    content: [
        Widget.Box({
            vertical: true,
            setup: self => self.hook(wifi, () => self.children =
                wifi.access_points.map(ap => Widget.Button({
                    on_clicked: () => {
                        if (dependencies("nmcli"))
                            Utils.execAsync(`nmcli device wifi connect ${ap.bssid}`)
                    },
                    child: Widget.Box({
                        children: [
                            Widget.Icon(ap.iconName),
                            Widget.Label(ap.ssid || ""),
                            Widget.Icon({
                                icon: icons.ui.tick,
                                hexpand: true,
                                hpack: "end",
                                setup: self => Utils.idle(() => {
                                    if (!self.is_destroyed)
                                        self.visible = ap.active
                                }),
                            }),
                        ],
                    }),
                })),
            ),
        }),
        Widget.Separator(),
        Widget.Button({
            on_clicked: () => sh(options.quicksettings.networkSettings.value),
            child: Widget.Box({
                children: [
                    Widget.Icon(icons.ui.settings),
                    Widget.Label("Network"),
                ],
            }),
        }),
    ],
})