summarylogtreecommitdiffstats
path: root/0001-invoke-waked-when-an-alarm-changes.patch
blob: cb88c27ece680bcf944ab040d29f4458957de925 (plain)
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
187
188
189
190
191
192
193
From 65007fd13530afe604a05ff7ab85fb71eb041936 Mon Sep 17 00:00:00 2001
From: Robin Westermann <gitlab@seath.de>
Date: Sat, 27 Feb 2021 14:41:22 +0100
Subject: [PATCH] invoke waked when an alarm changes

When an alarm is deleted, created, edited or rearmed the service
waked is notified about the update. So waked can wake the system
from suspend when an alarm is fired.

Fixes #100

Co-Authored-By: pcworld <0188801@gmail.com>
---
 build-aux/flatpak/org.gnome.clocks.json |  1 +
 src/alarm-face.vala                     |  2 +
 src/alarm-item.vala                     | 14 ++++++-
 src/alarm-setup-dialog.vala             |  1 +
 src/meson.build                         |  1 +
 src/waked-utils.vala                    | 53 +++++++++++++++++++++++++
 6 files changed, 70 insertions(+), 2 deletions(-)
 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 b3d768f..daedbf8 100644
--- a/build-aux/flatpak/org.gnome.clocks.json
+++ b/build-aux/flatpak/org.gnome.clocks.json
@@ -11,6 +11,7 @@
         "--socket=fallback-x11",
         "--socket=wayland",
         "--socket=pulseaudio",
+        "--system-talk-name=de.seath.Waked",
         "--share=network",
         "--env=G_MESSAGES_DEBUG=org.gnome.ClocksDevel"
     ],
diff --git a/src/alarm-face.vala b/src/alarm-face.vala
index 04728ab..1a593a7 100644
--- a/src/alarm-face.vala
+++ b/src/alarm-face.vala
@@ -121,6 +121,7 @@ public class Face : Adw.Bin, Clocks.Clock {
                 ((SetupDialog) dialog).apply_to_alarm (alarm);
                 save ();
             } else if (response == DELETE_ALARM) {
+                WakedUtils.remove_timer (alarm.id);
                 alarms.delete_item (alarm);
                 save ();
             }
@@ -130,6 +131,7 @@ public class Face : Adw.Bin, Clocks.Clock {
     }
 
     internal void delete (Item alarm) {
+        WakedUtils.remove_timer (alarm.id);
         alarms.delete_item (alarm);
         save ();
     }
diff --git a/src/alarm-item.vala b/src/alarm-item.vala
index 6103342..e350d1d 100644
--- a/src/alarm-item.vala
+++ b/src/alarm-item.vala
@@ -20,6 +20,7 @@
 namespace Clocks {
 namespace Alarm {
 
+
 private struct AlarmTime {
     public int hour;
     public int minute;
@@ -88,8 +89,11 @@ private class Item : Object, ContentItem {
                 _active = value;
                 if (_active) {
                     reset ();
-                } else if (state == State.RINGING) {
-                    stop ();
+                } else {
+                    WakedUtils.remove_timer (id);
+                    if (state == State.RINGING) {
+                        stop ();
+                    }
                 }
                 notify_property ("active");
             }
@@ -150,6 +154,10 @@ private class Item : Object, ContentItem {
         }
 
         alarm_time = dt;
+
+        if (active) {
+            WakedUtils.update_timer (id, alarm_time);
+        }
     }
 
     private void update_snooze_time (GLib.DateTime start_time) {
@@ -172,6 +180,7 @@ private class Item : Object, ContentItem {
     public void snooze () {
         bell.stop ();
         state = State.SNOOZING;
+        WakedUtils.update_timer (id, snooze_time);
     }
 
     public void stop () {
@@ -221,6 +230,7 @@ private class Item : Object, ContentItem {
             update_alarm_time (); // reschedule for the next repeat
         }
 
+
         return state != last_state;
     }
 
diff --git a/src/alarm-setup-dialog.vala b/src/alarm-setup-dialog.vala
index 30163f3..a838993 100644
--- a/src/alarm-setup-dialog.vala
+++ b/src/alarm-setup-dialog.vala
@@ -264,6 +264,7 @@ private class SetupDialog : Gtk.Dialog {
 
     private void avoid_duplicate_alarm () {
         var alarm = new Item ();
+        alarm.editing = true;
         apply_to_alarm (alarm);
 
         var duplicate = alarm.check_duplicate_alarm (other_alarms);
diff --git a/src/meson.build b/src/meson.build
index 61bf1ab..129e9a3 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',
diff --git a/src/waked-utils.vala b/src/waked-utils.vala
new file mode 100644
index 0000000..9b8fa4a
--- /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);
+        }
+    }
+}
+}
-- 
2.35.1