mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
core API: move now_ms to spirc.rs
This commit is contained in:
parent
55f27a9e0a
commit
77882836ce
2 changed files with 10 additions and 10 deletions
|
@ -8,7 +8,6 @@ use std::ops::{Mul, Rem, Shr};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::time::{UNIX_EPOCH, SystemTime};
|
|
||||||
|
|
||||||
mod int128;
|
mod int128;
|
||||||
mod spotify_id;
|
mod spotify_id;
|
||||||
|
@ -22,14 +21,6 @@ pub fn rand_vec<G: Rng, R: Rand>(rng: &mut G, size: usize) -> Vec<R> {
|
||||||
rng.gen_iter().take(size).collect()
|
rng.gen_iter().take(size).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn now_ms() -> i64 {
|
|
||||||
let dur = match SystemTime::now().duration_since(UNIX_EPOCH) {
|
|
||||||
Ok(dur) => dur,
|
|
||||||
Err(err) => err.duration(),
|
|
||||||
};
|
|
||||||
(dur.as_secs() * 1000 + (dur.subsec_nanos() / 1000_000) as u64) as i64
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mkdir_existing(path: &Path) -> io::Result<()> {
|
pub fn mkdir_existing(path: &Path) -> io::Result<()> {
|
||||||
fs::create_dir(path).or_else(|err| {
|
fs::create_dir(path).or_else(|err| {
|
||||||
if err.kind() == io::ErrorKind::AlreadyExists {
|
if err.kind() == io::ErrorKind::AlreadyExists {
|
||||||
|
|
11
src/spirc.rs
11
src/spirc.rs
|
@ -6,7 +6,7 @@ use protobuf::{self, Message};
|
||||||
use core::config::ConnectConfig;
|
use core::config::ConnectConfig;
|
||||||
use core::mercury::MercuryError;
|
use core::mercury::MercuryError;
|
||||||
use core::session::Session;
|
use core::session::Session;
|
||||||
use core::util::{now_ms, SpotifyId, SeqGenerator};
|
use core::util::{SpotifyId, SeqGenerator};
|
||||||
use core::version;
|
use core::version;
|
||||||
|
|
||||||
use protocol;
|
use protocol;
|
||||||
|
@ -18,6 +18,7 @@ use playback::player::Player;
|
||||||
use std;
|
use std;
|
||||||
use rand;
|
use rand;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
use std::time::{UNIX_EPOCH, SystemTime};
|
||||||
|
|
||||||
pub struct SpircTask {
|
pub struct SpircTask {
|
||||||
player: Player,
|
player: Player,
|
||||||
|
@ -53,6 +54,14 @@ pub struct Spirc {
|
||||||
commands: mpsc::UnboundedSender<SpircCommand>,
|
commands: mpsc::UnboundedSender<SpircCommand>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn now_ms() -> i64 {
|
||||||
|
let dur = match SystemTime::now().duration_since(UNIX_EPOCH) {
|
||||||
|
Ok(dur) => dur,
|
||||||
|
Err(err) => err.duration(),
|
||||||
|
};
|
||||||
|
(dur.as_secs() * 1000 + (dur.subsec_nanos() / 1000_000) as u64) as i64
|
||||||
|
}
|
||||||
|
|
||||||
fn initial_state() -> State {
|
fn initial_state() -> State {
|
||||||
protobuf_init!(protocol::spirc::State::new(), {
|
protobuf_init!(protocol::spirc::State::new(), {
|
||||||
repeat: false,
|
repeat: false,
|
||||||
|
|
Loading…
Reference in a new issue