Render downloads internal page
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::{DomainError, DownloadId, ProfileId, UrlText};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum DownloadState {
|
||||
InProgress,
|
||||
Paused,
|
||||
Completed,
|
||||
Cancelled,
|
||||
Failed,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct DownloadEntry {
|
||||
id: DownloadId,
|
||||
profile_id: ProfileId,
|
||||
source_url: UrlText,
|
||||
file_name: String,
|
||||
state: DownloadState,
|
||||
received_bytes: u64,
|
||||
total_bytes: Option<u64>,
|
||||
started_at: SystemTime,
|
||||
}
|
||||
|
||||
impl DownloadEntry {
|
||||
pub fn started(
|
||||
profile_id: ProfileId,
|
||||
source_url: UrlText,
|
||||
file_name: impl Into<String>,
|
||||
total_bytes: Option<u64>,
|
||||
started_at: SystemTime,
|
||||
) -> Result<Self, DomainError> {
|
||||
let file_name = file_name.into();
|
||||
let file_name = file_name.trim();
|
||||
if file_name.is_empty() {
|
||||
return Err(DomainError::EmptyField { field: "file_name" });
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
id: DownloadId::new(),
|
||||
profile_id,
|
||||
source_url,
|
||||
file_name: file_name.to_string(),
|
||||
state: DownloadState::InProgress,
|
||||
received_bytes: 0,
|
||||
total_bytes,
|
||||
started_at,
|
||||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn id(&self) -> &DownloadId {
|
||||
&self.id
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn profile_id(&self) -> &ProfileId {
|
||||
&self.profile_id
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn source_url(&self) -> &UrlText {
|
||||
&self.source_url
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn file_name(&self) -> &str {
|
||||
&self.file_name
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn state(&self) -> &DownloadState {
|
||||
&self.state
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn received_bytes(&self) -> u64 {
|
||||
self.received_bytes
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn total_bytes(&self) -> Option<u64> {
|
||||
self.total_bytes
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn started_at(&self) -> SystemTime {
|
||||
self.started_at
|
||||
}
|
||||
}
|
||||
@@ -38,3 +38,4 @@ entity_id!(SpaceId, "space");
|
||||
entity_id!(ProfileId, "profile");
|
||||
entity_id!(SplitId, "split");
|
||||
entity_id!(WebViewId, "webview");
|
||||
entity_id!(DownloadId, "download");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
mod archive;
|
||||
mod command;
|
||||
mod download;
|
||||
mod error;
|
||||
mod history;
|
||||
mod identifiers;
|
||||
@@ -11,9 +12,10 @@ mod url_text;
|
||||
|
||||
pub use archive::{ArchiveSource, ArchivedTab};
|
||||
pub use command::{CommandIntent, CommandScope};
|
||||
pub use download::{DownloadEntry, DownloadState};
|
||||
pub use error::DomainError;
|
||||
pub use history::HistoryEntry;
|
||||
pub use identifiers::{ProfileId, SpaceId, SplitId, TabId, WebViewId};
|
||||
pub use identifiers::{DownloadId, ProfileId, SpaceId, SplitId, TabId, WebViewId};
|
||||
pub use profile::{Profile, ProfileKind};
|
||||
pub use space::{ArchivePolicy, Space};
|
||||
pub use split::{SplitAxis, SplitLayout, SplitPane};
|
||||
|
||||
Reference in New Issue
Block a user