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]]
name = "post_maker"
version = "0.2.2"
version = "0.2.3"
dependencies = [
"clap",
"dirs",

View File

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

View File

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

View File

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