mirror of
https://github.com/2e3s/awatcher.git
synced 2025-07-22 18:10:05 +00:00
Fix client host
This commit is contained in:
parent
03e94e2f26
commit
7ac76da921
@ -25,9 +25,13 @@ async fn main() -> anyhow::Result<(), Box<dyn Error>> {
|
||||
let config = config.watchers_config;
|
||||
|
||||
if config.no_server {
|
||||
warn!("Not sending to server {}:{}", config.host, config.port);
|
||||
warn!(
|
||||
"Not sending to server {}:{}",
|
||||
config.client_host(),
|
||||
config.port
|
||||
);
|
||||
} else {
|
||||
info!("Sending to server {}:{}", config.host, config.port);
|
||||
info!("Sending to server {}:{}", config.client_host(), config.port);
|
||||
}
|
||||
info!(
|
||||
"Idle timeout: {} seconds",
|
||||
|
@ -2,6 +2,8 @@ pub mod defaults;
|
||||
mod file_config;
|
||||
mod filters;
|
||||
|
||||
use std::{net::Ipv4Addr, str::FromStr};
|
||||
|
||||
use self::filters::Filter;
|
||||
use chrono::Duration;
|
||||
pub use file_config::FileConfig;
|
||||
@ -17,6 +19,18 @@ pub struct Config {
|
||||
pub filters: Vec<Filter>,
|
||||
}
|
||||
|
||||
fn normalize_server_host(server_host: &str) -> String {
|
||||
let is_zero_first_octet = match Ipv4Addr::from_str(server_host) {
|
||||
Ok(ip) => ip.octets()[0] == 0,
|
||||
Err(_) => false,
|
||||
};
|
||||
if is_zero_first_octet {
|
||||
"127.0.0.1".to_string()
|
||||
} else {
|
||||
server_host.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn match_window_data(&self, app_id: &str, title: &str) -> FilterResult {
|
||||
for filter in &self.filters {
|
||||
@ -28,4 +42,8 @@ impl Config {
|
||||
|
||||
FilterResult::Skip
|
||||
}
|
||||
|
||||
pub fn client_host(&self) -> String {
|
||||
normalize_server_host(&self.host)
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ pub struct ReportClient {
|
||||
|
||||
impl ReportClient {
|
||||
pub async fn new(config: Config) -> anyhow::Result<Self, Box<dyn Error>> {
|
||||
let client = AwClient::new(&config.host, config.port, "awatcher")?;
|
||||
let client = AwClient::new(&config.client_host(), config.port, "awatcher")?;
|
||||
|
||||
let hostname = gethostname::gethostname().into_string().unwrap();
|
||||
let idle_bucket_name = format!("aw-watcher-afk_{hostname}");
|
||||
|
Loading…
x
Reference in New Issue
Block a user