From 7f12f33fccb76cbf41125104417cb90b3ca78abf Mon Sep 17 00:00:00 2001 From: Jackson Goode Date: Thu, 17 Oct 2024 13:38:21 -0700 Subject: [PATCH] Replace old deps --- Cargo.lock | 145 ++++++++++----------------------- psst-gui/Cargo.toml | 6 +- psst-gui/src/data/config.rs | 51 ++++++++---- psst-gui/src/data/mod.rs | 4 +- psst-gui/src/delegate.rs | 2 +- psst-gui/src/ui/preferences.rs | 4 +- psst-gui/src/webapi/cache.rs | 9 +- 7 files changed, 94 insertions(+), 127 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ef92630..2456a31b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,6 +49,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + [[package]] name = "alsa" version = "0.9.1" @@ -513,15 +519,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "block2" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" -dependencies = [ - "objc2", -] - [[package]] name = "blocking" version = "1.6.1" @@ -1011,24 +1008,24 @@ dependencies = [ ] [[package]] -name = "dirs-next" -version = "1.0.2" +name = "directories" +version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf36e65a80337bea855cd4ef9b8401ffce06a7baedf2e85ec467b1ac3f6e82b6" +checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35" dependencies = [ - "cfg-if", - "dirs-sys-next", + "dirs-sys", ] [[package]] -name = "dirs-sys-next" -version = "0.1.2" +name = "dirs-sys" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" dependencies = [ "libc", + "option-ext", "redox_users", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -1365,6 +1362,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -1389,12 +1392,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fs_extra" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" - [[package]] name = "futf" version = "0.1.5" @@ -2033,6 +2030,17 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + [[package]] name = "heck" version = "0.3.3" @@ -2290,7 +2298,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", ] [[package]] @@ -2573,12 +2581,6 @@ dependencies = [ "libc", ] -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - [[package]] name = "linux-raw-sys" version = "0.3.8" @@ -2617,12 +2619,12 @@ dependencies = [ ] [[package]] -name = "lru-cache" -version = "0.1.2" +name = "lru" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "linked-hash-map", + "hashbrown 0.15.0", ] [[package]] @@ -2965,40 +2967,6 @@ dependencies = [ "malloc_buf", ] -[[package]] -name = "objc-sys" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb91bdd390c7ce1a8607f35f3ca7151b65afc0ff5ff3b34fa350f7d7c7e4310" - -[[package]] -name = "objc2" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a785d4eeff09c14c487497c162e92766fbb3e4059a71840cecc03d9a50b804" -dependencies = [ - "objc-sys", - "objc2-encode", -] - -[[package]] -name = "objc2-encode" -version = "4.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7891e71393cd1f227313c9379a26a584ff3d7e6e7159e988851f0934c993f0f8" - -[[package]] -name = "objc2-foundation" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" -dependencies = [ - "bitflags 2.6.0", - "block2", - "libc", - "objc2", -] - [[package]] name = "object" version = "0.36.4" @@ -3048,6 +3016,12 @@ dependencies = [ "pathdiff", ] +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "ordered-stream" version = "0.2.0" @@ -3337,15 +3311,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" -[[package]] -name = "platform-dirs" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e188d043c1a692985f78b5464853a263f1a27e5bd6322bad3a4078ee3c998a38" -dependencies = [ - "dirs-next", -] - [[package]] name = "png" version = "0.17.13" @@ -3547,19 +3512,18 @@ name = "psst-gui" version = "0.1.0" dependencies = [ "crossbeam-channel", + "directories", "druid", "druid-enums", "druid-shell", "env_logger", - "fs_extra", "image 0.25.2", "itertools 0.13.0", "log", - "lru-cache", + "lru", "once_cell", "open", "parking_lot", - "platform-dirs", "psst-core", "rand", "raw-window-handle", @@ -3573,7 +3537,6 @@ dependencies = [ "time-humanize", "ureq", "url", - "webbrowser", "winres", ] @@ -5079,24 +5042,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webbrowser" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "425ba64c1e13b1c6e8c5d2541c8fac10022ca584f33da781db01b5756aef1f4e" -dependencies = [ - "block2", - "core-foundation", - "home", - "jni", - "log", - "ndk-context", - "objc2", - "objc2-foundation", - "url", - "web-sys", -] - [[package]] name = "webpki-roots" version = "0.25.4" diff --git a/psst-gui/Cargo.toml b/psst-gui/Cargo.toml index 3a1f52d2..8ff4de5e 100644 --- a/psst-gui/Cargo.toml +++ b/psst-gui/Cargo.toml @@ -17,14 +17,13 @@ psst-core = { path = "../psst-core" } # Common crossbeam-channel = { version = "0.5.13" } +directories = { version = "5.0.1" } env_logger = { version = "0.11.5" } -fs_extra = { version = "1.3.0" } itertools = { version = "0.13.0" } log = { version = "0.4.22" } -lru-cache = { version = "0.1.2" } +lru = { version = "0.12.5" } once_cell = { version = "1.19.0" } parking_lot = { version = "0.12.3" } -platform-dirs = { version = "0.3.0" } rand = { version = "0.8.5" } regex = { version = "1.10.6" } serde = { version = "1.0.209", features = ["derive", "rc"] } @@ -52,7 +51,6 @@ raw-window-handle = { version = "0.5.2" } # Must stay compatible with Druid souvlaki = { version = "0.7.3", default-features = false, features = [ "use_zbus", ] } -webbrowser = { version = "1.0.1" } sanitize_html = "0.8.1" [target.'cfg(windows)'.build-dependencies] winres = { version = "0.1.12" } diff --git a/psst-gui/src/data/config.rs b/psst-gui/src/data/config.rs index cbb897f4..37f09786 100644 --- a/psst-gui/src/data/config.rs +++ b/psst-gui/src/data/config.rs @@ -1,12 +1,15 @@ -use std::io::{BufReader, BufWriter}; -use std::{env, env::VarError, fs::File, path::PathBuf}; +use std::{ + env::{self, VarError}, + fs::{self, File, OpenOptions}, + io::{BufReader, BufWriter}, + path::{Path, PathBuf}, +}; -use std::fs::OpenOptions; #[cfg(target_family = "unix")] use std::os::unix::fs::OpenOptionsExt; use druid::{Data, Lens, Size}; -use platform_dirs::AppDirs; +use directories::ProjectDirs; use psst_core::{ cache::mkdir_if_not_exists, connection::Credentials, @@ -15,9 +18,8 @@ use psst_core::{ }; use serde::{Deserialize, Serialize}; -use crate::ui::theme; - use super::{Nav, Promise, QueueBehavior, SliderScrollScale}; +use crate::ui::theme; #[derive(Clone, Debug, Data, Lens)] pub struct Preferences { @@ -33,7 +35,7 @@ impl Preferences { } pub fn measure_cache_usage() -> Option { - Config::cache_dir().and_then(|path| fs_extra::dir::get_size(path).ok()) + Config::cache_dir().and_then(|path| get_dir_size(&path)) } } @@ -123,25 +125,23 @@ impl Default for Config { } impl Config { - fn app_dirs() -> Option { - const USE_XDG_ON_MACOS: bool = false; - - AppDirs::new(Some(APP_NAME), USE_XDG_ON_MACOS) + fn project_dirs() -> Option { + ProjectDirs::from("", "", APP_NAME) } pub fn spotify_local_files_file(username: &str) -> Option { - AppDirs::new(Some("spotify"), false).map(|dir| { + ProjectDirs::from("", "", "spotify").map(|dirs| { let path = format!("Users/{}-user/local-files.bnk", username); - dir.config_dir.join(path) + dirs.config_dir().join(path) }) } pub fn cache_dir() -> Option { - Self::app_dirs().map(|dirs| dirs.cache_dir) + Self::project_dirs().map(|dirs| dirs.cache_dir().to_path_buf()) } pub fn config_dir() -> Option { - Self::app_dirs().map(|dirs| dirs.config_dir) + Self::project_dirs().map(|dirs| dirs.config_dir().to_path_buf()) } fn config_path() -> Option { @@ -281,3 +281,24 @@ impl Default for SortCriteria { Self::DateAdded } } + +// 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) + } else { + None + } +} diff --git a/psst-gui/src/data/mod.rs b/psst-gui/src/data/mod.rs index 16c3e7ea..45da6743 100644 --- a/psst-gui/src/data/mod.rs +++ b/psst-gui/src/data/mod.rs @@ -34,7 +34,9 @@ use psst_core::{item_id::ItemId, session::SessionService}; pub use crate::data::{ album::{Album, AlbumDetail, AlbumLink, AlbumType}, - artist::{Artist, ArtistAlbums, ArtistInfo, ArtistStats, ArtistDetail, ArtistLink, ArtistTracks}, + artist::{ + Artist, ArtistAlbums, ArtistDetail, ArtistInfo, ArtistLink, ArtistStats, ArtistTracks, + }, config::{AudioQuality, Authentication, Config, Preferences, PreferencesTab, Theme}, ctx::Ctx, find::{FindQuery, Finder, MatchFindQuery}, diff --git a/psst-gui/src/delegate.rs b/psst-gui/src/delegate.rs index 96fe24ed..743ecd23 100644 --- a/psst-gui/src/delegate.rs +++ b/psst-gui/src/delegate.rs @@ -130,7 +130,7 @@ impl AppDelegate for Delegate { Application::global().clipboard().put_string(text); Handled::Yes } else if let Some(text) = cmd.get(cmd::GO_TO_URL) { - let _ = webbrowser::open(text); + let _ = open::that(text); Handled::Yes } else if let Handled::Yes = self.command_image(ctx, target, cmd, data) { Handled::Yes diff --git a/psst-gui/src/ui/preferences.rs b/psst-gui/src/ui/preferences.rs index d9c5d403..b6b103d7 100644 --- a/psst-gui/src/ui/preferences.rs +++ b/psst-gui/src/ui/preferences.rs @@ -332,7 +332,7 @@ impl> Controller for Authenticate { data.preferences.auth.result.defer_default(); let (auth_url, pkce_verifier) = oauth::generate_auth_url(8888); - if webbrowser::open(&auth_url).is_err() { + if open::that(&auth_url).is_err() { data.error_alert("Failed to open browser"); return; } @@ -522,7 +522,7 @@ fn about_tab_widget() -> impl Widget { Label::new(psst_core::REMOTE_URL) .with_text_color(Color::rgb8(138, 180, 248)) .on_left_click(|_, _, _, _| { - webbrowser::open(psst_core::REMOTE_URL).ok(); + open::that(psst_core::REMOTE_URL).ok(); }), ); diff --git a/psst-gui/src/webapi/cache.rs b/psst-gui/src/webapi/cache.rs index 26191e8f..db83fac5 100644 --- a/psst-gui/src/webapi/cache.rs +++ b/psst-gui/src/webapi/cache.rs @@ -2,13 +2,14 @@ use std::{ collections::hash_map::DefaultHasher, fs::{self, File}, hash::{Hash, Hasher}, + num::NonZeroUsize, path::PathBuf, sync::Arc, }; use druid::image; use druid::ImageBuf; -use lru_cache::LruCache; +use lru::LruCache; use parking_lot::Mutex; use psst_core::cache::mkdir_if_not_exists; @@ -22,16 +23,16 @@ impl WebApiCache { const IMAGE_CACHE_SIZE: usize = 256; Self { base, - images: Mutex::new(LruCache::new(IMAGE_CACHE_SIZE)), + images: Mutex::new(LruCache::new(NonZeroUsize::new(IMAGE_CACHE_SIZE).unwrap())), } } pub fn get_image(&self, uri: &Arc) -> Option { - self.images.lock().get_mut(uri).cloned() + self.images.lock().get(uri).cloned() } pub fn set_image(&self, uri: Arc, image: ImageBuf) { - self.images.lock().insert(uri, image); + self.images.lock().put(uri, image); } pub fn get_image_from_disk(&self, uri: &Arc) -> Option {