diff options
author | Aylur <[email protected]> | 2024-05-26 19:54:00 +0200 |
---|---|---|
committer | Aylur <[email protected]> | 2024-05-26 19:54:00 +0200 |
commit | ae2b733af5d4693534bec237e38c0a57716f4c37 (patch) | |
tree | b3d33e5b6f86173e6150a9c52a2565eab80a87a4 | |
parent | 9d83811e3f3158a356ece00971db4765205732a9 (diff) |
rename vfunc_response to vfunc_request
-rwxr-xr-x | gjs/sample.js | 43 | ||||
-rw-r--r-- | gjs/src/application.ts | 4 | ||||
-rw-r--r-- | lua/astal-dev-1.rockspec | 36 | ||||
-rw-r--r-- | lua/astal/application.lua | 4 | ||||
-rwxr-xr-x | lua/sample.lua | 81 | ||||
-rw-r--r-- | node/src/application.ts | 4 | ||||
-rw-r--r-- | python/astal/application.py | 4 | ||||
-rw-r--r-- | src/astal.vala | 6 |
8 files changed, 32 insertions, 150 deletions
diff --git a/gjs/sample.js b/gjs/sample.js deleted file mode 100755 index 2aa6145..0000000 --- a/gjs/sample.js +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env -S gjs -m -import { Variable, App, Widget, Astal, bind } from "./dist/index.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) -}) diff --git a/gjs/src/application.ts b/gjs/src/application.ts index b98b831..b34e798 100644 --- a/gjs/src/application.ts +++ b/gjs/src/application.ts @@ -39,10 +39,10 @@ class AstalJS extends Astal.Application { requestHandler?: RequestHandler - vfunc_response(msg: string, conn: Gio.SocketConnection): void { + vfunc_request(msg: string, conn: Gio.SocketConnection): void { if (typeof this.requestHandler === "function") { this.requestHandler(msg, response => { - Astal.write_sock(conn, response, (_, res) => + Astal.write_sock(conn, String(response), (_, res) => Astal.write_sock_finish(res), ) }) diff --git a/lua/astal-dev-1.rockspec b/lua/astal-dev-1.rockspec index 35517d3..616f4f8 100644 --- a/lua/astal-dev-1.rockspec +++ b/lua/astal-dev-1.rockspec @@ -1,22 +1,30 @@ package = "astal" version = "dev-1" + source = { - url = "git+https://github.com/astal-sh/libastal" + url = "git+https://github.com/astal-sh/libastal", } + description = { - summary = "lua bindings for libastal.", - homepage = "https://github.com/astal-sh/libastal", - license = "GPL-3" + summary = "lua bindings for libastal.", + homepage = "https://github.com/astal-sh/libastal", + license = "GPL-3", } + +dependencies = { + "lua >= 5.1, < 5.4", + "lgi >= 0.9.2", +} + build = { - type = "builtin", - modules = { - ["astal.application"] = "astal/application.lua", - ["astal.binding"] = "astal/binding.lua", - ["astal.init"] = "astal/init.lua", - ["astal.process"] = "astal/process.lua", - ["astal.time"] = "astal/time.lua", - ["astal.variable"] = "astal/variable.lua", - ["astal.widget"] = "astal/widget.lua", - } + type = "builtin", + modules = { + ["astal.application"] = "astal/application.lua", + ["astal.binding"] = "astal/binding.lua", + ["astal.init"] = "astal/init.lua", + ["astal.process"] = "astal/process.lua", + ["astal.time"] = "astal/time.lua", + ["astal.variable"] = "astal/variable.lua", + ["astal.widget"] = "astal/widget.lua", + }, } diff --git a/lua/astal/application.lua b/lua/astal/application.lua index 6146e33..551367a 100644 --- a/lua/astal/application.lua +++ b/lua/astal/application.lua @@ -6,8 +6,8 @@ local request_handler function AstalLua:do_request(msg, conn) if type(request_handler) == "function" then - request_handler(msg, function(request) - Astal.write_sock(conn, request, function(_, res) + request_handler(msg, function(response) + Astal.write_sock(conn, tostring(response), function(_, res) Astal.write_sock_finish(res) end) end) diff --git a/lua/sample.lua b/lua/sample.lua deleted file mode 100755 index 2c76af6..0000000 --- a/lua/sample.lua +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env lua --- imports -local astal = require("astal.init") -local Widget, Variable, App, bind = astal.Widget, astal.Variable, astal.App, astal.bind - --- state -local player = astal.require("Playerctl").Player.new("spotify") - -local title = Variable(player:get_title()):observe(player, "metadata", function() - return player:get_title() -end) - -local rnd = Variable(1):poll(1000, function() - return math.random(1, 10) -end) - --- ui -local Bar = function(monitor) - return Widget.Window({ - application = App, - id = "bar", - name = "bar", - monitor = monitor, - anchor = astal.Astal.WindowAnchor.BOTTOM - + astal.Astal.WindowAnchor.LEFT - + astal.Astal.WindowAnchor.RIGHT, - exclusivity = "EXCLUSIVE", - - Widget.CenterBox({ - class_name = "bar", - start_widget = Widget.Label({ - valign = "CENTER", - label = "Welcome to Astal.lua", - }), - center_widget = Widget.Box({ - children = bind(rnd):as(function(n) - local children = {} - for i = 1, n, 1 do - table.insert( - children, - Widget.Button({ - label = tostring(i), - on_clicked = function() - print(i) - end, - }) - ) - end - return children - end), - }), - end_widget = Widget.Label({ - valign = "CENTER", - label = bind(title), - }), - }), - }) -end - --- css -local css = [[ -.bar button { - color: blue; -} -]] - --- main -App:start({ - request_handler = function(msg, res) - if msg == "quit" then - os.exit(0) - end - if msg == "inspector" then - res(App:inspector()) - end - res("hi") - end, - css = css, -}, function() - Bar(0) -end) diff --git a/node/src/application.ts b/node/src/application.ts index bc0f47f..f7598f8 100644 --- a/node/src/application.ts +++ b/node/src/application.ts @@ -36,10 +36,10 @@ class AstalJS extends Astal.Application { requestHandler?: RequestHandler - vfunc_response(msg: string, conn: any): void { + vfunc_request(msg: string, conn: any): void { if (typeof this.requestHandler === "function") { this.requestHandler(msg, response => { - Astal.writeSock(conn, response, (_, res) => + Astal.writeSock(conn, String(response), (_, res) => Astal.writeSockFinish(res), ) }) diff --git a/python/astal/application.py b/python/astal/application.py index 3eb1a4f..de0ba18 100644 --- a/python/astal/application.py +++ b/python/astal/application.py @@ -9,13 +9,13 @@ class _Application(Astal.Application): super().__init__() self.request_handler: RequestHandler | None = None - def do_response(self, msg: str, conn: Gio.SocketConnection) -> None: + def do_request(self, msg: str, conn: Gio.SocketConnection) -> None: if self.request_handler: self.request_handler( msg, lambda response: Astal.write_sock( conn, - response, + str(response), lambda _, res: Astal.write_sock_finish(res), ), ) diff --git a/src/astal.vala b/src/astal.vala index fe6558c..e8c3f75 100644 --- a/src/astal.vala +++ b/src/astal.vala @@ -1,6 +1,5 @@ namespace Astal { public class Application : Gtk.Application { - public signal void request (string request); private List<Gtk.CssProvider> css_providers; private SocketService service; private string socket; @@ -73,11 +72,10 @@ public class Application : Gtk.Application { private async void _socket_request(SocketConnection conn) { string message = yield read_sock(conn); - request(message.strip()); - response(message.strip(), conn); + request(message.strip(), conn); } - public virtual void response(string msg, SocketConnection conn) { + public virtual void request(string msg, SocketConnection conn) { write_sock.begin(conn, "missing response implementation on ".concat(application_id)); } |