A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
1
use serde::Deserialize;2
use std::fmt::Write;3
use std::fs;4
use std::path::Path;5
use std::path::PathBuf;7
use crate::error::Error;8
use crate::Result;
74
impl Config {75
pub fn acquire() -> Result<Self> {74
let mut config_path = match dirs::config_dir() {75
Some(config_path) => config_path,76
None => return Err(Error::new("unable to determine config path!")),76
let mut config_file = Self::get_global();77
let local_file = Self::get_local();78
if local_file.is_some() {79
config_file = local_file;80
}81
match config_file {82
Some(file) => {83
let raw = fs::read_to_string(&file)?;84
let config: Self = toml::from_str(&raw)?;85
Ok(config)86
}87
None => Err(Error::new("unable to determine config file!")),88
}89
}90
fn get_local() -> Option<PathBuf> {91
let local_file = Path::new("config.toml").to_path_buf();92
if !local_file.exists() {93
return None;94
}95
Some(local_file)96
}97
fn get_global() -> Option<PathBuf> {98
let mut global_file = match dirs::config_dir() {99
Some(file) => file,100
None => return None,101
};78
config_path.push(APP_NAME);79
config_path.push("config.toml");80
let raw = fs::read_to_string(&config_path)?;81
let config: Self = toml::from_str(&raw)?;82
Ok(config)102
global_file.push(APP_NAME);103
global_file.push("config.toml");104
if !global_file.exists() {105
return None;106
}107
Some(global_file)108
}109
}
10
<title>Verbal</title>11
<link rel="manifest" href="/manifest.json">12
<link rel="icon" type="image/png" href="/asset/img/favicon.png">13
<link rel="apple-touch-icon" href="/asset/img/icon-192x192.png">14
<link rel="stylesheet" href="/asset/css/style.css">15
<link rel="stylesheet" href="/asset/css/output.css">16
<link rel="stylesheet" href="/asset/lib/tabler-icons.min.css">
5
{6
"src": "/asset/img/icon-192x192.png",7
"sizes": "192x192",8
"type": "image/png"8
"type": "image/png",9
"purpose": "maskable"10
},11
{12
"src": "/asset/img/icon-512x512.png",13
"sizes": "512x512",13
"type": "image/png"14
"type": "image/png",15
"purpose": "maskable"16
}17
],18
"id": "/",