diff options
-rw-r--r-- | gjs/src/application.ts | 2 | ||||
-rw-r--r-- | lua/astal/application.lua | 2 | ||||
-rw-r--r-- | src/astal.vala | 32 | ||||
-rw-r--r-- | src/cli.vala | 11 |
4 files changed, 22 insertions, 25 deletions
diff --git a/gjs/src/application.ts b/gjs/src/application.ts index ec588ca..835b319 100644 --- a/gjs/src/application.ts +++ b/gjs/src/application.ts @@ -80,7 +80,7 @@ class AstalJS extends Astal.Application { }) if (!this.acquire_socket()) - return client(msg => this.message(msg)!, ...programArgs) + return client(msg => Astal.Application.send_message(this.instance_name, msg)!, ...programArgs) if (css) this.apply_css(css, false) diff --git a/lua/astal/application.lua b/lua/astal/application.lua index f1b1ad3..c325ed1 100644 --- a/lua/astal/application.lua +++ b/lua/astal/application.lua @@ -75,7 +75,7 @@ function Astal.Application:start(config) if not app:acquire_socket() then return config.client(function(msg) - return app:message(msg) + return Astal.Application.send_message(self.instance_name, msg) end, table.unpack(arg)) end diff --git a/src/astal.vala b/src/astal.vala index 4f8021e..3ed705d 100644 --- a/src/astal.vala +++ b/src/astal.vala @@ -117,7 +117,7 @@ public class Application : Gtk.Application { [DBus (visible=false)] public virtual void request(string msg, SocketConnection conn) { - write_sock.begin(conn, "missing response implementation on ".concat(application_id)); + write_sock.begin(conn, @"missing response implementation on $application_id"); } /** @@ -126,10 +126,8 @@ public class Application : Gtk.Application { */ [DBus (visible=false)] public bool acquire_socket() { - socket_path = GLib.Environment.get_user_runtime_dir().concat( - "/", - instance_name, - ".sock"); + var rundir = GLib.Environment.get_user_runtime_dir(); + socket_path = @"$rundir/$instance_name.sock"; if (FileUtils.test(socket_path, GLib.FileTest.EXISTS)) { info("socket %s exists", socket_path); @@ -146,11 +144,10 @@ public class Application : Gtk.Application { null); service.incoming.connect((conn) => { - _socket_request.begin(conn); + _socket_request.begin(conn, (_, res) => _socket_request.end(res)); return false; }); - Bus.own_name( BusType.SESSION, "io.Astal." + instance_name, @@ -176,6 +173,8 @@ public class Application : Gtk.Application { } public string message(string? msg) throws DBusError, IOError { + var rundir = GLib.Environment.get_user_runtime_dir(); + var socket_path = @"$rundir/$instance_name.sock"; var client = new SocketClient(); if (msg == null) @@ -280,17 +279,20 @@ public class Application : Gtk.Application { } } - public static string send_message(string instance, string message) throws IOError { + public static string send_message(string instance_name, string msg) { + var rundir = GLib.Environment.get_user_runtime_dir(); + var socket_path = @"$rundir/$instance_name.sock"; + var client = new SocketClient(); + try { - IApplication proxy = Bus.get_proxy_sync( - BusType.SESSION, - "io.Astal." + instance, - "/io/Astal/Application" - ); + var conn = client.connect(new UnixSocketAddress(socket_path), null); + conn.output_stream.write(msg.concat("\x04").data); - return proxy.message(message); + var stream = new DataInputStream(conn.input_stream); + return stream.read_upto("\x04", -1, null, null); } catch (Error err) { - throw new IOError.FAILED(@"could not write to app '$instance'"); + printerr(err.message); + return ""; } } } diff --git a/src/cli.vala b/src/cli.vala index 3e3eb15..0b60cd1 100644 --- a/src/cli.vala +++ b/src/cli.vala @@ -46,7 +46,7 @@ int main(string[] argv) { } if (version) { - print("@VERSION@"); + print(Astal.VERSION); return 0; } @@ -80,13 +80,8 @@ int main(string[] argv) { request = request.concat(" ", argv[i]); } - try { - var reply = Astal.Application.send_message(instance_name, request); - print("%s\n", reply); - } catch (IOError err) { - printerr("%s\n", err.message); - return 1; - } + var reply = Astal.Application.send_message(instance_name, request); + print("%s\n", reply); return 0; } |