diff --git a/connect/src/spirc.rs b/connect/src/spirc.rs index 5e3ba38..352a3fc 100644 --- a/connect/src/spirc.rs +++ b/connect/src/spirc.rs @@ -21,7 +21,6 @@ use librespot_core::spotify_id::{SpotifyAudioType, SpotifyId, SpotifyIdError}; use librespot_core::util::url_encode; use librespot_core::util::SeqGenerator; use librespot_core::version; -use librespot_core::volume::Volume; enum SpircPlayStatus { Stopped, @@ -1297,7 +1296,7 @@ impl SpircTask { self.mixer .set_volume(volume_to_mixer(volume, &self.config.volume_ctrl)); if let Some(cache) = self.session.cache() { - cache.save_volume(Volume { volume }) + cache.save_volume(volume) } self.player.emit_volume_set_event(volume); } diff --git a/core/src/cache.rs b/core/src/cache.rs index 76d49fa..018c4c2 100644 --- a/core/src/cache.rs +++ b/core/src/cache.rs @@ -5,7 +5,6 @@ use std::path::{Path, PathBuf}; use crate::authentication::Credentials; use crate::spotify_id::FileId; -use crate::volume::Volume; /// A cache for volume, credentials and audio files. #[derive(Clone)] @@ -80,7 +79,7 @@ impl Cache { } } - pub fn volume(&self) -> Option { + pub fn volume(&self) -> Option { let location = self.volume_location.as_ref()?; let read = || { @@ -103,7 +102,7 @@ impl Cache { } } - pub fn save_volume(&self, volume: Volume) { + pub fn save_volume(&self, volume: u16) { if let Some(ref location) = self.volume_location { let result = File::create(location).and_then(|mut file| write!(file, "{}", volume)); if let Err(e) = result { diff --git a/core/src/lib.rs b/core/src/lib.rs index c65878c..a00d30b 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -54,4 +54,3 @@ pub mod session; pub mod spotify_id; pub mod util; pub mod version; -pub mod volume; diff --git a/core/src/volume.rs b/core/src/volume.rs deleted file mode 100644 index 6b456d1..0000000 --- a/core/src/volume.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::fs::File; -use std::io::{Read, Write}; -use std::path::Path; - -#[derive(Clone, Copy, Debug)] -pub struct Volume { - pub volume: u16, -} - -impl Volume { - // read volume from file - fn from_reader(mut reader: R) -> u16 { - let mut contents = String::new(); - reader.read_to_string(&mut contents).unwrap(); - contents.trim().parse::().unwrap() - } - - pub(crate) fn from_file>(path: P) -> Option { - File::open(path).ok().map(Volume::from_reader) - } - - // write volume to file - fn save_to_writer(&self, writer: &mut W) { - writer - .write_all(self.volume.to_string().as_bytes()) - .unwrap(); - } - - pub(crate) fn save_to_file>(&self, path: P) { - let mut file = File::create(path).unwrap(); - self.save_to_writer(&mut file) - } -} diff --git a/src/main.rs b/src/main.rs index b22d7d5..f900f68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -292,9 +292,8 @@ fn setup(args: &[String]) -> Setup { } (volume as i32 * 0xFFFF / 100) as u16 }) - .map(Volume) .or_else(|| cache.as_ref().and_then(Cache::volume)) - .unwrap_or(Volume(0x8000)); + .unwrap_or(0x8000); let zeroconf_port = matches .opt_str("zeroconf-port")