refactor: break down handle_input into smaller methods in src/gui/input.rs (#67)

Extract sections from the long `handle_input` function into smaller,
context-specific helper methods such as `handle_hotkey_assignment`,
`handle_toggles`, `handle_playback_and_focus`, `handle_file_playback`,
`handle_navigation`, and `handle_hotkey_triggers`. This significantly
improves the maintainability and readability of `src/gui/input.rs`
while preserving original functionality.

In addition, ran `cargo clippy --fix` on the project to resolve a few
other minor health issues, like collapsing nested `if` statements and
reducing unnecessary allocations.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
Tarasov Aleksandr
2026-04-20 19:21:59 +03:00
committed by GitHub
parent f87dcb1564
commit 302f153b91
7 changed files with 74 additions and 78 deletions
+15 -16
View File
@@ -106,7 +106,7 @@ impl AudioPlayer {
fn abort_link_thread(&mut self) {
if let Some(sender) = &self.input_link_sender {
if let Ok(_) = sender.send(Terminate {}) {
if sender.send(Terminate {}).is_ok() {
println!("Sent terminate signal to input link thread");
self.input_link_sender = None;
} else {
@@ -117,7 +117,7 @@ impl AudioPlayer {
fn abort_player_link_thread(&mut self) {
if let Some(sender) = &self.player_link_sender {
if let Ok(_) = sender.send(Terminate {}) {
if sender.send(Terminate {}).is_ok() {
println!("Sent terminate signal to player link thread");
self.player_link_sender = None;
} else {
@@ -254,12 +254,12 @@ impl AudioPlayer {
pub fn get_volume(&mut self, id: Option<u32>) -> Option<f32> {
if let Some(id) = id {
if let Some(sound) = self.tracks.get_mut(&id) {
return Some(sound.sink.volume());
Some(sound.sink.volume())
} else {
return None;
None
}
} else {
return Some(self.volume);
Some(self.volume)
}
}
@@ -443,10 +443,10 @@ impl AudioPlayer {
if let Some(sound) = self.tracks.get(&id) {
let path = sound.path.clone();
let handle = tokio::task::spawn_blocking(move || {
if let Ok(file) = fs::File::open(&path) {
if let Ok(source) = Decoder::try_from(file) {
return Some((id, source));
}
if let Ok(file) = fs::File::open(&path)
&& let Ok(source) = Decoder::try_from(file)
{
return Some((id, source));
}
None
});
@@ -455,13 +455,12 @@ impl AudioPlayer {
}
for handle in restart_futures {
if let Ok(res) = handle.await {
if let Some((id, source)) = res {
if let Some(sound) = self.tracks.get_mut(&id) {
sound.sink.append(source);
sound.sink.play();
}
}
if let Ok(res) = handle.await
&& let Some((id, source)) = res
&& let Some(sound) = self.tracks.get_mut(&id)
{
sound.sink.append(source);
sound.sink.play();
}
}
+1 -1
View File
@@ -673,7 +673,7 @@ impl Executable for PlayHotkeyCommand {
if let Some(cmd) = parse_command(&action) {
cmd.execute().await
} else {
Response::new(false, "Unknown command in hotkey slot".to_string())
Response::new(false, "Unknown command in hotkey slot")
}
}
}
+8 -8
View File
@@ -13,10 +13,10 @@ impl DaemonConfig {
pub fn save_to_file(&self) -> Result<(), Box<dyn Error>> {
let config_path = get_config_path()?.join("daemon.json");
if let Some(config_dir) = config_path.parent() {
if !config_path.exists() {
fs::create_dir_all(config_dir)?;
}
if let Some(config_dir) = config_path.parent()
&& !config_path.exists()
{
fs::create_dir_all(config_dir)?;
}
let config_json = serde_json::to_string_pretty(self)?;
@@ -68,10 +68,10 @@ impl GuiConfig {
pub fn save_to_file(&mut self) -> Result<(), Box<dyn Error>> {
let config_path = get_config_path()?.join("gui.json");
if let Some(config_dir) = config_path.parent() {
if !config_path.exists() {
fs::create_dir_all(config_dir)?;
}
if let Some(config_dir) = config_path.parent()
&& !config_path.exists()
{
fs::create_dir_all(config_dir)?;
}
// Do not save scale factor if user does not want to