summaryrefslogtreecommitdiff
path: root/js/sample.gjs.js
blob: c435c14566abdcc9954a60d65db0b980f6cac85e (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
#!/usr/bin/env -S gjs -m
import { Variable, App, Widget, Astal, bind } from "../js/dist/gjs/astal.js"
import Playerctl from "gi://Playerctl"

// state
const player = Playerctl.Player.new("spotify")
const date = Variable("").poll(1000, "date")
const title = Variable(player.get_title()).observe(player, "metadata", () => player.get_title())

// ui
function Bar(monitor) {
    return Widget.Window(
        {
            monitor,
            application: App,
            exclusivity: Astal.Exclusivity.EXCLUSIVE,
            anchor: Astal.WindowAnchor.BOTTOM |
                Astal.WindowAnchor.LEFT |
                Astal.WindowAnchor.RIGHT
        },
        Widget.CenterBox({
            startWidget: Widget.Label({
                label: date(l => `Current date: ${l}`),
            }),
            endWidget: Widget.Label({
                label: bind(title).as(t => `Title: ${t}`)
            }),
        })
    )
}

// main
App.start({
    requestHandler(msg, res) {
        switch (msg) {
            case "inspector": return res(App.inspector())
            case "quit": return res(App.quit())
            default: return App.eval(msg).then(res).catch(console.error)
        }
    }
}, () => {
    Bar(0)
})