summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/astal.vala32
-rw-r--r--src/cli.vala11
2 files changed, 20 insertions, 23 deletions
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;
}