Render downloads internal page
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ely_domain::{
|
||||
ArchivedTab, BrowserTab, DomainError, HistoryEntry, Profile, ProfileId, ProfileKind, Space,
|
||||
SpaceId, TabId, UrlText,
|
||||
ArchivedTab, BrowserTab, DomainError, DownloadEntry, HistoryEntry, Profile, ProfileId,
|
||||
ProfileKind, Space, SpaceId, TabId, UrlText,
|
||||
};
|
||||
|
||||
use crate::CoreError;
|
||||
|
||||
mod commands;
|
||||
mod downloads;
|
||||
mod history;
|
||||
mod profiles;
|
||||
mod tabs;
|
||||
@@ -37,6 +38,7 @@ pub struct BrowserSnapshot {
|
||||
pub favorites: Vec<BrowserTab>,
|
||||
pub pinned_tabs: Vec<BrowserTab>,
|
||||
pub archived_tabs: Vec<ArchivedTab>,
|
||||
pub download_entries: Vec<DownloadEntry>,
|
||||
pub history_entries: Vec<HistoryEntry>,
|
||||
pub spaces: Vec<Space>,
|
||||
pub active_tab_id: TabId,
|
||||
@@ -52,6 +54,7 @@ pub struct BrowserCore {
|
||||
profiles: Vec<Profile>,
|
||||
tabs: Vec<BrowserTab>,
|
||||
archived_tabs: Vec<ArchivedTab>,
|
||||
download_entries: Vec<DownloadEntry>,
|
||||
history_entries: Vec<HistoryEntry>,
|
||||
active_space_id: SpaceId,
|
||||
active_profile_id: ProfileId,
|
||||
@@ -93,6 +96,7 @@ impl BrowserCore {
|
||||
profiles: vec![profile],
|
||||
tabs: vec![tab],
|
||||
archived_tabs: Vec::new(),
|
||||
download_entries: Vec::new(),
|
||||
history_entries: Vec::new(),
|
||||
command_query: String::new(),
|
||||
new_tab_url,
|
||||
@@ -179,6 +183,7 @@ impl BrowserCore {
|
||||
favorites: self.favorites(),
|
||||
pinned_tabs: self.pinned_tabs(),
|
||||
archived_tabs: self.archived_tabs.clone(),
|
||||
download_entries: self.visible_downloads(),
|
||||
history_entries: self.visible_history(),
|
||||
spaces: self.spaces.clone(),
|
||||
tabs: self.visible_tabs(),
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ely_domain::{DownloadEntry, DownloadId, UrlText};
|
||||
|
||||
use crate::CoreError;
|
||||
|
||||
use super::BrowserCore;
|
||||
|
||||
impl BrowserCore {
|
||||
pub fn record_download_started(
|
||||
&mut self,
|
||||
source_url: UrlText,
|
||||
file_name: impl Into<String>,
|
||||
total_bytes: Option<u64>,
|
||||
) -> Result<DownloadId, CoreError> {
|
||||
let entry = DownloadEntry::started(
|
||||
self.active_profile_id.clone(),
|
||||
source_url,
|
||||
file_name,
|
||||
total_bytes,
|
||||
SystemTime::now(),
|
||||
)?;
|
||||
let download_id = entry.id().clone();
|
||||
self.download_entries.push(entry);
|
||||
Ok(download_id)
|
||||
}
|
||||
|
||||
pub(super) fn visible_downloads(&self) -> Vec<DownloadEntry> {
|
||||
self.download_entries
|
||||
.iter()
|
||||
.filter(|entry| entry.profile_id() == &self.active_profile_id)
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
use std::error::Error;
|
||||
|
||||
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
||||
use ely_domain::{ProfileKind, UrlText};
|
||||
|
||||
#[test]
|
||||
fn download_entries_stay_with_active_profile() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let default_profile_id = core.active_tab()?.profile_id().clone();
|
||||
|
||||
core.record_download_started(
|
||||
UrlText::parse("https://example.com/report.pdf")?,
|
||||
"report.pdf",
|
||||
Some(2048),
|
||||
)?;
|
||||
|
||||
let default_snapshot = core.snapshot()?;
|
||||
assert_eq!(default_snapshot.download_entries.len(), 1);
|
||||
assert_eq!(default_snapshot.download_entries[0].file_name(), "report.pdf");
|
||||
assert_eq!(default_snapshot.download_entries[0].profile_id(), &default_profile_id);
|
||||
|
||||
core.create_profile("Personal", 0xf54e00, ProfileKind::Standard)?;
|
||||
let personal_snapshot = core.snapshot()?;
|
||||
assert!(personal_snapshot.download_entries.is_empty());
|
||||
|
||||
core.record_download_started(
|
||||
UrlText::parse("https://example.com/archive.zip")?,
|
||||
"archive.zip",
|
||||
None,
|
||||
)?;
|
||||
assert_eq!(core.snapshot()?.download_entries.len(), 1);
|
||||
|
||||
core.select_profile(&default_profile_id)?;
|
||||
let default_snapshot = core.snapshot()?;
|
||||
assert_eq!(default_snapshot.download_entries.len(), 1);
|
||||
assert_eq!(default_snapshot.download_entries[0].file_name(), "report.pdf");
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user