Skip to content

Commit

Permalink
Reduce & replace old dependencies (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksongoode authored Oct 21, 2024
1 parent b3c56fd commit f619063
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 377 deletions.
599 changes: 269 additions & 330 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions psst-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ 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" }
once_cell = { version = "1.19.0" }
oauth2 = { version = "4.4.2" }
once_cell = { version = "1.20.2" }
parking_lot = { version = "0.12.3" }
quick-protobuf = { version = "0.8.1" }
rand = { version = "0.8.5" }
rangemap = { version = "1.5.1" }
serde = { version = "1.0.209", features = ["derive"] }
serde_json = { version = "1.0.127" }
serde = { version = "1.0.210", features = ["derive"] }
serde_json = { version = "1.0.132" }
socks = { version = "0.3.4" }
tempfile = { version = "3.12.0" }
tempfile = { version = "3.13.0" }
ureq = { version = "2.10.1", features = ["json"] }
url = { version = "2.5.2" }
oauth2 = { version = "4.4.2" }

# Cryptography
aes = { version = "0.8.4" }
Expand All @@ -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 }
8 changes: 5 additions & 3 deletions psst-core/build.rs
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
16 changes: 7 additions & 9 deletions psst-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ 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" }
once_cell = { version = "1.19.0" }
lru = { version = "0.12.5" }
once_cell = { version = "1.20.2" }
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"] }
serde_json = { version = "1.0.127" }
regex = { version = "1.11.0" }
serde = { version = "1.0.210", features = ["derive", "rc"] }
serde_json = { version = "1.0.132" }
threadpool = { version = "1.8.1" }
time = { version = "0.3.36", features = ["macros", "formatting"] }
time-humanize = { version = "0.1.3" }
Expand All @@ -52,11 +51,10 @@ 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" }
image = { version = "0.25.2" }
image = { version = "0.25.4" }

[package.metadata.bundle]
name = "Psst"
Expand Down
42 changes: 27 additions & 15 deletions psst-gui/src/data/config.rs
Original file line number Diff line number Diff line change
@@ -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 directories::ProjectDirs;
use druid::{Data, Lens, Size};
use platform_dirs::AppDirs;
use psst_core::{
cache::mkdir_if_not_exists,
connection::Credentials,
Expand All @@ -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 {
Expand All @@ -33,7 +35,7 @@ impl Preferences {
}

pub fn measure_cache_usage() -> Option<u64> {
Config::cache_dir().and_then(|path| fs_extra::dir::get_size(path).ok())
Config::cache_dir().and_then(|path| get_dir_size(&path))
}
}

Expand Down Expand Up @@ -123,25 +125,23 @@ impl Default for Config {
}

impl Config {
fn app_dirs() -> Option<AppDirs> {
const USE_XDG_ON_MACOS: bool = false;

AppDirs::new(Some(APP_NAME), USE_XDG_ON_MACOS)
fn project_dirs() -> Option<ProjectDirs> {
ProjectDirs::from("", "", APP_NAME)
}

pub fn spotify_local_files_file(username: &str) -> Option<PathBuf> {
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<PathBuf> {
Self::app_dirs().map(|dirs| dirs.cache_dir)
Self::project_dirs().map(|dirs| dirs.cache_dir().to_path_buf())
}

pub fn config_dir() -> Option<PathBuf> {
Self::app_dirs().map(|dirs| dirs.config_dir)
Self::project_dirs().map(|dirs| dirs.config_dir().to_path_buf())
}

fn config_path() -> Option<PathBuf> {
Expand Down Expand Up @@ -281,3 +281,15 @@ impl Default for SortCriteria {
Self::DateAdded
}
}

fn get_dir_size(path: &Path) -> Option<u64> {
fs::read_dir(path).ok()?.try_fold(0, |acc, entry| {
let entry = entry.ok()?;
let size = if entry.file_type().ok()?.is_dir() {
get_dir_size(&entry.path())?
} else {
entry.metadata().ok()?.len()
};
Some(acc + size)
})
}
4 changes: 3 additions & 1 deletion psst-gui/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion psst-gui/src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl AppDelegate<AppState> 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
Expand Down
7 changes: 4 additions & 3 deletions psst-gui/src/ui/lyrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ fn track_lyrics_widget() -> impl Widget<AppState> {
.on_left_click(|ctx, _, c, _| {
if c.data.start_time_ms.parse::<u64>().unwrap() != 0 {
ctx.submit_command(
cmd::SKIP_TO_POSITION.with(c.data.start_time_ms.parse::<u64>().unwrap())
cmd::SKIP_TO_POSITION
.with(c.data.start_time_ms.parse::<u64>().unwrap()),
)
}
}
})
})
},
Expand All @@ -92,4 +93,4 @@ fn track_lyrics_widget() -> impl Widget<AppState> {
|_, data, _| data.lyrics.defer(()),
|_, data, r| data.lyrics.update(((), r.1)),
)
}
}
4 changes: 2 additions & 2 deletions psst-gui/src/ui/preferences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl<W: Widget<AppState>> Controller<AppState, W> 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;
}
Expand Down Expand Up @@ -522,7 +522,7 @@ fn about_tab_widget() -> impl Widget<AppState> {
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();
}),
);

Expand Down
9 changes: 5 additions & 4 deletions psst-gui/src/webapi/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<str>) -> Option<ImageBuf> {
self.images.lock().get_mut(uri).cloned()
self.images.lock().get(uri).cloned()
}

pub fn set_image(&self, uri: Arc<str>, image: ImageBuf) {
self.images.lock().insert(uri, image);
self.images.lock().put(uri, image);
}

pub fn get_image_from_disk(&self, uri: &Arc<str>) -> Option<ImageBuf> {
Expand Down

0 comments on commit f619063

Please sign in to comment.