From 117beb3dd6b57549a26215d23b48d223161ed9ee Mon Sep 17 00:00:00 2001 From: Jackson Goode Date: Fri, 18 Oct 2024 17:08:55 -0700 Subject: [PATCH] Time --- Cargo.lock | 13 ++++++++++++- psst-core/Cargo.toml | 16 +++++++++++----- psst-core/build.rs | 8 +++++--- psst-gui/src/data/config.rs | 27 +++++++++------------------ psst-gui/src/ui/lyrics.rs | 7 ++++--- 5 files changed, 41 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2456a31b..eaa0c7bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2938,6 +2938,15 @@ dependencies = [ "syn 2.0.77", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "oauth2" version = "4.4.2" @@ -3475,7 +3484,6 @@ dependencies = [ "aes", "audio_thread_priority", "byteorder", - "chrono", "cpal", "crossbeam-channel", "ctr", @@ -3502,6 +3510,7 @@ dependencies = [ "socks", "symphonia", "tempfile", + "time", "ureq", "url", "windows 0.58.0", @@ -4517,7 +4526,9 @@ checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", + "libc", "num-conv", + "num_threads", "powerfmt", "serde", "time-core", diff --git a/psst-core/Cargo.toml b/psst-core/Cargo.toml index 933c82b8..e4cf6917 100644 --- a/psst-core/Cargo.toml +++ b/psst-core/Cargo.toml @@ -6,19 +6,20 @@ edition = "2021" [build-dependencies] -chrono = { version = "0.4.38" } gix-config = { version = "0.40.0" } +time = { version = "0.3.36", features = ["local-offset"] } [dependencies] psst-protocol = { path = "../psst-protocol" } # Common byteorder = { version = "1.5.0" } -git-version = { version = "0.3.9" } crossbeam-channel = { version = "0.5.13" } +git-version = { version = "0.3.9" } log = { version = "0.4.22" } num-bigint = { version = "0.4.6", features = ["rand"] } num-traits = { version = "0.2.19" } +oauth2 = { version = "4.4.2" } once_cell = { version = "1.19.0" } parking_lot = { version = "0.12.3" } quick-protobuf = { version = "0.8.1" } @@ -30,7 +31,6 @@ socks = { version = "0.3.4" } tempfile = { version = "3.12.0" } ureq = { version = "2.10.1", features = ["json"] } url = { version = "2.5.2" } -oauth2 = { version = "4.4.2" } # Cryptography aes = { version = "0.8.4" } @@ -45,7 +45,13 @@ cpal = { version = "0.15.3", optional = true } cubeb = { git = "https://github.com/mozilla/cubeb-rs", optional = true } libsamplerate = { version = "0.1.0" } rb = { version = "0.4.1" } -symphonia = { version = "0.5.4", default-features = false, features = ["ogg", "vorbis", "mp3"]} +symphonia = { version = "0.5.4", default-features = false, features = [ + "ogg", + "vorbis", + "mp3", +] } [target.'cfg(target_os = "windows")'.dependencies] -windows = { version = "0.58.0", features = ["Win32_System_Com"], default-features = false } +windows = { version = "0.58.0", features = [ + "Win32_System_Com", +], default-features = false } diff --git a/psst-core/build.rs b/psst-core/build.rs index cac2c23b..4e899af6 100644 --- a/psst-core/build.rs +++ b/psst-core/build.rs @@ -1,14 +1,16 @@ +use gix_config::File; use std::{env, fs, io::Write}; +use time::OffsetDateTime; fn main() { let outdir = env::var("OUT_DIR").unwrap(); let outfile = format!("{}/build-time.txt", outdir); let mut fh = fs::File::create(outfile).unwrap(); - write!(fh, r#""{}""#, chrono::Local::now()).ok(); + let now = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc()); + write!(fh, r#""{}""#, now).ok(); - let git_config = - gix_config::File::from_git_dir("../.git/".into()).expect("Git Config not found!"); + let git_config = File::from_git_dir("../.git/".into()).expect("Git Config not found!"); // Get Git's 'Origin' URL let mut remote_url = git_config .raw_value("remote.origin.url") diff --git a/psst-gui/src/data/config.rs b/psst-gui/src/data/config.rs index 37f09786..3becbd24 100644 --- a/psst-gui/src/data/config.rs +++ b/psst-gui/src/data/config.rs @@ -8,8 +8,8 @@ use std::{ #[cfg(target_family = "unix")] use std::os::unix::fs::OpenOptionsExt; -use druid::{Data, Lens, Size}; use directories::ProjectDirs; +use druid::{Data, Lens, Size}; use psst_core::{ cache::mkdir_if_not_exists, connection::Credentials, @@ -282,23 +282,14 @@ impl Default for SortCriteria { } } -// Add this function at the end of the file fn get_dir_size(path: &Path) -> Option { - let mut total_size = 0; - if let Ok(entries) = fs::read_dir(path) { - for entry in entries.flatten() { - if let Ok(metadata) = entry.metadata() { - if metadata.is_file() { - total_size += metadata.len(); - } else if metadata.is_dir() { - if let Some(size) = get_dir_size(&entry.path()) { - total_size += size; - } - } - } - } - Some(total_size) + fs::read_dir(path).ok()?.fold(Some(0), |acc, entry| { + let entry = entry.ok()?; + let size = if entry.file_type().ok()?.is_dir() { + get_dir_size(&entry.path())? } else { - None - } + entry.metadata().ok()?.len() + }; + acc.map(|total| total + size) + }) } diff --git a/psst-gui/src/ui/lyrics.rs b/psst-gui/src/ui/lyrics.rs index af48928e..5e0d0ad7 100644 --- a/psst-gui/src/ui/lyrics.rs +++ b/psst-gui/src/ui/lyrics.rs @@ -77,9 +77,10 @@ fn track_lyrics_widget() -> impl Widget { .on_left_click(|ctx, _, c, _| { if c.data.start_time_ms.parse::().unwrap() != 0 { ctx.submit_command( - cmd::SKIP_TO_POSITION.with(c.data.start_time_ms.parse::().unwrap()) + cmd::SKIP_TO_POSITION + .with(c.data.start_time_ms.parse::().unwrap()), ) - } + } }) }) }, @@ -92,4 +93,4 @@ fn track_lyrics_widget() -> impl Widget { |_, data, _| data.lyrics.defer(()), |_, data, r| data.lyrics.update(((), r.1)), ) -} \ No newline at end of file +}