start working on messenger
This commit is contained in:
parent
c7aec5b594
commit
13551a0237
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@
|
|||||||
# exclude binarys in examples folder
|
# exclude binarys in examples folder
|
||||||
/examples/*
|
/examples/*
|
||||||
!/examples/*.rs
|
!/examples/*.rs
|
||||||
|
*.log
|
||||||
|
36
Cargo.lock
generated
36
Cargo.lock
generated
@ -61,9 +61,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "3.0.14"
|
version = "3.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b63edc3f163b3c71ec8aa23f9bd6070f77edbf3d1d198b164afa90ff00e4ec62"
|
checksum = "6d76c22c9b9b215eeb8d016ad3a90417bd13cb24cf8142756e6472445876cab7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atty",
|
"atty",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
@ -78,9 +78,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_derive"
|
name = "clap_derive"
|
||||||
version = "3.0.14"
|
version = "3.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9a1132dc3944b31c20dd8b906b3a9f0a5d0243e092d59171414969657ac6aa85"
|
checksum = "5fd1122e63869df2cb309f449da1ad54a7c6dfeb7c7e6ccd8e0825d9eb93bb72"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"proc-macro-error",
|
"proc-macro-error",
|
||||||
@ -96,12 +96,14 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"ffprobe",
|
"ffprobe",
|
||||||
|
"log",
|
||||||
"notify",
|
"notify",
|
||||||
"rand",
|
"rand",
|
||||||
"regex",
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
|
"simplelog",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -164,9 +166,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.4"
|
version = "0.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
|
checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"libc",
|
"libc",
|
||||||
@ -263,9 +265,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.117"
|
version = "0.2.119"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c"
|
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linked-hash-map"
|
name = "linked-hash-map"
|
||||||
@ -388,6 +390,12 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "paris"
|
||||||
|
version = "1.5.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c69d19a208bba8b94bd27d4b7a06ad153cddc6b88cb2149a668e23ce7bdb67d5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "ppv-lite86"
|
||||||
version = "0.2.16"
|
version = "0.2.16"
|
||||||
@ -550,6 +558,18 @@ dependencies = [
|
|||||||
"yaml-rust",
|
"yaml-rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "simplelog"
|
||||||
|
version = "0.11.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c1348164456f72ca0116e4538bdaabb0ddb622c7d9f16387c725af3e96d6001c"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"log",
|
||||||
|
"paris",
|
||||||
|
"termcolor",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
|
@ -16,6 +16,8 @@ notify = "4.0.0"
|
|||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
ffprobe = "0.3"
|
ffprobe = "0.3"
|
||||||
|
log = "0.4.14"
|
||||||
|
simplelog = { version = "^0.11.2", features = ["paris"] }
|
||||||
|
|
||||||
# tokio = { version = "1.16.1", features = ["full"] }
|
# tokio = { version = "1.16.1", features = ["full"] }
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
16
docs/developer.md
Normal file
16
docs/developer.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
### Cross Compile
|
||||||
|
|
||||||
|
For cross compiling on fedora linux, you need to install some extra packages:
|
||||||
|
|
||||||
|
- mingw compiler:
|
||||||
|
```
|
||||||
|
dnf install mingw{32,64}-filesystem mingw{32,64}-binutils mingw{32,64}-gcc{,-c++} mingw{32,64}-crt mingw{32,64}-headers mingw{32,64}-pkg-config mingw32-nsis mingw{32,64}-hamlib mingw{32,64}-libpng mingw{32,64}-libusbx mingw{32,64}-portaudio mingw{32,64}-fltk mingw{32,64}-libgnurx mingw{32,64}-gettext mingw{32,64}-winpthreads-static intltool
|
||||||
|
```
|
||||||
|
|
||||||
|
- rust tools:
|
||||||
|
```
|
||||||
|
rustup toolchain install stable-x86_64-pc-windows-gnu
|
||||||
|
rustup target add x86_64-pc-windows-gnu
|
||||||
|
```
|
||||||
|
|
||||||
|
[Cross](https://github.com/cross-rs/cross#dependencies) could be an option to.
|
21
examples/logging.rs
Normal file
21
examples/logging.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
extern crate log;
|
||||||
|
extern crate simplelog;
|
||||||
|
|
||||||
|
use simplelog::*;
|
||||||
|
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
TermLogger::init(LevelFilter::Debug, Config::default(), TerminalMode::Mixed, ColorChoice::Auto).unwrap();
|
||||||
|
//SimpleLogger::init(LevelFilter::Debug, Config::default()).unwrap();
|
||||||
|
// CombinedLogger::init(
|
||||||
|
// vec![
|
||||||
|
// TermLogger::new(LevelFilter::Debug, Config::default(), TerminalMode::Mixed, ColorChoice::Auto),
|
||||||
|
// WriteLogger::new(LevelFilter::Debug, Config::default(), File::create("my_rust_binary.log").unwrap()),
|
||||||
|
// ]
|
||||||
|
// ).unwrap();
|
||||||
|
|
||||||
|
error!("Bright red error");
|
||||||
|
info!("This only appears in <red>the log file</>");
|
||||||
|
debug!("This level is <b>currently</b> not enabled for any logger");
|
||||||
|
}
|
@ -3,10 +3,16 @@ mod output;
|
|||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use crate::output::desktop;
|
use crate::output::desktop;
|
||||||
use crate::utils::get_config;
|
use crate::utils::{get_config, Messenger};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
|
let msg = Messenger::new(&config);
|
||||||
|
|
||||||
|
msg.debug("this is a debug");
|
||||||
|
msg.info("this is a info");
|
||||||
|
msg.warning("this is a warning");
|
||||||
|
msg.error("this is a error");
|
||||||
// println!("{:#?}", config);
|
// println!("{:#?}", config);
|
||||||
|
|
||||||
// folder::walk(&config.storage.path, config.storage.shuffle, &config.storage.extensions);
|
// folder::walk(&config.storage.path, config.storage.shuffle, &config.storage.extensions);
|
||||||
|
85
src/utils/messenger.rs
Normal file
85
src/utils/messenger.rs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
extern crate log;
|
||||||
|
extern crate simplelog;
|
||||||
|
|
||||||
|
use simplelog::*;
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
|
use crate::utils::Config;
|
||||||
|
|
||||||
|
pub struct Messenger {
|
||||||
|
message: String,
|
||||||
|
log_to_file: bool,
|
||||||
|
backup_count: u32,
|
||||||
|
path: String,
|
||||||
|
level: String,
|
||||||
|
ffmpeg_level: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Messenger {
|
||||||
|
pub fn new(config: &Config) -> Self {
|
||||||
|
let conf = config.logging.clone();
|
||||||
|
|
||||||
|
let logger_config = simplelog::ConfigBuilder::new()
|
||||||
|
.set_level_color(Level::Info, Some(Color::Green))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
if conf.log_to_file {
|
||||||
|
WriteLogger::init(
|
||||||
|
LevelFilter::Debug,
|
||||||
|
simplelog::Config::default(),
|
||||||
|
File::create("ffplayout.log").unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
TermLogger::init(
|
||||||
|
LevelFilter::Debug,
|
||||||
|
logger_config,
|
||||||
|
TerminalMode::Mixed,
|
||||||
|
ColorChoice::Auto,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
Messenger {
|
||||||
|
message: "".to_string(),
|
||||||
|
log_to_file: conf.log_to_file,
|
||||||
|
backup_count: conf.backup_count,
|
||||||
|
path: conf.log_path,
|
||||||
|
level: conf.log_level,
|
||||||
|
ffmpeg_level: conf.ffmpeg_level,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn debug(&self, msg: &str) {
|
||||||
|
if self.level.to_lowercase() == "debug".to_string() {
|
||||||
|
debug!("{}", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn info(&self, msg: &str) {
|
||||||
|
if self.level.to_lowercase() == "debug".to_string()
|
||||||
|
|| self.level.to_lowercase() == "info".to_string()
|
||||||
|
{
|
||||||
|
info!("{}", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn warning(&self, msg: &str) {
|
||||||
|
if self.level.to_lowercase() == "debug".to_string()
|
||||||
|
|| self.level.to_lowercase() == "info".to_string()
|
||||||
|
|| self.level.to_lowercase() == "warning".to_string()
|
||||||
|
{
|
||||||
|
warn!("{}", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn error(&self, msg: &str) {
|
||||||
|
if self.level.to_lowercase() == "debug".to_string()
|
||||||
|
|| self.level.to_lowercase() == "info".to_string()
|
||||||
|
|| self.level.to_lowercase() == "warning".to_string()
|
||||||
|
|| self.level.to_lowercase() == "error".to_string()
|
||||||
|
{
|
||||||
|
error!("{}", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,14 +6,15 @@ use std::{fs::metadata, process, time, time::UNIX_EPOCH};
|
|||||||
|
|
||||||
mod arg_parse;
|
mod arg_parse;
|
||||||
mod config;
|
mod config;
|
||||||
// mod folder;
|
|
||||||
mod json_reader;
|
mod json_reader;
|
||||||
|
mod messenger;
|
||||||
mod playlist;
|
mod playlist;
|
||||||
|
|
||||||
pub use arg_parse::get_args;
|
pub use arg_parse::get_args;
|
||||||
pub use config::{get_config, Config};
|
pub use config::{get_config, Config};
|
||||||
// pub use folder::walk;
|
// pub use folder::walk;
|
||||||
pub use json_reader::{read_json, Program};
|
pub use json_reader::{read_json, Program};
|
||||||
|
pub use messenger::Messenger;
|
||||||
pub use playlist::program;
|
pub use playlist::program;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
Loading…
Reference in New Issue
Block a user