mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-04-22 20:06:18 +02:00
fix: prevent double download
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user