summaryrefslogtreecommitdiff
path: root/gui-apps/tuigreet/files/tuigreet-0.7.1-power-command-notify.patch
blob: 99b79d7c2a1babf5144bb5e1098fb765ec2bb38d (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
--- a/src/greeter.rs
+++ b/src/greeter.rs
@@ -16,7 +16,7 @@ use tokio::{
   process::Command,
   sync::{
     oneshot::{Receiver, Sender},
-    RwLock, RwLockWriteGuard,
+    Notify, RwLock, RwLockWriteGuard,
   },
 };
 use zeroize::Zeroize;
@@ -90,6 +90,7 @@ pub struct Greeter {
 
   pub power_commands: HashMap<PowerOption, String>,
   pub power_command: Option<Command>,
+  pub power_command_notify: Arc<Notify>,
   pub power_setsid: bool,
 
   pub working: bool,
--- a/src/main.rs
+++ b/src/main.rs
@@ -64,9 +64,12 @@ async fn run() -> Result<(), Box<dyn Error>> {
 
   tokio::task::spawn({
     let greeter = greeter.clone();
+    let notify = greeter.read().await.power_command_notify.clone();
 
     async move {
       loop {
+        notify.notified().await;
+
         let command = greeter.write().await.power_command.take();
 
         if let Some(mut command) = command {
--- a/src/power.rs
+++ b/src/power.rs
@@ -50,4 +50,5 @@ pub fn power(greeter: &mut Greeter, option: PowerOption) {
   };
 
   greeter.power_command = Some(command);
+  greeter.power_command_notify.notify_one();
 }