From 7c9c9ab1e2863888bbbc432299314ed3a37e02db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Thu, 7 May 2026 22:04:15 -0400 Subject: [PATCH] Split download page labels --- crates/ely_app/src/shell/internal_pages.rs | 1 + .../shell/internal_pages/download_labels.rs | 64 ++++++++++++++++ .../src/shell/internal_pages/downloads.rs | 74 +++---------------- 3 files changed, 74 insertions(+), 65 deletions(-) create mode 100644 crates/ely_app/src/shell/internal_pages/download_labels.rs diff --git a/crates/ely_app/src/shell/internal_pages.rs b/crates/ely_app/src/shell/internal_pages.rs index f9012eb..4f82e3e 100644 --- a/crates/ely_app/src/shell/internal_pages.rs +++ b/crates/ely_app/src/shell/internal_pages.rs @@ -1,3 +1,4 @@ +mod download_labels; mod downloads; use ely_browser_core::BrowserSnapshot; diff --git a/crates/ely_app/src/shell/internal_pages/download_labels.rs b/crates/ely_app/src/shell/internal_pages/download_labels.rs new file mode 100644 index 0000000..8dfb063 --- /dev/null +++ b/crates/ely_app/src/shell/internal_pages/download_labels.rs @@ -0,0 +1,64 @@ +use ely_domain::{ + DownloadDestination, DownloadEntry, DownloadPolicy, DownloadSecurity, DownloadState, +}; + +pub(crate) fn download_state_label(state: &DownloadState) -> &'static str { + match state { + DownloadState::InProgress => "In progress", + DownloadState::Paused => "Paused", + DownloadState::Completed => "Complete", + DownloadState::Cancelled => "Cancelled", + DownloadState::Failed => "Failed", + } +} + +pub(crate) fn download_size_label(entry: &DownloadEntry) -> String { + match entry.total_bytes() { + Some(total_bytes) => { + format!("{} of {}", format_bytes(entry.received_bytes()), format_bytes(total_bytes)) + } + None => format_bytes(entry.received_bytes()), + } +} + +pub(crate) fn download_policy_label(policy: &DownloadPolicy) -> String { + format!("Profile path: {}", download_destination_label(policy.destination())) +} + +pub(crate) fn download_entry_location_label(entry: &DownloadEntry) -> String { + match entry.target_file_path() { + Some(path) => path.display().to_string(), + None => download_destination_label(entry.destination()), + } +} + +pub(crate) fn download_security_label(security: &DownloadSecurity) -> &'static str { + match security { + DownloadSecurity::Standard => "Standard", + DownloadSecurity::DangerousExtension => "Extension prompt required", + } +} + +fn download_destination_label(destination: &DownloadDestination) -> String { + match destination { + DownloadDestination::AskEveryTime => "Ask before saving".to_string(), + DownloadDestination::FixedDirectory(path) => path.display().to_string(), + } +} + +fn format_bytes(bytes: u64) -> String { + const KIB: u64 = 1024; + const MIB: u64 = KIB * 1024; + const GIB: u64 = MIB * 1024; + + if bytes >= GIB { + return format!("{:.1} GB", bytes as f64 / GIB as f64); + } + if bytes >= MIB { + return format!("{:.1} MB", bytes as f64 / MIB as f64); + } + if bytes >= KIB { + return format!("{:.1} KB", bytes as f64 / KIB as f64); + } + format!("{bytes} B") +} diff --git a/crates/ely_app/src/shell/internal_pages/downloads.rs b/crates/ely_app/src/shell/internal_pages/downloads.rs index 5b11931..5897804 100644 --- a/crates/ely_app/src/shell/internal_pages/downloads.rs +++ b/crates/ely_app/src/shell/internal_pages/downloads.rs @@ -1,8 +1,6 @@ use ely_browser_core::BrowserSnapshot; use ely_design_system::colors; -use ely_domain::{ - DownloadDestination, DownloadEntry, DownloadPolicy, DownloadSecurity, DownloadState, -}; +use ely_domain::{DownloadEntry, DownloadSecurity, DownloadState}; use gpui::prelude::FluentBuilder; use gpui::{ AnyElement, Context, InteractiveElement, IntoElement, ParentElement, SharedString, Styled, div, @@ -14,7 +12,14 @@ use gpui_component::{ scroll::ScrollableElement, }; -use super::{ElyShell, render_canvas_surface}; +use super::{ + ElyShell, + download_labels::{ + download_entry_location_label, download_policy_label, download_security_label, + download_size_label, download_state_label, + }, + render_canvas_surface, +}; impl ElyShell { pub(super) fn render_downloads_page( @@ -400,43 +405,6 @@ fn download_action_button( Button::new((action, index)).ghost().xsmall().icon(icon).tooltip(tooltip) } -fn download_state_label(state: &DownloadState) -> &'static str { - match state { - DownloadState::InProgress => "In progress", - DownloadState::Paused => "Paused", - DownloadState::Completed => "Complete", - DownloadState::Cancelled => "Cancelled", - DownloadState::Failed => "Failed", - } -} - -fn download_size_label(entry: &DownloadEntry) -> String { - match entry.total_bytes() { - Some(total_bytes) => { - format!("{} of {}", format_bytes(entry.received_bytes()), format_bytes(total_bytes)) - } - None => format_bytes(entry.received_bytes()), - } -} - -fn download_policy_label(policy: &DownloadPolicy) -> String { - format!("Profile path: {}", download_destination_label(policy.destination())) -} - -fn download_destination_label(destination: &DownloadDestination) -> String { - match destination { - DownloadDestination::AskEveryTime => "Ask before saving".to_string(), - DownloadDestination::FixedDirectory(path) => path.display().to_string(), - } -} - -fn download_entry_location_label(entry: &DownloadEntry) -> String { - match entry.target_file_path() { - Some(path) => path.display().to_string(), - None => download_destination_label(entry.destination()), - } -} - fn render_download_file_error(message: String) -> AnyElement { div() .rounded_md() @@ -464,27 +432,3 @@ fn render_security_prompt(security: &DownloadSecurity) -> AnyElement { .child(download_security_label(security)) .into_any_element() } - -fn download_security_label(security: &DownloadSecurity) -> &'static str { - match security { - DownloadSecurity::Standard => "Standard", - DownloadSecurity::DangerousExtension => "Extension prompt required", - } -} - -fn format_bytes(bytes: u64) -> String { - const KIB: u64 = 1024; - const MIB: u64 = KIB * 1024; - const GIB: u64 = MIB * 1024; - - if bytes >= GIB { - return format!("{:.1} GB", bytes as f64 / GIB as f64); - } - if bytes >= MIB { - return format!("{:.1} MB", bytes as f64 / MIB as f64); - } - if bytes >= KIB { - return format!("{:.1} KB", bytes as f64 / KIB as f64); - } - format!("{bytes} B") -}