summaryrefslogtreecommitdiff
path: root/node/sample.js
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-05-25 14:44:50 +0200
committerAylur <[email protected]>2024-05-25 14:44:50 +0200
commit58fa1ab9be7ee8fd4a8e96865121a54d613978cc (patch)
tree56f01ba49fd2929690a16ac05a4af8f763e6b30b /node/sample.js
parenta7e25a4a5fcf4de89fe5a149a9aaf50a92be7af1 (diff)
separate node and gjs into its own package
Diffstat (limited to 'node/sample.js')
-rwxr-xr-xnode/sample.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/node/sample.js b/node/sample.js
new file mode 100755
index 0000000..1f038e1
--- /dev/null
+++ b/node/sample.js
@@ -0,0 +1,49 @@
+#!/usr/bin/env node
+import { Variable, App, Widget, Astal, bind, gi } from "./dist/index.js"
+const Playerctl = gi.require("Playerctl", "2.0")
+
+// state
+const player = Playerctl.Player.new("spotify")
+const title = Variable(player.getTitle()).observe(player, "metadata", () => player.getTitle())
+const date = Variable("")
+ // FIXME: doesn't work because promises don't resolve
+ // .poll(1000, "date")
+ // FIXME: don't know why but this doesn't work either
+ // .watch("bash -c 'while true; do date; sleep 1; done'")
+ // this does
+ .poll(1000, Date)
+
+// 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)
+})