From 07c04577016d2d8f46a70b2932b0ec1e53deec0e Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Thu, 5 Feb 2026 21:02:51 +0100 Subject: [PATCH] Fix Windows Rust still bugging me about variables by using a scope to create the normal_sink --- src/main.rs | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index f28945a..7851ea6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -228,38 +228,31 @@ fn update_ui_scale_factor_system(egui_context: Single<(&mut EguiContextSettings, fn play_sound(file_path: String, app_state: &mut AppState) { let file = File::open(&file_path).unwrap(); let src = Decoder::new(BufReader::new(file)).unwrap(); - let sink = Sink::connect_new(&app_state.sound_system.output_stream.mixer()); let length = src .total_duration() .expect("Could not get source duration") .as_secs_f32(); + let sink = Sink::connect_new(&app_state.sound_system.output_stream.mixer()); sink.append(src); sink.play(); - #[cfg(target_os = "windows")] - { - let file2 = File::open(&file_path).unwrap(); - let src2 = Decoder::new(BufReader::new(file2)).unwrap(); - let normal_sink = Sink::connect_new(&app_state.sound_system.normal_output_stream.mixer()); - normal_sink.append(src2); - - app_state.currently_playing.push(PlayingSound { - file_path: file_path.clone(), - length, - sink, - normal_sink - }); - - return; - } - - app_state.currently_playing.push(PlayingSound { + let playing_sound = PlayingSound { file_path: file_path.clone(), length, sink, - sink // sink twice cuz rust is dumb shit and doesnt understand im already returning - }) + #[cfg(target_os = "windows")] + normal_sink: { + let file2 = File::open(&file_path).unwrap(); + let src2 = Decoder::new(BufReader::new(file2)).unwrap(); + let normal_sink = Sink::connect_new(&app_state.sound_system.normal_output_stream.mixer()); + normal_sink.append(src2); + normal_sink.play(); + normal_sink + } + }; + + app_state.currently_playing.push(playing_sound); } fn ui_system(mut contexts: EguiContexts, mut app_state: ResMut) -> Result {