summaryrefslogtreecommitdiff
path: root/src/cli.vala
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-06-28 17:07:18 +0200
committerGitHub <[email protected]>2024-06-28 17:07:18 +0200
commit9a484bdee02904034449961612fd5b2cdbe6a337 (patch)
tree7be3b0a66894a980e6e9ddef5ef2e8782a2fe964 /src/cli.vala
parent2c701b970e7b2b208d8d12d3ea34078236d3f62e (diff)
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
Diffstat (limited to 'src/cli.vala')
-rw-r--r--src/cli.vala91
1 files changed, 45 insertions, 46 deletions
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;
}