Skip to content

Commit d0da5bb

Browse files
committed
Update dependencies and fix audio not working
1 parent 84d0e9c commit d0da5bb

File tree

3 files changed

+48
-52
lines changed

3 files changed

+48
-52
lines changed

Cargo.toml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@ iced = { version = "0.14", default-features = false, features = ["svg", "tokio",
1111
iced_aw = { version = "0.13", default-features = false, features = ["tabs"] }
1212
iced_drop = {git = "https://github.com/pml68/iced_drop.git", branch="0.14"}
1313

14-
rand = "0.8.5"
15-
chrono = "0.4.41"
14+
rand = "0.9.2"
15+
chrono = "0.4.42"
1616
chess = "3.2.0"
17-
csv = "1.3.1"
18-
serde = "1.0.217"
19-
serde_derive = "1.0.217"
20-
serde_json = "1.0.135"
21-
tokio = { version = "1.43.0", features = ["process", "io-std", "io-util", "sync"] }
22-
reqwest = "0.12.12"
23-
zstd = "0.13.2"
24-
rodio = { version = "0.20.1", default-features = false, features = ["vorbis"] }
25-
fluent-bundle = "0.15.3"
26-
intl-memoizer = "0.5.2"
27-
once_cell = "1.20.2"
28-
unic-langid = { version = "0.9.5", features = ["macros"] }
29-
diesel = { version = "2.2.6", features = ["sqlite"] }
17+
csv = "1.4.0"
18+
serde = "1.0.228"
19+
serde_derive = "1.0.228"
20+
serde_json = "1.0.149"
21+
tokio = { version = "1.49.0", features = ["process", "io-std", "io-util", "sync"] }
22+
reqwest = "0.13.1"
23+
zstd = "0.13.3"
24+
rodio = { version = "0.21.1", default-features = false, features = ["playback", "symphonia-all"] }
25+
fluent-bundle = "0.16.0"
26+
intl-memoizer = "0.5.3"
27+
once_cell = "1.21.3"
28+
unic-langid = { version = "0.9.6", features = ["macros"] }
29+
diesel = { version = "2.3.5", features = ["sqlite"] }
3030
dotenvy = "0.15.7"
31-
lopdf = "0.34.0"
32-
open = "5.3.2"
31+
lopdf = "0.38.0"
32+
open = "5.3.3"
3333
#rfd = { version = "0.13.0", default-features = false, features = ["xdg-portal", "tokio"] }
34-
rfd = "0.15.2"
35-
image = { version = "0.25.5", default-features = false, features = ["jpeg"] }
34+
rfd = "0.17.1"
35+
image = { version = "0.25.9", default-features = false, features = ["jpeg"] }
3636

3737
[target.'cfg(windows)'.dependencies]
38-
libsqlite3-sys = { version = "0.30.1", features = ["bundled"] }
38+
libsqlite3-sys = { version = "0.35.0", features = ["bundled"] }

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub const TRANSLATIONS_DIRECTORY: &str = "./translations/";
1919
pub const PIECES_DIRECTORY: &str = "pieces/";
2020
pub const SETTINGS_FILE: &str = "settings.json";
2121
pub const ONE_PIECE_SOUND_FILE: &str = "1piece.ogg";
22-
pub const TWO_PIECES_SOUND_FILE: &str = "2piece.ogg";
22+
pub const TWO_PIECES_SOUND_FILE: &str = "2pieces.ogg";
2323

2424
// Iced widget IDs need to be static
2525
pub static BTN_IDS: [&'static str; 64] = [

src/main.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use download_db::download_lichess_db;
44
use eval::{Engine, EngineStatus};
5-
use iced::widget::Id;
65
use iced::advanced::widget::Id as GenericId;
76
use iced::widget::svg::Handle;
87
use iced::widget::text::LineHeight;
@@ -25,10 +24,9 @@ use rfd::AsyncFileDialog;
2524
use iced_aw::{TabLabel, Tabs};
2625
use chess::{Board, BoardStatus, ChessMove, Color, File, Game, Piece, Rank, Square, ALL_SQUARES};
2726

28-
use rodio::{Decoder, OutputStream, OutputStreamHandle};
29-
use rodio::source::{Source, Buffered};
27+
use rodio::{OutputStream, OutputStreamBuilder};
3028

31-
use rand::thread_rng;
29+
use rand::rng;
3230
use rand::seq::SliceRandom;
3331

3432
mod config;
@@ -128,43 +126,41 @@ pub enum Message {
128126
}
129127

130128
struct SoundPlayback {
131-
// it's not directly used, but we need to keep it: https://github.com/RustAudio/rodio/issues/330
132-
stream: OutputStream,
133-
handle: OutputStreamHandle,
134-
one_piece_sound: Buffered<Decoder<BufReader<StdFile>>>,
135-
two_pieces_sound: Buffered<Decoder<BufReader<StdFile>>>,
129+
handle: OutputStream,
136130
}
137131

138132
impl SoundPlayback {
139133
pub const ONE_PIECE_SOUND: u8 = 0;
140134
pub const TWO_PIECE_SOUND: u8 = 1;
141135
pub fn init_sound() -> Option<Self> {
142136
let mut sound_playback = None;
143-
if let Ok((stream, handle)) = OutputStream::try_default() {
144-
let one_pieces_sound = StdFile::open(ONE_PIECE_SOUND_FILE);
145-
let two_pieces_sound = StdFile::open(TWO_PIECES_SOUND_FILE);
146-
147-
if let (Ok(one_piece), Ok(two_piece)) = (one_pieces_sound, two_pieces_sound) {
148-
sound_playback = Some(
149-
SoundPlayback {
150-
stream: stream,
151-
handle: handle,
152-
one_piece_sound: Decoder::new(BufReader::new(one_piece)).unwrap().buffered(),
153-
two_pieces_sound: Decoder::new(BufReader::new(two_piece)).unwrap().buffered()
154-
}
155-
);
156-
}
157-
}
137+
if let Ok(handle) = OutputStreamBuilder::open_default_stream() {
138+
sound_playback = Some (
139+
SoundPlayback {
140+
handle: handle,
141+
});
142+
}
158143
sound_playback
159144
}
160145
pub fn play_audio(&self, audio: u8) {
161-
let audio = match audio {
162-
SoundPlayback::ONE_PIECE_SOUND => self.one_piece_sound.clone(),
163-
_ => self.two_pieces_sound.clone(),
146+
let sink = match audio {
147+
SoundPlayback::ONE_PIECE_SOUND => {
148+
rodio::play(
149+
&self.handle.mixer(),
150+
BufReader::new(
151+
StdFile::open(ONE_PIECE_SOUND_FILE).unwrap()
152+
)).unwrap()
153+
},
154+
_ => {
155+
rodio::play(
156+
&self.handle.mixer(),
157+
BufReader::new(
158+
StdFile::open(TWO_PIECES_SOUND_FILE).unwrap()
159+
)).unwrap()
160+
},
164161
};
165-
if let Err(e) = self.handle.play_raw(audio.convert_samples()) {
166-
eprintln!("{e}");
167-
}
162+
sink.play();
163+
sink.detach();
168164
}
169165
}
170166

@@ -597,7 +593,7 @@ impl OfflinePuzzles {
597593
if let Some(puzzles_vec) = puzzles_vec {
598594
if !puzzles_vec.is_empty() {
599595
self.puzzle_tab.puzzles = puzzles_vec;
600-
self.puzzle_tab.puzzles.shuffle(&mut thread_rng());
596+
self.puzzle_tab.puzzles.shuffle(&mut rng());
601597
self.puzzle_tab.current_puzzle = 0;
602598
self.puzzle_number_ui = String::from("1");
603599
self.load_puzzle(false);

0 commit comments

Comments
 (0)