diff options
author | Aylur <[email protected]> | 2024-06-20 16:38:02 +0200 |
---|---|---|
committer | Aylur <[email protected]> | 2024-06-20 16:38:02 +0200 |
commit | 9812a21318abc3c508c5a6152336578d621a1032 (patch) | |
tree | b7641d9a1845c966204deea8c65f55d957da6d5f | |
parent | 758f1b3e4c767a9345a81b0d60873e57264d497f (diff) |
feat: notified replaced parameter
-rw-r--r-- | src/daemon.vala | 12 | ||||
-rw-r--r-- | src/notifd.vala | 6 | ||||
-rw-r--r-- | src/proxy.vala | 9 | ||||
-rw-r--r-- | src/signals.md | 7 |
4 files changed, 18 insertions, 16 deletions
diff --git a/src/daemon.vala b/src/daemon.vala index 69212ef..6b11204 100644 --- a/src/daemon.vala +++ b/src/daemon.vala @@ -22,12 +22,11 @@ internal class Daemon : Object { public bool ignore_timeout { get; set; } public bool dont_disturb { get; set; } - public signal void notified(uint id); + public signal void notified(uint id, bool replaced); public signal void resolved(uint id, ClosedReason reason); public signal void action_invoked(uint id, string action); // emitting an event from proxy doesn't seem to work - public void emit_notified(uint id) { notified(id); } public void emit_resolved(uint id, ClosedReason reason) { resolved(id, reason); } public void emit_action_invoked(uint id, string action) { action_invoked(id, action); } @@ -110,7 +109,7 @@ internal class Daemon : Object { var id = replaces_id > 0 ? replaces_id : n_id++; - add_notification(new Notification( + var replaced = add_notification(new Notification( app_name, id, app_icon, summary, body, actions, hints, expire_timeout )); @@ -121,17 +120,18 @@ internal class Daemon : Object { }, Priority.DEFAULT); } - if (!dont_disturb) - notified(id); + notified(id, replaced); cache(); return id; } - private void add_notification(Notification n) { + private bool add_notification(Notification n) { n.dismissed.connect(() => resolved(n.id, ClosedReason.DISMISSED_BY_USER)); n.invoked.connect((action) => action_invoked(n.id, action)); + var replaced = notifs.contains(n.id); notifs.set(n.id, n); + return replaced; } private void cache() { diff --git a/src/notifd.vala b/src/notifd.vala index 55d910b..f967421 100644 --- a/src/notifd.vala +++ b/src/notifd.vala @@ -50,7 +50,7 @@ public class Notifd : Object { return get_notification(id).to_json_string(); } - public signal void notified(uint id); + public signal void notified(uint id, bool replaced); public signal void resolved(uint id, ClosedReason reason); construct { @@ -72,7 +72,7 @@ public class Notifd : Object { private void try_daemon(DBusConnection conn) { daemon = new Daemon().register(conn); - daemon.notified.connect((id) => notified(id)); + daemon.notified.connect((id, replaced) => notified(id, replaced)); daemon.resolved.connect((id, reason) => resolved(id, reason)); daemon.notify.connect((prop) => { if (get_class().find_property(prop.name) != null) { @@ -89,7 +89,7 @@ public class Notifd : Object { return; } - proxy.notified.connect((id) => notified(id)); + proxy.notified.connect((id, replaced) => notified(id, replaced)); proxy.resolved.connect((id, reason) => resolved(id, reason)); proxy.notify.connect((prop) => { if (get_class().find_property(prop.name) != null) { diff --git a/src/proxy.vala b/src/proxy.vala index b5686fe..f32abbd 100644 --- a/src/proxy.vala +++ b/src/proxy.vala @@ -7,10 +7,9 @@ internal interface IDaemon : Object { public abstract uint[] notification_ids() throws DBusError, IOError; public abstract string get_notification_json(uint id) throws DBusError, IOError; - public signal void notified(uint id); + public signal void notified(uint id, bool replaced); public signal void resolved(uint id, ClosedReason reason); - public abstract void emit_notified(uint id); public abstract void emit_resolved(uint id, ClosedReason reason); public abstract void emit_action_invoked(uint id, string action); } @@ -41,7 +40,7 @@ internal class DaemonProxy : Object { return notifs.get(id); } - public signal void notified(uint id); + public signal void notified(uint id, bool replaced); public signal void resolved(uint id, ClosedReason reason); IDaemon proxy; @@ -103,9 +102,9 @@ internal class DaemonProxy : Object { notify_property(pspec.name); })); - ids.append(proxy.notified.connect((id) => { + ids.append(proxy.notified.connect((id, replaced) => { add_notification(id); - notified(id); + notified(id, replaced); })); ids.append(proxy.resolved.connect((id, reason) => { diff --git a/src/signals.md b/src/signals.md index 0111596..cdc6688 100644 --- a/src/signals.md +++ b/src/signals.md @@ -11,17 +11,20 @@ ignore this, I'm just dumb and can't follow where signals go or get emitted from ## Deamon non-spec, used by user -* notified(id) - by outside through dbus with `.Notify()` + +* notified(id, replaced) - by outside through dbus with `.Notify()` * resolved(id, reason) - by `Notification.dismiss()` or outside with `.CloseNotification` spec, not used by user + * notification_closed(id, reason) - sideeffect of `resolved` * action_invoked(id, action) - by `Notification.invoke()` ## Proxy mirrors Daemon -* notified(id) + +* notified(id, replaced) * resolved(id, reason) creates `Notification` objects through daemon's json strings |