diff options
author | kotontrion <[email protected]> | 2024-05-23 17:34:06 +0200 |
---|---|---|
committer | kotontrion <[email protected]> | 2024-05-23 17:34:06 +0200 |
commit | 3486989e9191af00248efb4a5a973fac64b1d8c1 (patch) | |
tree | bb7afb90da4266a57286ce6754ddb238f0c8b1c5 /src/cli.vala | |
parent | 2a148886dcf186afaf8393cccdc39ce4c7ebcbc7 (diff) |
add cli tool
Diffstat (limited to 'src/cli.vala')
-rw-r--r-- | src/cli.vala | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/cli.vala b/src/cli.vala new file mode 100644 index 0000000..c22e096 --- /dev/null +++ b/src/cli.vala @@ -0,0 +1,55 @@ +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 }, +}; + +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); + 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; +} |