Skip to content

Commit

Permalink
perf: remove lazy_static
Browse files Browse the repository at this point in the history
  • Loading branch information
ttimochan committed Jul 29, 2023
1 parent 7926f11 commit d12717a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ serde_json = "1.0"
dbus = "0.7.1"
tokio = { version = "1", features = ["full"] }
chrono = "0.4.26"
lazy_static = "1.4.0"

[profile.release]
panic = 'abort'
25 changes: 11 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: timochan
* @Date: 2023-07-17 11:48:02
* @LastEditors: timochan
* @LastEditTime: 2023-07-28 17:35:41
* @LastEditTime: 2023-07-29 11:25:42
* @FilePath: /processforlinux/src/main.rs
*/
mod get_active_window;
Expand All @@ -11,13 +11,11 @@ mod get_media;
mod reportprocess;

use chrono::Utc;
use lazy_static::lazy_static;

use std::process::exit;
use std::{error::Error, sync::Mutex, time::Duration};
use std::{error::Error, time::Duration};
use tokio::time::sleep;

type ApiVariables = (String, String, i64, bool, bool);

struct Config {
api_url: String,
api_key: String,
Expand All @@ -26,13 +24,6 @@ struct Config {
log_enable: bool,
}

lazy_static! {
static ref API_VARIABLES: Mutex<ApiVariables> =
Mutex::new(get_env_file::init().unwrap_or_else(|err| {
eprintln!("Failed to get env file: {}", err);
exit(1);
}));
}
async fn run_loop(config: Config) {
let mut last_time = Utc::now();
let mut previous_process_name = String::new();
Expand Down Expand Up @@ -116,8 +107,14 @@ async fn report(
#[tokio::main]
async fn main() {
let (api_url, api_key, watch_time, media_enable, log_enable) = {
let api_vars = API_VARIABLES.lock().unwrap();
api_vars.clone()
let api_vars = get_env_file::init();
match api_vars {
Ok(api_vars) => api_vars,
Err(e) => {
eprintln!("Failed to get api variables: {}", e);
exit(1);
}
}
};
let config = Config {
api_url: api_url,
Expand Down

0 comments on commit d12717a

Please sign in to comment.