aboutsummaryrefslogtreecommitdiff
path: root/linux/home/.config/ags/widget/quicksettings/widgets/PowerProfile.ts
blob: f566aaf6a0d411bce68d0691943f4247bc3dc2e6 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { ArrowToggleButton, Menu } from "../ToggleButton"
import icons from "lib/icons"

import asusctl from "service/asusctl"
const asusprof = asusctl.bind("profile")

const AsusProfileToggle = () => ArrowToggleButton({
    name: "asusctl-profile",
    icon: asusprof.as(p => icons.asusctl.profile[p]),
    label: asusprof,
    connection: [asusctl, () => asusctl.profile !== "Balanced"],
    activate: () => asusctl.setProfile("Quiet"),
    deactivate: () => asusctl.setProfile("Balanced"),
    activateOnArrow: false,
})

const AsusProfileSelector = () => Menu({
    name: "asusctl-profile",
    icon: asusprof.as(p => icons.asusctl.profile[p]),
    title: "Profile Selector",
    content: [
        Widget.Box({
            vertical: true,
            hexpand: true,
            children: [
                Widget.Box({
                    vertical: true,
                    children: asusctl.profiles.map(prof => Widget.Button({
                        on_clicked: () => asusctl.setProfile(prof),
                        child: Widget.Box({
                            children: [
                                Widget.Icon(icons.asusctl.profile[prof]),
                                Widget.Label(prof),
                            ],
                        }),
                    })),
                }),
            ],
        }),
        Widget.Separator(),
        Widget.Button({
            on_clicked: () => Utils.execAsync("rog-control-center"),
            child: Widget.Box({
                children: [
                    Widget.Icon(icons.ui.settings),
                    Widget.Label("Rog Control Center"),
                ],
            }),
        }),
    ],
})


const pp = await Service.import("powerprofiles")
const profile = pp.bind("active_profile")
const profiles = pp.profiles.map(p => p.Profile)

const pretty = (str: string) => str
    .split("-")
    .map(str => `${str.at(0)?.toUpperCase()}${str.slice(1)}`)
    .join(" ")

const PowerProfileToggle = () => ArrowToggleButton({
    name: "asusctl-profile",
    icon: profile.as(p => icons.powerprofile[p]),
    label: profile.as(pretty),
    connection: [pp, () => pp.active_profile !== profiles[1]],
    activate: () => pp.active_profile = profiles[0],
    deactivate: () => pp.active_profile = profiles[1],
    activateOnArrow: false,
})

const PowerProfileSelector = () => Menu({
    name: "asusctl-profile",
    icon: profile.as(p => icons.powerprofile[p]),
    title: "Profile Selector",
    content: [Widget.Box({
        vertical: true,
        hexpand: true,
        child: Widget.Box({
            vertical: true,
            children: profiles.map(prof => Widget.Button({
                on_clicked: () => pp.active_profile = prof,
                child: Widget.Box({
                    children: [
                        Widget.Icon(icons.powerprofile[prof]),
                        Widget.Label(pretty(prof)),
                    ],
                }),
            })),
        }),
    })],
})

export const ProfileToggle = asusctl.available
    ? AsusProfileToggle : PowerProfileToggle

export const ProfileSelector = asusctl.available
    ? AsusProfileSelector : PowerProfileSelector