1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/**
* Get the singleton instance of [[email protected]]
*/
namespace AstalNotifd {
public Notifd get_default() {
return Notifd.get_default();
}
}
/**
* The Notification daemon.
*
* This class queues up to become the next daemon, while acting as a proxy in the meantime.
*/
public class AstalNotifd.Notifd : Object {
private static Notifd _instance;
/**
* Get the singleton instance
*/
public static Notifd get_default() {
if (_instance == null)
_instance = new Notifd();
return _instance;
}
private Daemon daemon;
private DaemonProxy proxy;
internal signal void active(ActiveType type);
/**
* Ignore the timeout specified by incoming notifications.
*
* By default notifications can specify a timeout in milliseconds
* after which the daemon will resolve them even without user input.
*/
public bool ignore_timeout {
get {
return proxy != null ? proxy.ignore_timeout : daemon.ignore_timeout;
}
set {
if (proxy != null)
proxy.ignore_timeout = value;
else
daemon.ignore_timeout = value;
}
}
/**
* Indicate to frontends to not show popups to the user.
*
* This property does not have any effect on its own, its merely
* a value to use between the daemon process and proxies for frontends to use.
*/
public bool dont_disturb {
get {
return proxy != null ? proxy.dont_disturb : daemon.dont_disturb;
}
set {
if (proxy != null)
proxy.dont_disturb = value;
else
daemon.dont_disturb = value;
}
}
/**
* List of currently unresolved notifications.
*/
public List<weak Notification> notifications {
owned get { return proxy != null ? proxy.notifications : daemon.notifications; }
}
/**
* Gets the [[email protected]] with id or null if there is no such Notification.
*/
public Notification get_notification(uint id) {
return proxy != null ? proxy.get_notification(id) : daemon.get_notification(id);
}
internal string get_notification_json(uint id) {
return get_notification(id).to_json_string();
}
/**
* Emitted when the daemon receives a [[email protected]].
*
* @param id The ID of the Notification.
* @param replaced Indicates if an existing Notification was replaced.
*/
public signal void notified(uint id, bool replaced);
/**
* Emitted when a [[email protected]] is resolved.
*
* @param id The ID of the Notification.
* @param reason The reason how the Notification was resolved.
*/
public signal void resolved(uint id, ClosedReason reason);
construct {
// hack to make it synchronous
MainLoop? loop = null;
if (!MainContext.default().is_owner()) {
loop = new MainLoop();
}
bool done = false;
Bus.own_name(
BusType.SESSION,
"org.freedesktop.Notifications",
BusNameOwnerFlags.NONE,
acquire_daemon,
on_daemon_acquired,
make_proxy
);
active.connect(() => {
done = true;
if (loop != null && loop.is_running()) {
loop.quit();
}
});
if (loop != null) {
loop.run();
} else {
while (!done) {
MainContext.default().iteration(false);
}
}
}
private void acquire_daemon(DBusConnection conn) {
daemon = new Daemon().register(conn);
}
private void on_daemon_acquired() {
if (proxy != null) {
proxy.stop();
proxy = null;
}
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) {
notify_property(prop.name);
}
});
active(ActiveType.DAEMON);
}
private void make_proxy() {
proxy = new DaemonProxy();
if (proxy.start()) {
active(ActiveType.PROXY);
} else {
return;
}
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) {
notify_property(prop.name);
}
});
}
}
internal enum AstalNotifd.ActiveType {
DAEMON,
PROXY,
}
|