Added GetSubscribeData to dbus daemon (#123)

* Added GetSubscribeData to dbus daemon

* Updated client to use GetSubscribeData
This commit is contained in:
Erik Reider
2022-05-14 12:54:48 +02:00
committed by GitHub
parent f4ba92140f
commit d295a76e77
2 changed files with 29 additions and 6 deletions

View File

@@ -1,3 +1,9 @@
public struct SwayncDaemonData {
public bool dnd;
public bool cc_open;
public uint count;
}
[DBus (name = "org.erikreider.swaync.cc")]
interface CcDaemon : GLib.Object {
@@ -21,6 +27,9 @@ interface CcDaemon : GLib.Object {
public abstract void set_visibility (bool value) throws DBusError, IOError;
[DBus (name = "GetSubscribeData")]
public abstract SwayncDaemonData get_subscribe_data () throws Error;
public signal void subscribe (uint count, bool dnd, bool cc_open);
}
@@ -58,9 +67,8 @@ private void on_subscribe (uint count, bool dnd, bool cc_open) {
private void print_subscribe () {
try {
on_subscribe (cc_daemon.notification_count (),
cc_daemon.get_dnd (),
cc_daemon.get_visibility ());
SwayncDaemonData data = cc_daemon.get_subscribe_data ();
on_subscribe (data.count, data.dnd, data.cc_open);
} catch (Error e) {
on_subscribe (0, false, false);
}
@@ -86,9 +94,8 @@ private void on_subscribe_waybar (uint count, bool dnd, bool cc_open) {
private void print_subscribe_waybar () {
try {
on_subscribe_waybar (cc_daemon.notification_count (),
cc_daemon.get_dnd (),
cc_daemon.get_visibility ());
SwayncDaemonData data = cc_daemon.get_subscribe_data ();
on_subscribe_waybar (data.count, data.dnd, data.cc_open);
} catch (Error e) {
on_subscribe_waybar (0, false, false);
}

View File

@@ -1,4 +1,10 @@
namespace SwayNotificationCenter {
public struct Data {
public bool dnd;
public bool cc_open;
public uint count;
}
[DBus (name = "org.erikreider.swaync.cc")]
public class SwayncDaemon : Object {
public StateCache cache_state;
@@ -57,6 +63,16 @@ namespace SwayNotificationCenter {
}
}
/** Gets subscribe data but in one call */
[DBus (name = "GetSubscribeData")]
public Data get_subscribe_data () throws Error {
return Data () {
dnd = get_dnd (),
cc_open = get_visibility (),
count = notification_count (),
};
}
/**
* Called when Dot Not Disturb state changes and when
* notification gets added/removed