diff --git a/daemon/src/config.rs b/daemon/src/config.rs index 562b201..039a4c8 100644 --- a/daemon/src/config.rs +++ b/daemon/src/config.rs @@ -16,7 +16,7 @@ pub struct Config { pub ui_level: u8, pub colorblind_mode: bool, pub key_input_mode: u8, - pub ntfy_topic: Option, + pub ntfy_url: Option, pub analyzers: AnalyzerConfig, } @@ -31,7 +31,7 @@ impl Default for Config { colorblind_mode: false, key_input_mode: 0, analyzers: AnalyzerConfig::default(), - ntfy_topic: None, + ntfy_url: None, } } } diff --git a/daemon/src/main.rs b/daemon/src/main.rs index 7cbd704..51701e3 100644 --- a/daemon/src/main.rs +++ b/daemon/src/main.rs @@ -17,7 +17,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use crate::config::{parse_args, parse_config}; use crate::diag::run_diag_read_thread; use crate::error::RayhunterError; -use crate::notifications::{run_notification_worker, NotificationService}; +use crate::notifications::{NotificationService, run_notification_worker}; use crate::pcap::get_pcap; use crate::qmdl_store::RecordingStore; use crate::server::{ServerState, get_config, get_qmdl, get_zip, serve_static, set_config}; @@ -220,7 +220,7 @@ async fn run_with_config( let mut maybe_ui_shutdown_tx = None; let mut maybe_key_input_shutdown_tx = None; - let notification_service = NotificationService::new(config.ntfy_topic.clone()); + let notification_service = NotificationService::new(config.ntfy_url.clone()); if !config.debug_mode { let (ui_shutdown_tx, ui_shutdown_rx) = oneshot::channel(); diff --git a/daemon/src/notifications.rs b/daemon/src/notifications.rs index c554eb0..8b1b05c 100644 --- a/daemon/src/notifications.rs +++ b/daemon/src/notifications.rs @@ -8,8 +8,6 @@ use log::error; use tokio::sync::mpsc::{self, error::TryRecvError}; use tokio_util::task::TaskTracker; -static NTFY_BASE_URL: &str = "https://ntfy.sh/"; - pub struct Notification { message_type: String, message: String, @@ -35,19 +33,15 @@ struct NotificationStatus { } pub struct NotificationService { - channel_name: Option, + url: Option, tx: mpsc::Sender, rx: mpsc::Receiver, } impl NotificationService { - pub fn new(channel_name: Option) -> Self { + pub fn new(url: Option) -> Self { let (tx, rx) = mpsc::channel(10); - Self { - channel_name, - tx, - rx, - } + Self { url, tx, rx } } pub fn new_handler(&self) -> mpsc::Sender { @@ -81,12 +75,11 @@ pub fn run_notification_worker( failed_since_last_success: 0, }); // Ignore if we're in the debounce period - if let Some(debounce) = notification.debounce { - if let Some(last_sent) = status.last_sent { - if last_sent.elapsed() < debounce { - continue; - } - } + if let Some(debounce) = notification.debounce + && let Some(last_sent) = status.last_sent + && last_sent.elapsed() < debounce + { + continue; } status.message = notification.message; status.needs_sending = true; @@ -117,7 +110,7 @@ pub fn run_notification_worker( } match http_client - .post(format!("{NTFY_BASE_URL}{channel_name}")) + .post(&url) .body(notification.message.clone()) .send() .await diff --git a/daemon/web/src/lib/components/ConfigForm.svelte b/daemon/web/src/lib/components/ConfigForm.svelte index 9d01734..fd065d7 100644 --- a/daemon/web/src/lib/components/ConfigForm.svelte +++ b/daemon/web/src/lib/components/ConfigForm.svelte @@ -112,16 +112,17 @@
- - + ntfy URL for Sending Notifications + + + />
- +