Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions daemon/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub struct Config {
pub ntfy_url: Option<String>,
/// Vector containing the types of enabled notifications
pub enabled_notifications: Vec<NotificationType>,
/// Whether Rayhunter should periodically check GitHub for new releases
pub auto_check_updates: bool,
/// Vector containing the list of enabled analyzers
pub analyzers: AnalyzerConfig,
/// Minimum disk space required to start a recording
Expand Down Expand Up @@ -134,6 +136,7 @@ impl Default for Config {
analyzers: AnalyzerConfig::default(),
ntfy_url: None,
enabled_notifications: vec![NotificationType::Warning, NotificationType::LowBattery],
auto_check_updates: true,
min_space_to_start_recording_mb: 1,
min_space_to_continue_recording_mb: 1,
gps_mode: GpsMode::Disabled,
Expand Down
2 changes: 2 additions & 0 deletions daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod pcap;
pub mod qmdl_store;
pub mod server;
pub mod stats;
pub mod update;
pub mod webdav;

#[cfg(feature = "apidocs")]
Expand All @@ -34,6 +35,7 @@ use utoipa::OpenApi;
server::get_zip,
stats::get_system_stats,
stats::get_qmdl_manifest,
stats::get_update_status,
stats::get_log,
diag::start_recording,
diag::stop_recording,
Expand Down
17 changes: 16 additions & 1 deletion daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod pcap;
mod qmdl_store;
mod server;
mod stats;
mod update;
mod webdav;

use std::net::SocketAddr;
Expand All @@ -29,7 +30,8 @@ use crate::server::{
ServerState, debug_set_display_state, get_config, get_qmdl, get_time, get_wifi_status, get_zip,
scan_wifi, serve_static, set_config, set_time_offset, test_notification,
};
use crate::stats::{get_qmdl_manifest, get_system_stats};
use crate::stats::{get_qmdl_manifest, get_system_stats, get_update_status};
use crate::update::{UpdateStatus, run_update_check_worker};
use crate::webdav::run_webdav_upload_worker;
use wifi_station::WifiStatus;

Expand Down Expand Up @@ -63,6 +65,7 @@ fn get_router() -> AppRouter {
.route("/api/qmdl/{name}", get(get_qmdl))
.route("/api/zip/{name}", get(get_zip))
.route("/api/system-stats", get(get_system_stats))
.route("/api/update-status", get(get_update_status))
.route("/api/qmdl-manifest", get(get_qmdl_manifest))
.route("/api/log", get(get_log))
.route("/api/start-recording", post(start_recording))
Expand Down Expand Up @@ -217,6 +220,7 @@ async fn run_with_config(
let _shutdown_guard = shutdown_token.clone().drop_guard();

let notification_service = NotificationService::new(config.ntfy_url.clone());
let update_status_lock = Arc::new(RwLock::new(UpdateStatus::default()));

if !config.debug_mode {
info!("Starting Diag Thread");
Expand Down Expand Up @@ -258,6 +262,16 @@ async fn run_with_config(
diag_tx.clone(),
shutdown_token.clone(),
);

if config.auto_check_updates {
run_update_check_worker(
&task_tracker,
shutdown_token.clone(),
update_status_lock.clone(),
notification_service.new_handler(),
config.enabled_notifications.clone(),
);
}
}

let analysis_status_lock = Arc::new(RwLock::new(analysis_status));
Expand Down Expand Up @@ -339,6 +353,7 @@ async fn run_with_config(
wifi_status,
wifi_scan_lock: tokio::sync::Mutex::new(()),
gps_state: Arc::new(tokio::sync::RwLock::new(initial_gps)),
update_status_lock: update_status_lock.clone(),
});
run_server(&task_tracker, state, shutdown_token.clone()).await;

Expand Down
1 change: 1 addition & 0 deletions daemon/src/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum NotificationError {
pub enum NotificationType {
Warning,
LowBattery,
Update,
}

pub struct Notification {
Expand Down
3 changes: 3 additions & 0 deletions daemon/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::gps::GpsData;
use crate::notifications::DEFAULT_NOTIFICATION_TIMEOUT;
use crate::pcap::{generate_pcap_data, load_gps_records_for_entry};
use crate::qmdl_store::RecordingStore;
use crate::update::UpdateStatus;

pub struct ServerState {
pub config_path: String,
Expand All @@ -42,6 +43,7 @@ pub struct ServerState {
pub wifi_status: Arc<RwLock<wifi_station::WifiStatus>>,
pub wifi_scan_lock: tokio::sync::Mutex<()>,
pub gps_state: Arc<RwLock<Option<GpsData>>>,
pub update_status_lock: Arc<RwLock<UpdateStatus>>,
}

#[cfg_attr(feature = "apidocs", utoipa::path(
Expand Down Expand Up @@ -580,6 +582,7 @@ mod tests {
wifi_status: Arc::new(RwLock::new(wifi_station::WifiStatus::default())),
wifi_scan_lock: tokio::sync::Mutex::new(()),
gps_state: Arc::new(RwLock::new(None)),
update_status_lock: Arc::new(RwLock::new(UpdateStatus::default())),
})
}

Expand Down
15 changes: 15 additions & 0 deletions daemon/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::Arc;
use crate::battery::get_battery_status;
use crate::error::RayhunterError;
use crate::server::ServerState;
use crate::update::UpdateStatus;
use crate::{battery::BatteryState, qmdl_store::ManifestEntry};

use axum::Json;
Expand Down Expand Up @@ -220,6 +221,20 @@ pub async fn get_qmdl_manifest(
}))
}

#[cfg_attr(feature = "apidocs", utoipa::path(
get,
path = "/api/update-status",
tag = "Statistics",
responses(
(status = StatusCode::OK, description = "Success", body = UpdateStatus)
),
summary = "Rayhunter update status",
description = "Check for available updates for Rayhunter."
))]
pub async fn get_update_status(State(state): State<Arc<ServerState>>) -> Json<UpdateStatus> {
Json(state.update_status_lock.read().await.clone())
}

#[cfg_attr(feature = "apidocs", utoipa::path(
get,
path = "/api/log",
Expand Down
Loading
Loading