summaryrefslogtreecommitdiff
path: root/src/cli.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli.vala')
-rw-r--r--src/cli.vala54
1 files changed, 29 insertions, 25 deletions
diff --git a/src/cli.vala b/src/cli.vala
index 433ba43..afce774 100644
--- a/src/cli.vala
+++ b/src/cli.vala
@@ -5,6 +5,7 @@ static bool list;
static string invoke;
static int close_n;
static int get_n;
+static bool toggle_dnd;
const OptionEntry[] options = {
{ "version", 'v', OptionFlags.NONE, OptionArg.NONE, ref version, null, null },
@@ -14,6 +15,7 @@ const OptionEntry[] options = {
{ "invoke", 'i', OptionFlags.NONE, OptionArg.STRING, ref invoke, null, null },
{ "close", 'c', OptionFlags.NONE, OptionArg.INT, ref close_n, null, null },
{ "get", 'g', OptionFlags.NONE, OptionArg.INT, ref get_n, null, null },
+ { "toggle-dnd", 't', OptionFlags.NONE, OptionArg.NONE, ref toggle_dnd, null, null },
{ null },
};
@@ -34,17 +36,17 @@ int main(string[] argv) {
print("Usage:\n");
print(" %s [flags]\n\n", argv[0]);
print("Flags:\n");
- print(" -h, --help Print this help and exit\n");
- print(" -v, --version Print version number and exit\n");
- print(" -l, --list Print every notification and exit\n");
- print(" -d, --daemonize Watch for new notifications\n");
- print(" -i, --invoke Invoke a notification action\n");
- print(" -c, --close Close a notification by its id\n");
- print(" -g, --get Print a notification by its id\n");
+ print(" -h, --help Print this help and exit\n");
+ print(" -v, --version Print version number and exit\n");
+ print(" -l, --list Print every notification and exit\n");
+ print(" -d, --daemonize Watch for new notifications\n");
+ print(" -i, --invoke Invoke a notification action\n");
+ print(" -c, --close Close a notification by its id\n");
+ print(" -g, --get Print a notification by its id\n");
+ print(" -t, --toggle-dnd Toggle do not disturb\n");
return 0;
}
- var loop = new MainLoop();
var notifd = new AstalNotifd.Notifd();
if (version) {
@@ -53,16 +55,27 @@ int main(string[] argv) {
}
if (list) {
- var cache = Environment.get_user_cache_dir() + "/astal/notifd/notifications.json";
- if (FileUtils.test(cache, FileTest.EXISTS)) {
+ var state = Environment.get_user_state_dir() + "/astal/notifd/notifications.json";
+ if (FileUtils.test(state, FileTest.EXISTS)) {
try {
uint8[] json;
- File.new_for_path(cache).load_contents(null, out json, null);
- stdout.printf("%s", (string)json);
+ File.new_for_path(state).load_contents(null, out json, null);
+
+ var obj = Json.from_string((string)json);
+
+ var list = obj.get_object().get_member("notifications");
+ stdout.printf("%s\n", Json.to_string(list, true));
+ return 0;
} catch (Error err) {
stderr.printf("failed to load cache: %s", err.message);
}
}
+ stdout.printf("[]\n");
+ return 0;
+ }
+
+ if (toggle_dnd) {
+ notifd.dont_disturb = !notifd.dont_disturb;
return 0;
}
@@ -71,6 +84,7 @@ int main(string[] argv) {
stdout.printf("%s\n", notifd.get_notification_json(id));
stdout.flush();
});
+ new MainLoop().run();
}
if (invoke != null) {
@@ -83,29 +97,19 @@ int main(string[] argv) {
var n_id = int.parse(split[0]);
var a_id = split[1];
- notifd.active.connect(() => {
- notifd.get_notification(n_id).invoke(a_id);
- loop.quit();
- });
+ notifd.get_notification(n_id).invoke(a_id);
}
if (close_n > 0) {
- notifd.active.connect(() => {
- notifd.get_notification(close_n).dismiss();
- loop.quit();
- });
+ notifd.get_notification(close_n).dismiss();
}
if (get_n > 0) {
- notifd.active.connect(() => {
- stdout.printf("%s", notifd.get_notification(get_n).to_json_string());
- loop.quit();
- });
+ stdout.printf("%s", notifd.get_notification(get_n).to_json_string());
}
if (!daemonize && invoke == null && close_n == 0 && get_n == 0)
return 1;
- loop.run();
return 0;
}