diff --git a/src-tauri/src/geoip_downloader.rs b/src-tauri/src/geoip_downloader.rs index 35634b3..acc9b99 100644 --- a/src-tauri/src/geoip_downloader.rs +++ b/src-tauri/src/geoip_downloader.rs @@ -5,6 +5,7 @@ use directories::BaseDirs; use reqwest::Client; use serde::{Deserialize, Serialize}; use std::path::PathBuf; +use std::sync::atomic::{AtomicBool, Ordering}; use tokio::fs; use tokio::io::AsyncWriteExt; @@ -22,6 +23,8 @@ pub struct GeoIPDownloadProgress { pub eta_seconds: Option, } +static DOWNLOAD_IN_PROGRESS: AtomicBool = AtomicBool::new(false); + pub struct GeoIPDownloader { client: Client, } @@ -126,6 +129,22 @@ impl GeoIPDownloader { pub async fn download_geoip_database( &self, _app_handle: &tauri::AppHandle, + ) -> Result<(), Box> { + if DOWNLOAD_IN_PROGRESS + .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) + .is_err() + { + log::info!("GeoIP database download already in progress, skipping"); + return Ok(()); + } + let result = self.download_geoip_database_inner(_app_handle).await; + DOWNLOAD_IN_PROGRESS.store(false, Ordering::SeqCst); + result + } + + async fn download_geoip_database_inner( + &self, + _app_handle: &tauri::AppHandle, ) -> Result<(), Box> { // Emit initial progress let _ = events::emit(