fix: app nap ipc drop and implement delete modal

This commit is contained in:
NimBold
2026-06-15 13:29:20 +03:30
parent d046c95c28
commit 9e26be5b2c
8 changed files with 141 additions and 78 deletions
+14 -1
View File
@@ -18,7 +18,7 @@ use tokio::{
};
use uuid::Uuid;
const PROGRESS_INTERVAL: Duration = Duration::from_millis(150);
const PROGRESS_INTERVAL: Duration = Duration::from_millis(1000);
const WRITE_BUFFER_CAPACITY: usize = 256 * 1024;
#[derive(Debug)]
@@ -153,6 +153,7 @@ impl CoordinatorEventSink {
fraction,
speed: format_speed(speed_bytes),
eta,
size: total.map(|t| format_size(t as f64)),
},
);
}
@@ -586,6 +587,18 @@ fn format_speed(bytes_per_second: f64) -> String {
}
}
fn format_size(bytes: f64) -> String {
if bytes >= 1024.0 * 1024.0 * 1024.0 {
format!("{:.2} GB", bytes / (1024.0 * 1024.0 * 1024.0))
} else if bytes >= 1024.0 * 1024.0 {
format!("{:.1} MB", bytes / (1024.0 * 1024.0))
} else if bytes >= 1024.0 {
format!("{:.1} KB", bytes / 1024.0)
} else {
format!("{bytes:.0} B")
}
}
fn format_duration(seconds: f64) -> String {
if seconds >= 3600.0 {
format!("{:.0}h {:.0}m", seconds / 3600.0, (seconds % 3600.0) / 60.0)
+11 -2
View File
@@ -164,8 +164,17 @@ async fn download_handler(
};
if let Some(window) = state.app_handle.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
let is_visible = window.is_visible().unwrap_or(true);
if !is_visible {
let _ = window.show();
let _ = window.set_focus();
// Sleep briefly to let the webview wake up from macOS App Nap
// otherwise the IPC event emitted immediately after is dropped.
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
} else {
let _ = window.show();
let _ = window.set_focus();
}
}
if state.app_handle.emit("extension-add-download", download).is_err() {
+3 -1
View File
@@ -367,6 +367,7 @@ pub struct DownloadProgressEvent {
fraction: f64,
speed: String,
eta: String,
size: Option<String>,
}
fn collect_download_uris(url: &str, mirrors: Option<&str>) -> Vec<String> {
@@ -790,12 +791,13 @@ pub(crate) async fn start_media_download_internal(
.unwrap_or_else(|| "-".to_string());
let now = std::time::Instant::now();
if now.duration_since(last_progress_at) >= std::time::Duration::from_millis(150) {
if now.duration_since(last_progress_at) >= std::time::Duration::from_millis(1000) {
let _ = app_handle.emit("download-progress", DownloadProgressEvent {
id: id.to_string(),
fraction: overall_fraction,
speed,
eta,
size: None,
});
last_progress_at = now;
}