feat: optiona exit code on App.quit

This commit is contained in:
Aylur
2024-07-31 16:25:04 +02:00
parent f86a908952
commit a0680e3b88
4 changed files with 26 additions and 7 deletions
+5
View File
@@ -59,6 +59,11 @@ class AstalJS extends Astal.Application {
super.apply_css(style, reset)
}
quit(code?: number): void {
super.quit()
exit(code ?? 0)
}
start({ requestHandler, css, hold, main, client, ...cfg }: Config = {}) {
client ??= () => {
print(`Astal instance "${this.instanceName}" already running`)
+5
View File
@@ -16,6 +16,11 @@ function AstalLua:do_request(msg, conn)
end
end
function AstalLua:quit(code)
Astal.Application.quit(self)
os.exit(code)
end
local app = AstalLua()
---@class StartConfig
+8
View File
@@ -0,0 +1,8 @@
local App = require("astal.application")
App:start({
instance_name = "test",
main = function()
App:quit(1)
end,
})
+8 -7
View File
@@ -192,11 +192,11 @@ public class Application : Gtk.Application {
}
}
construct {
public new void quit() throws DBusError, IOError {
if (instance_name == null)
instance_name = "astal";
shutdown.connect(() => {
if (service != null) {
if (FileUtils.test(socket_path, GLib.FileTest.EXISTS)){
try {
File.new_for_path(socket_path).delete(null);
@@ -204,17 +204,18 @@ public class Application : Gtk.Application {
warning(err.message);
}
}
});
}
base.quit();
}
construct {
shutdown.connect(() => { try { quit(); } catch(Error err) {} });
Unix.signal_add(1, () => { try { quit(); } catch(Error err) {} }, Priority.HIGH);
Unix.signal_add(2, () => { try { quit(); } catch(Error err) {} }, Priority.HIGH);
Unix.signal_add(15, () => { try { quit(); } catch(Error err) {} }, Priority.HIGH);
}
public new void quit() throws DBusError, IOError {
base.quit();
}
public static List<string> get_instances() {
var list = new List<string>();
var prefix = "io.Astal.";