Skip to content

Commit 5a91352

Browse files
committed
reduce the idle timings by half
1 parent f1140f9 commit 5a91352

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use std::{
88
collections::HashMap,
99
error::Error,
1010
process::{Child, Command},
11-
sync::atomic::AtomicBool,
12-
sync::{Arc, Mutex},
11+
sync::{atomic::AtomicBool, Arc, Mutex},
1312
thread::sleep,
1413
time::{Duration, Instant},
1514
};
@@ -45,6 +44,7 @@ impl DBusInterface for DBusRunner {
4544
msg.read3::<String, HashMap<_, _>, Vec<String>>().unwrap().1;
4645
if let Some(playback_status) = items.get("PlaybackStatus") {
4746
if let Some(status) = playback_status.0.as_str() {
47+
log::debug!("Status found {}", status);
4848
if status == "Playing" {
4949
good_to_send.store(true, std::sync::atomic::Ordering::SeqCst);
5050
} else {
@@ -121,8 +121,6 @@ impl IdleApp {
121121
Ok(child) => {
122122
log::debug!("Swayidle is inhibiting now!");
123123
inhibit.0 = Some(child);
124-
process_running
125-
.store(true, std::sync::atomic::Ordering::SeqCst);
126124
}
127125
Err(e) => {
128126
eprintln!("unable to block swayidle :: {:?}", e)
@@ -152,6 +150,7 @@ impl IdleApp {
152150

153151
fn run_cmd(&self) -> Result<Child, Box<dyn Error>> {
154152
log::debug!("command is spawning");
153+
let process_running = Arc::clone(&self.process_running);
155154
match Command::new("systemd-inhibit")
156155
.arg("--what")
157156
.arg("idle")
@@ -170,6 +169,7 @@ impl IdleApp {
170169
if let Ok(mut last_block_time) = self.last_block_time.lock() {
171170
*last_block_time = Some(Instant::now());
172171
}
172+
process_running.store(true, std::sync::atomic::Ordering::SeqCst);
173173
Ok(child)
174174
}
175175
Err(e) => {
@@ -185,13 +185,13 @@ impl IdleApp {
185185

186186
const INTERFACE_NAME: &str = "org.freedesktop.DBus.Properties";
187187
const DBUS_NAMESPACE: &str = "/org/mpris/MediaPlayer2";
188-
const INHIBIT_DURATION: u64 = 55;
188+
const INHIBIT_DURATION: u64 = 25;
189189
const OVERLAP_DURATION: u64 = 5;
190190

191191
fn main() -> Result<(), Box<dyn Error>> {
192192
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
193193
log::debug!("Swaddle starting up");
194-
let app = IdleApp::new(60)?;
194+
let app = IdleApp::new(30)?;
195195
app.run()
196196
}
197197

0 commit comments

Comments
 (0)