This commit is contained in:
Piyush मिश्रः 2022-01-29 23:47:42 +05:30
parent 18f555e3e8
commit cb3c12f708
4 changed files with 44 additions and 44 deletions

2
Cargo.lock generated
View File

@ -626,7 +626,7 @@ dependencies = [
[[package]] [[package]]
name = "post_maker" name = "post_maker"
version = "0.2.2" version = "0.2.3"
dependencies = [ dependencies = [
"clap", "clap",
"dirs", "dirs",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "post_maker" name = "post_maker"
version = "0.2.2" version = "0.2.3"
edition = "2021" edition = "2021"
description = "Post Maker helps you to make post for Instagram and other Social Media apps easily." description = "Post Maker helps you to make post for Instagram and other Social Media apps easily."
authors = ["PiyushXCoder <https://piyushxcoder.in>"] authors = ["PiyushXCoder <https://piyushxcoder.in>"]

View File

@ -19,12 +19,7 @@ use fltk::dialog;
use fltk_theme::ThemeType; use fltk_theme::ThemeType;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{collections::HashMap, fs::File, path::PathBuf};
collections::HashMap,
fs::File,
path::PathBuf,
time::{Duration, SystemTime},
};
lazy_static! { lazy_static! {
/// Directory where all Configurations are present /// Directory where all Configurations are present
@ -218,38 +213,39 @@ pub(crate) fn save_configs(configs: HashMap<String, ConfigFile>) {
} }
pub(crate) fn log_file() -> File { pub(crate) fn log_file() -> File {
match File::open(&*LOG_FILE) { // match File::open(&*LOG_FILE) {
Ok(mut file) => { // Ok(mut file) => {
if is_file_30_days_old(&file) { // if is_file_30_days_old(&file) {
// match File::create(&*LOG_FILE) {
// Ok(f) => file = f,
// Err(e) => {
// dialog::alert_default("Can't open log file!");
// panic!("{:?}", e);
// }
// }
// }
// file
// }
// Err(_) =>
match File::create(&*LOG_FILE) { match File::create(&*LOG_FILE) {
Ok(f) => file = f,
Err(e) => {
dialog::alert_default("Can't open log file!");
panic!("{:?}", e);
}
}
}
file
}
Err(_) => match File::create(&*LOG_FILE) {
Ok(f) => f, Ok(f) => f,
Err(e) => { Err(e) => {
dialog::alert_default("Can't open log file!"); dialog::alert_default("Can't open log file!");
panic!("{:?}", e); panic!("{:?}", e);
} }
},
} }
// }
} }
pub(crate) fn is_file_30_days_old(file: &File) -> bool { // pub(crate) fn is_file_30_days_old(file: &File) -> bool {
if let Ok(meta) = file.metadata() { // if let Ok(meta) = file.metadata() {
if let Ok(time) = meta.created() { // if let Ok(time) = meta.created() {
if let Ok(dur) = SystemTime::now().duration_since(time) { // if let Ok(dur) = SystemTime::now().duration_since(time) {
if dur > Duration::from_secs(60 * 60 * 24 * 30) { // if dur > Duration::from_secs(60 * 60 * 24 * 30) {
return true; // return true;
} // }
} // }
} // }
} // }
false // false
} // }

View File

@ -47,11 +47,15 @@ fn main() {
let app = App::default(); let app = App::default();
WidgetTheme::new(globals::THEME.clone().into()).apply(); WidgetTheme::new(globals::THEME.clone().into()).apply();
if let Err(e) = CombinedLogger::init(vec![WriteLogger::new( if let Err(e) = CombinedLogger::init(vec![
WriteLogger::new(LevelFilter::Warn, Config::default(), config::log_file()),
TermLogger::new(
LevelFilter::Info, LevelFilter::Info,
Config::default(), Config::default(),
config::log_file(), TerminalMode::Mixed,
)]) { ColorChoice::Auto,
),
]) {
dialog::alert_default("Failed to start logger"); dialog::alert_default("Failed to start logger");
panic!("Failed to start logger\n{:?}", e); panic!("Failed to start logger\n{:?}", e);
} }