summaryrefslogtreecommitdiff
path: root/lib/astal/gtk3
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-10-15 01:26:32 +0200
committerAylur <[email protected]>2024-10-15 01:26:32 +0200
commit2f71cd4c08bb4514efe43533e6a5d03535204c29 (patch)
treefc991a12e159ad645187862c90f40731794d6e47 /lib/astal/gtk3
parent9fab13452a26ed55c01047d4225f699f43bba20d (diff)
refactor lua and gjs lib
Diffstat (limited to 'lib/astal/gtk3')
-rw-r--r--lib/astal/gtk3/src/application.vala68
1 files changed, 27 insertions, 41 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) => {