Use proper config directory
This commit is contained in:
parent
4fbeccdde1
commit
553f34a111
|
|
@ -377,6 +377,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"crabidy-core",
|
"crabidy-core",
|
||||||
|
"dirs",
|
||||||
"flume",
|
"flume",
|
||||||
"futures",
|
"futures",
|
||||||
"gstreamer",
|
"gstreamer",
|
||||||
|
|
@ -461,6 +462,15 @@ dependencies = [
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs"
|
||||||
|
version = "5.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
|
||||||
|
dependencies = [
|
||||||
|
"dirs-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs-next"
|
name = "dirs-next"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
|
|
@ -471,6 +481,18 @@ dependencies = [
|
||||||
"dirs-sys-next",
|
"dirs-sys-next",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs-sys"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"option-ext",
|
||||||
|
"redox_users",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs-sys-next"
|
name = "dirs-sys-next"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
|
@ -1453,6 +1475,12 @@ version = "1.17.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "option-ext"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "option-operations"
|
name = "option-operations"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ pub trait ProviderClient: std::fmt::Debug + Send + Sync {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Hash)]
|
#[derive(Clone, Debug, Hash)]
|
||||||
pub enum ProviderError {
|
pub enum ProviderError {
|
||||||
|
Config(String),
|
||||||
UnknownUser,
|
UnknownUser,
|
||||||
CouldNotLogin,
|
CouldNotLogin,
|
||||||
FetchError,
|
FetchError,
|
||||||
|
|
|
||||||
|
|
@ -20,3 +20,4 @@ tonic = "0.9.2"
|
||||||
async-trait = "0.1.68"
|
async-trait = "0.1.68"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
tokio-stream = { version = "0.1.14", features = ["sync"] }
|
tokio-stream = { version = "0.1.14", features = ["sync"] }
|
||||||
|
dirs = "5.0.1"
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ use tokio_stream::StreamExt;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
|
path::PathBuf,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
@ -149,10 +150,24 @@ impl ProviderOrchestrator {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ProviderClient for ProviderOrchestrator {
|
impl ProviderClient for ProviderOrchestrator {
|
||||||
async fn init(_s: &str) -> Result<Self, ProviderError> {
|
async fn init(_s: &str) -> Result<Self, ProviderError> {
|
||||||
let raw_toml_settings = fs::read_to_string("/tmp/tidaldy.toml").unwrap_or("".to_owned());
|
let config_dir = dirs::config_dir()
|
||||||
|
.map(|d| d.join("crabidy"))
|
||||||
|
.unwrap_or(PathBuf::from("/tmp"));
|
||||||
|
let dir_exists = tokio::fs::try_exists(&config_dir)
|
||||||
|
.await
|
||||||
|
.map_err(|e| ProviderError::Config(e.to_string()))?;
|
||||||
|
if !dir_exists {
|
||||||
|
tokio::fs::create_dir(&config_dir)
|
||||||
|
.await
|
||||||
|
.map_err(|e| ProviderError::Config(e.to_string()))?;
|
||||||
|
}
|
||||||
|
let config_file = config_dir.join("tidaly.toml");
|
||||||
|
let raw_toml_settings = fs::read_to_string(&config_file).unwrap_or("".to_owned());
|
||||||
let tidal_client = Arc::new(tidaldy::Client::init(&raw_toml_settings).await.unwrap());
|
let tidal_client = Arc::new(tidaldy::Client::init(&raw_toml_settings).await.unwrap());
|
||||||
let new_toml_config = tidal_client.settings();
|
let new_toml_config = tidal_client.settings();
|
||||||
fs::write("/tmp/tidaldy.toml", new_toml_config).unwrap();
|
tokio::fs::write(&config_file, new_toml_config)
|
||||||
|
.await
|
||||||
|
.map_err(|e| ProviderError::Config(e.to_string()));
|
||||||
let (provider_tx, provider_rx) = flume::bounded(100);
|
let (provider_tx, provider_rx) = flume::bounded(100);
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
provider_rx,
|
provider_rx,
|
||||||
|
|
@ -291,12 +306,12 @@ impl Playback {
|
||||||
duration: self
|
duration: self
|
||||||
.play
|
.play
|
||||||
.duration()
|
.duration()
|
||||||
.and_then(|t| Some(t.mseconds() as u32))
|
.map(|t| t.mseconds() as u32)
|
||||||
.unwrap_or(0),
|
.unwrap_or(0),
|
||||||
position: self
|
position: self
|
||||||
.play
|
.play
|
||||||
.position()
|
.position()
|
||||||
.and_then(|t| Some(t.mseconds() as u32))
|
.map(|t| t.mseconds() as u32)
|
||||||
.unwrap_or(0),
|
.unwrap_or(0),
|
||||||
};
|
};
|
||||||
let play_state = match *self.state.lock().unwrap() {
|
let play_state = match *self.state.lock().unwrap() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue