diff options
author | Aylur <[email protected]> | 2024-05-19 02:39:53 +0200 |
---|---|---|
committer | Aylur <[email protected]> | 2024-05-19 02:39:53 +0200 |
commit | 1425b396b08f0e91d45bbd0f92b1309115c7c870 (patch) | |
tree | 8af1a899a14d8a01a9ef50e248c077b48aed25bc /js/sample.gjs.js |
init 0.1.0
Diffstat (limited to 'js/sample.gjs.js')
-rwxr-xr-x | js/sample.gjs.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/js/sample.gjs.js b/js/sample.gjs.js new file mode 100755 index 0000000..c435c14 --- /dev/null +++ b/js/sample.gjs.js @@ -0,0 +1,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) +}) |