diff --git a/src/core/nal.rs b/src/core/nal.rs index f7f972f..5b2fe97 100644 --- a/src/core/nal.rs +++ b/src/core/nal.rs @@ -58,8 +58,14 @@ impl NalConfig { pub fn default() -> Self { NalConfig { net_type: Option::from(NetType::Sangfor), - login: LoginConfig { username: "".to_string(), password: "".to_string() }, - check: NetStatusCheck { interval: 0 }, + login: LoginConfig { + username: "".to_string(), + password: "".to_string(), + }, + check: NetStatusCheck { + // 默认3秒 + interval: 3 + }, } } } @@ -88,7 +94,6 @@ pub fn init_config() -> NalConfig { } - /// 获取没有代理的客户端 pub fn get_no_proxy_client() -> Client { Client::builder() diff --git a/src/main.rs b/src/main.rs index 8bfeaab..ee92a8a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,7 @@ async fn main() { let service = Service::new("net-auto-login"); if cli.install { service.install(); + service.start(); return; } if cli.uninstall { diff --git a/src/util/logs.rs b/src/util/logs.rs index a16542a..800f13e 100644 --- a/src/util/logs.rs +++ b/src/util/logs.rs @@ -1,12 +1,22 @@ -use std::fs; +use std::{env, fs}; +use std::io::{Error}; +use std::path::Path; use chrono::Local; use log::LevelFilter; +use log::{error, LevelFilter}; /// 初始化日志 -pub fn init(log_file: &str, level: LevelFilter) -> Result<(), fern::InitError> { - fs::create_dir_all("./logs").unwrap(); // 如果需要,创建日志目录 - let log_file_path = "./logs/".to_string() + log_file; - /* +pub fn init(log_file: &str, level: LevelFilter) -> Result<(), Error> { + let current_dir = if cfg!(target_os = "windows") { + // env::current_dir()?.to_str().unwrap_or(".").to_string() + env::current_exe()? + .parent().unwrap_or(Path::new(".")) + .to_str().unwrap_or(".").to_string() + } else { ".".to_string() }; + let logs_dir = current_dir + "/logs/"; + fs::create_dir_all(logs_dir.clone()).unwrap(); // 如果需要,创建日志目录 + let log_file_path = logs_dir.to_string() + log_file; + /* //env_logger /// 定义一个函数用于将DateTime对象转换为指定格式的字符串 fn format_timestamp(dt: Timestamp) -> String { let dt: DateTime = DateTime::from_str(&*dt.to_string()).unwrap();