diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/astal/gtk3/src/application.vala | 68 | ||||
-rw-r--r-- | lib/astal/io/application.vala | 12 |
2 files changed, 36 insertions, 44 deletions
diff --git a/lib/astal/gtk3/src/application.vala b/lib/astal/gtk3/src/application.vala index 8539aa0..2255333 100644 --- a/lib/astal/gtk3/src/application.vala +++ b/lib/astal/gtk3/src/application.vala @@ -3,8 +3,9 @@ public class Astal.Application : Gtk.Application, AstalIO.Application { private List<Gtk.CssProvider> css_providers = new List<Gtk.CssProvider>(); private SocketService service; private DBusConnection conn; - private string socket_path { get; set; } - private string _instance_name; + private string _instance_name = "astal"; + + public string socket_path { get; private set; } [DBus (visible=false)] public signal void monitor_added(Gdk.Monitor monitor); @@ -34,8 +35,8 @@ public class Astal.Application : Gtk.Application, AstalIO.Application { public string instance_name { owned get { return _instance_name; } construct set { - application_id = "io.Astal." + value; - _instance_name = value; + _instance_name = value != null ? value : "astal"; + application_id = @"io.Astal.$_instance_name"; } } @@ -138,54 +139,39 @@ public class Astal.Application : Gtk.Application, AstalIO.Application { AstalIO.write_sock.begin(conn, @"missing response implementation on $application_id"); } - /** - * should be called before `run()` - * the return value indicates if instance is already running - */ [DBus (visible=false)] - public void acquire_socket() { - try { - service = AstalIO.acquire_socket(this); - - Bus.own_name( - BusType.SESSION, - "io.Astal." + instance_name, - BusNameOwnerFlags.NONE, - (conn) => { - try { - this.conn = conn; - conn.register_object("/io/Astal/Application", this); - } catch (Error err) { - critical(err.message); - } - }, - () => {}, - () => {} - ); - } catch (Error err) { - critical("could not acquire socket %s\n", application_id); - critical(err.message); - } - } + public void acquire_socket() throws Error { + string path; + service = AstalIO.acquire_socket(this, out path); + socket_path = path; - public new void quit() throws DBusError, IOError { - if (service != null) { - if (FileUtils.test(socket_path, GLib.FileTest.EXISTS)){ + Bus.own_name( + BusType.SESSION, + application_id, + BusNameOwnerFlags.NONE, + (conn) => { try { - File.new_for_path(socket_path).delete(null); + this.conn = conn; + conn.register_object("/io/Astal/Application", this); } catch (Error err) { - warning(err.message); + critical(err.message); } - } + }, + () => {}, + () => {} + ); + } + + public new void quit() throws DBusError, IOError { + if (service != null) { + service.stop(); + service.close(); } base.quit(); } construct { - if (instance_name == null) - instance_name = "astal"; - activate.connect(() => { var display = Gdk.Display.get_default(); display.monitor_added.connect((mon) => { diff --git a/lib/astal/io/application.vala b/lib/astal/io/application.vala index 00bef57..60318ed 100644 --- a/lib/astal/io/application.vala +++ b/lib/astal/io/application.vala @@ -14,7 +14,7 @@ public interface Application : Object { public abstract void request(string msg, SocketConnection conn) throws Error; } -public SocketService acquire_socket(Application app) throws Error { +public SocketService acquire_socket(Application app, out string sock) throws Error { var name = app.instance_name; foreach (var instance in get_instances()) { if (instance == name) { @@ -23,7 +23,13 @@ public SocketService acquire_socket(Application app) throws Error { } var rundir = Environment.get_user_runtime_dir(); - var path = @"$rundir/$name.sock"; + var dir = @"$rundir/astal"; + var path = @"$dir/$name.sock"; + sock = path; + + if (!FileUtils.test(dir, FileTest.IS_DIR)) { + File.new_for_path(path).make_directory_with_parents(null); + } if (FileUtils.test(path, FileTest.EXISTS)) { try { @@ -123,7 +129,7 @@ public static void toggle_window_by_name(string instance, string window) { public static string send_message(string instance_name, string msg) { var rundir = Environment.get_user_runtime_dir(); - var socket_path = @"$rundir/$instance_name.sock"; + var socket_path = @"$rundir/astal/$instance_name.sock"; var client = new SocketClient(); try { |