Skip to content

Commit 77f9c02

Browse files
committed
preparing for release
1 parent 98a4a00 commit 77f9c02

1 file changed

Lines changed: 4 additions & 72 deletions

File tree

src/main.rs

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use std::time::{Duration, SystemTime};
1212
use std::{fs, io};
1313

1414
// In seconds
15-
const DEBUG_INTERVAL: u64 = 5;
15+
const DEBUG_INTERVAL: u64 = 60;
1616

1717
#[derive(Parser, Debug)]
1818
#[command(author="Rasmus Kirk", version, about = "Rustle - Keep your digital speakers from sleeping, using low sound signals", long_about = None)]
1919
struct Args {
20-
/// Duration of each tone in seconds
20+
/// Duration of each tone in seconds (0 for continual playback)
2121
#[arg(short = 'd', long, default_value_t = 120.0)]
2222
pulse_duration: f32,
2323

@@ -29,8 +29,8 @@ struct Args {
2929
#[arg(short = 'a', long, default_value_t = 0.01)]
3030
amplitude: f32,
3131

32-
/// Minutes of undetected sound until the tone plays
33-
#[arg(short = 's', long, default_value_t = 10)]
32+
/// Minutes of undetected sound until the tone plays (0 to ignore playing sound)
33+
#[arg(short = 's', long, default_value_t = 0)]
3434
minutes_of_silence: u64,
3535
}
3636

@@ -55,74 +55,6 @@ fn is_playing_pipewire() -> anyhow::Result<bool> {
5555
Ok(str::from_utf8(&x)?.trim() != "0")
5656
}
5757

58-
// This function is horrible no matter what I do lol
59-
fn is_playing_alsa() -> io::Result<bool> {
60-
let base_path = Path::new("/proc/asound");
61-
62-
let handle_err = |e| {
63-
error!("{e}");
64-
false
65-
};
66-
67-
let f = |entry: io::Result<DirEntry>, starts_with| {
68-
let entry = entry.ok()?;
69-
let filename_starts_with = entry.file_name().to_string_lossy().starts_with(starts_with);
70-
let is_dir = entry
71-
.file_type()
72-
.map(|ft| ft.is_dir())
73-
.unwrap_or_else(handle_err);
74-
if !(filename_starts_with && is_dir) {
75-
return None;
76-
};
77-
Some(entry)
78-
};
79-
80-
let check_sub = |path| {
81-
fs::read_dir(path)
82-
.into_iter()
83-
.flatten()
84-
.filter(|entry| {
85-
entry
86-
.as_ref()
87-
.is_ok_and(|x| x.file_name().to_str().is_some_and(|x| x == "status"))
88-
})
89-
.any(|status| {
90-
status.is_ok_and(|status| {
91-
fs::read_to_string(status.path())
92-
.map(|content| content.contains("state: RUNNING"))
93-
.unwrap_or_else(handle_err)
94-
})
95-
})
96-
};
97-
98-
let check_pcm = |path| {
99-
fs::read_dir(path)
100-
.into_iter()
101-
.flatten()
102-
.filter_map(|x| f(x, "sub"))
103-
.any(|sub| check_sub(sub.path()))
104-
};
105-
106-
let check_card = |path: &Path| {
107-
fs::read_dir(path)
108-
.into_iter()
109-
.flatten()
110-
.filter_map(|x| f(x, "pcm"))
111-
.any(|pcm| check_pcm(pcm.path()))
112-
};
113-
114-
Ok(fs::read_dir(base_path)?
115-
.filter_map(|entry| entry.ok())
116-
.filter(|entry| entry.file_name().to_string_lossy().starts_with("card"))
117-
.filter(|entry| {
118-
entry
119-
.file_type()
120-
.map(|ft| ft.is_dir())
121-
.unwrap_or_else(handle_err)
122-
})
123-
.any(|card| check_card(&card.path())))
124-
}
125-
12658
fn play_sound(args: &Args) -> anyhow::Result<()> {
12759
let (_stream, stream_handle) = OutputStream::try_default()?;
12860
let sink = Sink::try_new(&stream_handle)?;

0 commit comments

Comments
 (0)