use std::env;
use std::path::PathBuf;
pub fn preferences() -> Option<PathBuf> {
env::var("alfred_preferences").ok().map(PathBuf::from)
}
pub fn local_preferences() -> Option<PathBuf> {
match (preferences(),env::var("alfred_preferences_localhash")) {
(Some(mut prefs),Ok(hash)) => {
prefs.extend(["preferences","local",&hash].iter());
Some(prefs)
}
_ => None
}
}
pub fn theme() -> Option<String> {
env::var("alfred_theme").ok()
}
pub fn theme_background_str() -> Option<String> {
env::var("alfred_theme_background").ok()
}
pub fn theme_selection_background_str() -> Option<String> {
env::var("alfred_theme_selection_background").ok()
}
#[derive(Copy,Clone,Debug,PartialEq,Eq,Hash)]
pub enum Subtext {
Always,
AlternativeActions,
SelectedResult,
Never
}
pub fn theme_subtext() -> Option<Subtext> {
match env::var("alfred_theme_subtext").as_ref().map(|s| s.as_ref()) {
Ok("0") => Some(Subtext::Always),
Ok("1") => Some(Subtext::AlternativeActions),
Ok("2") => Some(Subtext::SelectedResult),
Ok("3") => Some(Subtext::Never),
_ => None
}
}
pub fn version() -> Option<String> {
env::var("alfred_version").ok()
}
pub fn version_build() -> Option<i32> {
env::var("alfred_version_build").ok().and_then(|s| s.parse().ok())
}
pub fn workflow_bundle_id() -> Option<String> {
env::var("alfred_workflow_bundleid").ok()
}
pub fn workflow_cache() -> Option<PathBuf> {
env::var("alfred_workflow_cache").ok().map(PathBuf::from)
}
pub fn workflow_data() -> Option<PathBuf> {
env::var("alfred_workflow_data").ok().map(PathBuf::from)
}
pub fn workflow_name() -> Option<String> {
env::var("alfred_workflow_name").ok()
}
pub fn workflow_uid() -> Option<String> {
env::var("alfred_workflow_uid").ok()
}
pub fn workflow_version() -> Option<String> {
env::var("alfred_workflow_version").ok()
}
pub fn is_debug() -> bool {
match env::var("alfred_debug") {
Ok(val) => val == "1",
_ => false
}
}