Skip to content

Commit

Permalink
Replace old deps
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksongoode committed Oct 17, 2024
1 parent b3c56fd commit 7f12f33
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 127 deletions.
145 changes: 45 additions & 100 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions psst-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down Expand Up @@ -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" }
Expand Down
51 changes: 36 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 druid::{Data, Lens, Size};
use platform_dirs::AppDirs;
use directories::ProjectDirs;
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,24 @@ impl Default for SortCriteria {
Self::DateAdded
}
}

// Add this function at the end of the file
fn get_dir_size(path: &Path) -> Option<u64> {
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
}
}
Loading

0 comments on commit 7f12f33

Please sign in to comment.