fix: prevent double download

This commit is contained in:
zhom
2026-03-03 00:57:09 +04:00
parent 266ecda1c7
commit dd6834a4af
+19
View File
@@ -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<f64>,
}
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<dyn std::error::Error + Send + Sync>> {
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<dyn std::error::Error + Send + Sync>> {
// Emit initial progress
let _ = events::emit(