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
180
181
182
183
184
185
186
|
From bf30260ed3bf6fdf14fd25f3b760f7c60500571c Mon Sep 17 00:00:00 2001
From: Egor Shestakov <ved@altlinux.org>
Date: Fri, 26 Apr 2024 20:33:24 +0700
Subject: [PATCH] alarm: Waked support patch
Add buildtime option that enables waked support.
Since many distibutions use waked for a long
time it could be upstreamed. This solution may
be considered as universal because it requires
only running the waked daemon and it is suitable
for both systems with or without systemd.
---
build-aux/flatpak/org.gnome.clocks.json | 1 +
meson_options.txt | 4 +-
src/alarm-face.vala | 6 +++
src/alarm-item.vala | 13 ++++++
src/meson.build | 5 +++
src/waked-utils.vala | 53 +++++++++++++++++++++++++
6 files changed, 81 insertions(+), 1 deletion(-)
create mode 100644 src/waked-utils.vala
diff --git a/build-aux/flatpak/org.gnome.clocks.json b/build-aux/flatpak/org.gnome.clocks.json
index d0a5a730..04afb90b 100644
--- a/build-aux/flatpak/org.gnome.clocks.json
+++ b/build-aux/flatpak/org.gnome.clocks.json
@@ -15,6 +15,7 @@
"--socket=wayland",
"--socket=pulseaudio",
"--share=network",
+ "--system-talk-name=de.seath.Waked",
"--env=G_MESSAGES_DEBUG=org.gnome.ClocksDevel"
],
"build-options": {
diff --git a/meson_options.txt b/meson_options.txt
index 12ff40dc..928e8a39 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -9,4 +9,6 @@ option(
description: 'The build profile for Clock. One of "default" or "development".'
)
-option('docs', type : 'boolean', value : false)
\ No newline at end of file
+option('docs', type : 'boolean', value : false)
+
+option('waked', type : 'boolean', value : true)
diff --git a/src/alarm-face.vala b/src/alarm-face.vala
index b7625350..5de1efb0 100644
--- a/src/alarm-face.vala
+++ b/src/alarm-face.vala
@@ -84,6 +84,9 @@ public class Face : Adw.Bin, Clocks.Clock {
});
row.remove_alarm.connect (() => {
+#if HAVE_WAKED
+ WakedUtils.remove_timer (((Item) item).id);
+#endif
alarms.delete_item ((Item) item);
if (ring_time_toast != null && item == ring_time_toast_alarm) {
ring_time_toast_alarm = null;
@@ -187,6 +190,9 @@ public class Face : Adw.Bin, Clocks.Clock {
alarm.active = true;
save ();
} else if (response == DELETE_ALARM) {
+#if HAVE_WAKED
+ WakedUtils.remove_timer (alarm.id);
+#endif
alarms.delete_item (alarm);
save ();
}
diff --git a/src/alarm-item.vala b/src/alarm-item.vala
index 27968f75..34e6b256 100644
--- a/src/alarm-item.vala
+++ b/src/alarm-item.vala
@@ -87,6 +87,14 @@ private class Item : Object, ContentItem {
notify_property ("active");
}
notify_property ("ring-time");
+
+#if HAVE_WAKED
+ if (value == null) {
+ WakedUtils.remove_timer (id);
+ } else {
+ WakedUtils.update_timer (id, ring_time);
+ }
+#endif
}
}
@@ -186,6 +194,11 @@ private class Item : Object, ContentItem {
var guid = id != null ? (string) id : GLib.DBus.generate_guid ();
Object (id: guid);
}
+ ~Item () {
+#if HAVE_WAKED
+ WakedUtils.remove_timer (id);
+#endif
+ }
private void setup_bell () {
bell = new Utils.Bell (GLib.File.new_for_uri ("resource://org/gnome/clocks/sounds/alarm-clock-elapsed.oga"));
diff --git a/src/meson.build b/src/meson.build
index 344781c8..9f42855c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -24,6 +24,7 @@ clocks_vala_sources = files(
'timer-setup.vala',
'timer-setup-dialog.vala',
'utils.vala',
+ 'waked-utils.vala',
'widgets.vala',
'window.vala',
'world-face.vala',
@@ -47,6 +48,10 @@ clocks_sources = [
resources
]
+if get_option('waked')
+ add_project_arguments('-D', 'HAVE_WAKED', language: 'vala')
+endif
+
clocks_vala_args = [
'--target-glib', '2.72',
'--vapidir', meson.current_source_dir(),
diff --git a/src/waked-utils.vala b/src/waked-utils.vala
new file mode 100644
index 00000000..9b8fa4ad
--- /dev/null
+++ b/src/waked-utils.vala
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2021 Robin Westermann <waked@seath.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+namespace Clocks {
+namespace WakedUtils {
+
+ [DBus (name = "de.seath.Waked")]
+ interface Waked : Object {
+ public abstract void add (string id, uint64 time) throws GLib.Error;
+ public abstract void update (string id, uint64 time) throws GLib.Error;
+ public abstract void remove (string id) throws GLib.Error;
+ }
+
+ public void update_timer (string id, GLib.DateTime time) {
+ try {
+ Waked waked = Bus.get_proxy_sync (BusType.SYSTEM, "de.seath.Waked",
+ "/de/seath/Waked/Alarm");
+
+ waked.update (id, time.to_unix ());
+
+ } catch (GLib.Error e) {
+ stderr.printf ("%s\n", e.message);
+ }
+ }
+
+ public void remove_timer (string id) {
+ try {
+ Waked waked = Bus.get_proxy_sync (BusType.SYSTEM, "de.seath.Waked",
+ "/de/seath/Waked/Alarm");
+
+ waked.remove (id);
+
+ } catch (GLib.Error e) {
+ stderr.printf ("%s\n", e.message);
+ }
+ }
+}
+}
--
GitLab
|