From 9a484bdee02904034449961612fd5b2cdbe6a337 Mon Sep 17 00:00:00 2001 From: Aylur <104676705+Aylur@users.noreply.github.com> Date: Fri, 28 Jun 2024 17:07:18 +0200 Subject: add flake, format, small fixes (#1) * add flake, format, small fixes * moved the mainloop in cli.vala to the scope of deamonize * made versions public in config.vala * added notify_property("items") calls in tray.vala, this makes it work with the bind API in gjs * added flake.nix NOTE for nix: The dbusmenu workaround in meson seems to break typelib linking on nix which I could not find a solution for. A simple workaround is to simply put the dependencies of dbusmenu-gtk in buildInputs, which is fine, but I'm sure this will cause confusion since no other libs require additional packages in buildInputs * fix(cli): item changed event * move header to includedir/astal --- src/cli.vala | 91 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 46 deletions(-) (limited to 'src/cli.vala') diff --git a/src/cli.vala b/src/cli.vala index c22e096..3147fb5 100644 --- a/src/cli.vala +++ b/src/cli.vala @@ -1,55 +1,54 @@ -static bool help; static bool version; static bool daemonize; const OptionEntry[] options = { - { "version", 'v', OptionFlags.NONE, OptionArg.NONE, ref version, "Print version number", null }, - { "daemon", 'd', OptionFlags.NONE, OptionArg.NONE, ref daemonize, "Monitor the systemtray", null }, - { null }, + { "version", 'v', OptionFlags.NONE, OptionArg.NONE, ref version, "Print version number", null }, + { "daemonize", 'd', OptionFlags.NONE, OptionArg.NONE, ref daemonize, "Monitor the systemtray", null }, + { null }, }; int main(string[] argv) { - try { - var opts = new OptionContext(); - opts.add_main_entries(options, null); - opts.set_help_enabled(true); - opts.set_ignore_unknown_options(false); - opts.parse(ref argv); - } catch (OptionError err) { - printerr (err.message); - return 1; - } - - var loop = new MainLoop(); - var tray = new AstalTray.Tray(); - - if (version) { - print(AstalTray.VERSION); + try { + var opts = new OptionContext(); + opts.add_main_entries(options, null); + opts.set_help_enabled(true); + opts.set_ignore_unknown_options(false); + opts.parse(ref argv); + } catch (OptionError err) { + printerr (err.message); + return 1; + } + + if (version) { + print(AstalTray.VERSION); + return 0; + } + + if (daemonize) { + var loop = new MainLoop(); + var tray = new AstalTray.Tray(); + + tray.item_added.connect((id) => { + AstalTray.TrayItem item = tray.get_item(id); + + stdout.printf("{\"event\":\"item_added\",\"id\":\"%s\",\"item\":%s}\n", + id, item.to_json_string()); + stdout.flush(); + + item.changed.connect(() => { + stdout.printf("{\"event\":\"item_changed\",\"id\":\"%s\",\"item\":%s}\n", + id, item.to_json_string()); + stdout.flush(); + }); + }); + + tray.item_removed.connect((id) => { + stdout.printf("{\"event\":\"item_removed\",\"id\":\"%s\"}\n", id); + stdout.flush(); + }); + + loop.run(); + } + return 0; - } - - if (daemonize) { - tray.item_added.connect((id) => { - - AstalTray.TrayItem item = tray.get_item(id); - - string item_json = item.to_json_string(); - stdout.printf("{\"event\":\"item_added\",\"id\":\"%s\",\"item\":%s}\n", - id, item_json); - stdout.flush(); - - item.changed.connect(() => { - stdout.printf("{\"event\":\"item_changed\",\"id\":\"%s\",\"item\":%s}\n", - id, item_json); - stdout.flush(); - }); - }); - tray.item_removed.connect((id) => { - stdout.printf("{\"event\":\"item_removed\",\"id\":\"%s\"}\n", id); - stdout.flush(); - }); - } - - loop.run(); - return 0; } -- cgit v1.2.3