-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathhelpers.rs
74 lines (60 loc) · 2.1 KB
/
helpers.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use crate::wallpaper::{self, Wallpaper};
use color_eyre::{eyre::Result, Report};
use log::LevelFilter;
use matugen::color::color::Source;
use std::io::Write;
use crate::util::arguments::Cli;
pub fn get_log_level(args: &Cli) -> LevelFilter {
let log_level: LevelFilter = if args.verbose == Some(true) {
LevelFilter::Info
} else if args.quiet == Some(true) {
LevelFilter::Off
} else if args.debug == Some(true) {
LevelFilter::Debug
} else {
LevelFilter::Warn
};
log_level
}
#[cfg(feature = "update-informer")]
pub fn check_version() {
use update_informer::{registry, Check};
let name = env!("CARGO_PKG_NAME");
let current_version = env!("CARGO_PKG_VERSION");
let informer = update_informer::new(registry::Crates, name, current_version);
if let Some(version) = informer.check_version().ok().flatten() {
warn!(
"New version is available: <b><red>{}</> -> <b><green>{}</>",
current_version, version
);
}
}
pub fn setup_logging(args: &Cli) -> Result<(), Report> {
let log_level = get_log_level(args);
let mut logger = pretty_env_logger::env_logger::builder();
logger.filter_level(log_level);
if log_level != LevelFilter::Debug {
logger.format_module_path(false);
logger.format(|buf, record| writeln!(buf, "{}", record.args()));
} else {
// logger.format_timestamp(Some(pretty_env_logger::env_logger::fmt::TimestampPrecision::Nanos));
logger.format_timestamp_micros();
}
logger.try_init()?;
Ok(())
}
pub fn set_wallpaper(source: &Source, _wallpaper_cfg: &Wallpaper) -> Result<(), Report> {
let path = match &source {
Source::Image { path } => path,
Source::Color { .. } => return Ok(()),
#[cfg(feature = "web-image")]
Source::WebImage { .. } => return Ok(()),
};
#[cfg(target_os = "windows")]
wallpaper::windows::set(path)?;
#[cfg(target_os = "macos")]
wallpaper::macos::set(&path)?;
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
wallpaper::unix::set(path, _wallpaper_cfg)?;
Ok(())
}