aboutsummaryrefslogtreecommitdiff
path: root/.config/ags/service/asusctl.ts
blob: 16acbd73c6e4b5fe7b5912d622ca9134ae52f69c (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
import { sh } from "lib/utils"

type Profile = "Performance" | "Balanced" | "Quiet"
type Mode = "Hybrid" | "Integrated"

class Asusctl extends Service {
    static {
        Service.register(this, {}, {
            "profile": ["string", "r"],
            "mode": ["string", "r"],
        })
    }

    available = !!Utils.exec("which asusctl")
    #profile: Profile = "Balanced"
    #mode: Mode = "Hybrid"

    async nextProfile() {
        await sh("asusctl profile -n")
        const profile = await sh("asusctl profile -p")
        const p = profile.split(" ")[3] as Profile
        this.#profile = p
        this.changed("profile")
    }

    async setProfile(prof: Profile) {
        await sh(`asusctl profile --profile-set ${prof}`)
        this.#profile = prof
        this.changed("profile")
    }

    async nextMode() {
        await sh(`supergfxctl -m ${this.#mode === "Hybrid" ? "Integrated" : "Hybrid"}`)
        this.#mode = await sh("supergfxctl -g") as Mode
        this.changed("profile")
    }

    constructor() {
        super()

        if (this.available) {
            sh("asusctl profile -p").then(p => this.#profile = p.split(" ")[3] as Profile)
            sh("supergfxctl -g").then(m => this.#mode = m as Mode)
        }
    }

    get profiles(): Profile[] { return ["Performance", "Balanced", "Quiet"] }
    get profile() { return this.#profile }
    get mode() { return this.#mode }
}

export default new Asusctl