mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-09-25 10:51:03 +02:00
fix: prevent double download
This commit is contained in:
@@ -5,6 +5,7 @@ use directories::BaseDirs;
|
|||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
|
|
||||||
@@ -22,6 +23,8 @@ pub struct GeoIPDownloadProgress {
|
|||||||
pub eta_seconds: Option<f64>,
|
pub eta_seconds: Option<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static DOWNLOAD_IN_PROGRESS: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
pub struct GeoIPDownloader {
|
pub struct GeoIPDownloader {
|
||||||
client: Client,
|
client: Client,
|
||||||
}
|
}
|
||||||
@@ -126,6 +129,22 @@ impl GeoIPDownloader {
|
|||||||
pub async fn download_geoip_database(
|
pub async fn download_geoip_database(
|
||||||
&self,
|
&self,
|
||||||
_app_handle: &tauri::AppHandle,
|
_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>> {
|
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
// Emit initial progress
|
// Emit initial progress
|
||||||
let _ = events::emit(
|
let _ = events::emit(
|
||||||
|
|||||||
Reference in New Issue
Block a user