Downloading prototype works
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
use std::{path::PathBuf, sync::{Arc, Mutex, MutexGuard}};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use theme::Theme;
|
||||
use tooling::Tooling;
|
||||
|
||||
pub mod theme;
|
||||
pub mod tooling;
|
||||
|
||||
lazy_static::lazy_static!(
|
||||
static ref SETTINGS: Arc<Mutex<Settings>> = Arc::new(Mutex::new(Settings::default()));
|
||||
@@ -14,7 +16,10 @@ pub type Result<T> = anyhow::Result<T>;
|
||||
pub struct Settings {
|
||||
#[serde(skip)]
|
||||
settings_path: PathBuf,
|
||||
#[serde(default)]
|
||||
pub theme: Theme,
|
||||
#[serde(default)]
|
||||
pub tooling: Tooling,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
@@ -27,6 +32,11 @@ impl Settings {
|
||||
pub fn load(&mut self, path: Option<PathBuf>) -> Result<()> {
|
||||
let path = path.unwrap_or(self.settings_path.clone());
|
||||
if !path.exists() {
|
||||
let mut dir = path.clone();
|
||||
dir.pop();
|
||||
if !dir.exists() {
|
||||
std::fs::create_dir_all(dir)?;
|
||||
}
|
||||
std::fs::write(&path, "[theme]")?;
|
||||
self.save(Some(path.clone()))?;
|
||||
}
|
||||
|
||||
42
xmpd-settings/src/tooling.rs
Normal file
42
xmpd-settings/src/tooling.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Tooling {
|
||||
#[serde(default="Tooling::default_ytdlp_path")]
|
||||
pub ytdlp_path: camino::Utf8PathBuf,
|
||||
#[serde(default="Tooling::default_spotdl_path")]
|
||||
pub spotdl_path: camino::Utf8PathBuf,
|
||||
#[serde(default="Tooling::default_ffmpeg_path")]
|
||||
pub ffmpeg_path: camino::Utf8PathBuf,
|
||||
#[serde(default="Tooling::default_song_format")]
|
||||
pub song_format: String,
|
||||
}
|
||||
|
||||
impl Default for Tooling {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
ytdlp_path: Self::default_ytdlp_path(),
|
||||
spotdl_path: Self::default_spotdl_path(),
|
||||
ffmpeg_path: Self::default_ffmpeg_path(),
|
||||
song_format: Self::default_song_format(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Tooling {
|
||||
fn default_ytdlp_path() -> camino::Utf8PathBuf {
|
||||
camino::Utf8PathBuf::from_str("yt-dlp").unwrap()
|
||||
}
|
||||
fn default_spotdl_path() -> camino::Utf8PathBuf {
|
||||
camino::Utf8PathBuf::from_str("spotdl").unwrap()
|
||||
}
|
||||
fn default_ffmpeg_path() -> camino::Utf8PathBuf {
|
||||
camino::Utf8PathBuf::from_str("ffmpeg").unwrap()
|
||||
}
|
||||
fn default_song_format() -> String {
|
||||
String::from("flac")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user