mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
refactor(gui): replace unsafe unwrap with idiomatic if let Some in input handling (#22)
This commit addresses a code health issue in `src/gui/input.rs` where an `.is_some()` check was followed by an unsafe `.unwrap()` on `self.app_state.selected_file`. The logic has been updated to use the idiomatic `if let Some(path) = self.app_state.selected_file.clone()` pattern. The `.clone()` is necessary because the subsequent methods (`self.play_file` and `self.stop`) require a mutable borrow (`&mut self`), which would conflict with an immutable borrow of `self.app_state.selected_file`. This change ensures the code is safe and panic-free while satisfying Rust's borrow checker rules. Behavior remains unchanged. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
c649ef5410
commit
39648f7781
+6
-5
@@ -57,17 +57,18 @@ impl SoundpadGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Play selected file on Enter
|
// Play selected file on Enter
|
||||||
if self.key_pressed(ctx, Key::Enter) && self.app_state.selected_file.is_some() {
|
if self.key_pressed(ctx, Key::Enter) {
|
||||||
let path = &self.app_state.selected_file.clone().unwrap();
|
if let Some(path) = self.app_state.selected_file.clone() {
|
||||||
if modifiers.ctrl {
|
if modifiers.ctrl {
|
||||||
self.play_file(path, true);
|
self.play_file(&path, true);
|
||||||
} else if modifiers.shift
|
} else if modifiers.shift
|
||||||
&& let Some(last_track) = self.audio_player_state.tracks.last()
|
&& let Some(last_track) = self.audio_player_state.tracks.last()
|
||||||
{
|
{
|
||||||
self.stop(Some(last_track.id));
|
self.stop(Some(last_track.id));
|
||||||
self.play_file(path, true);
|
self.play_file(&path, true);
|
||||||
} else {
|
} else {
|
||||||
self.play_file(path, false);
|
self.play_file(&path, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user