Add reading list internal page
This commit is contained in:
@@ -17,6 +17,7 @@ fn internal_page_title(url: &str) -> Option<&'static str> {
|
||||
match url {
|
||||
"ely://new-tab" => Some("New Tab"),
|
||||
"ely://bookmarks" => Some("Bookmarks"),
|
||||
"ely://reading-list" => Some("Reading List"),
|
||||
"ely://downloads" => Some("Downloads"),
|
||||
"ely://history" => Some("History"),
|
||||
"ely://archive" => Some("Archived Tabs"),
|
||||
@@ -89,6 +90,10 @@ pub(crate) fn bookmarks_url() -> Result<UrlText, CoreError> {
|
||||
internal_page_url("ely://bookmarks")
|
||||
}
|
||||
|
||||
pub(crate) fn reading_list_url() -> Result<UrlText, CoreError> {
|
||||
internal_page_url("ely://reading-list")
|
||||
}
|
||||
|
||||
pub(crate) fn history_url() -> Result<UrlText, CoreError> {
|
||||
internal_page_url("ely://history")
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ use std::collections::BTreeMap;
|
||||
|
||||
use ely_domain::{
|
||||
ArchivedTab, BookmarkEntry, BrowserTab, DomainError, DownloadEntry, DownloadPolicy,
|
||||
HistoryEntry, Profile, ProfileId, ProfileKind, Space, SpaceId, SyncStatus, TabId, UrlText,
|
||||
HistoryEntry, Profile, ProfileId, ProfileKind, ReadingListEntry, Space, SpaceId, SyncStatus,
|
||||
TabId, UrlText,
|
||||
};
|
||||
|
||||
use crate::CoreError;
|
||||
@@ -13,6 +14,7 @@ mod downloads;
|
||||
mod history;
|
||||
mod plugins;
|
||||
mod profiles;
|
||||
mod reading_list;
|
||||
mod sync;
|
||||
mod tabs;
|
||||
|
||||
@@ -44,6 +46,7 @@ pub struct BrowserSnapshot {
|
||||
pub pinned_tabs: Vec<BrowserTab>,
|
||||
pub archived_tabs: Vec<ArchivedTab>,
|
||||
pub bookmarks: Vec<BookmarkEntry>,
|
||||
pub reading_list: Vec<ReadingListEntry>,
|
||||
pub download_entries: Vec<DownloadEntry>,
|
||||
pub history_entries: Vec<HistoryEntry>,
|
||||
pub installed_plugins: Vec<InstalledPlugin>,
|
||||
@@ -67,6 +70,7 @@ pub struct BrowserCore {
|
||||
tabs: Vec<BrowserTab>,
|
||||
archived_tabs: Vec<ArchivedTab>,
|
||||
bookmarks: Vec<BookmarkEntry>,
|
||||
reading_list: Vec<ReadingListEntry>,
|
||||
download_entries: Vec<DownloadEntry>,
|
||||
history_entries: Vec<HistoryEntry>,
|
||||
installed_plugins: Vec<InstalledPlugin>,
|
||||
@@ -112,6 +116,7 @@ impl BrowserCore {
|
||||
tabs: vec![tab],
|
||||
archived_tabs: Vec::new(),
|
||||
bookmarks: Vec::new(),
|
||||
reading_list: Vec::new(),
|
||||
download_entries: Vec::new(),
|
||||
history_entries: Vec::new(),
|
||||
installed_plugins: Vec::new(),
|
||||
@@ -194,6 +199,7 @@ impl BrowserCore {
|
||||
pinned_tabs: self.pinned_tabs(),
|
||||
archived_tabs: self.archived_tabs.clone(),
|
||||
bookmarks: self.visible_bookmarks(),
|
||||
reading_list: self.visible_reading_list(),
|
||||
download_entries: self.visible_downloads(),
|
||||
history_entries: self.visible_history(),
|
||||
installed_plugins: self.installed_plugins.clone(),
|
||||
|
||||
@@ -4,8 +4,8 @@ use crate::{
|
||||
CoreError,
|
||||
navigation::{
|
||||
about_url, bookmarks_url, downloads_url, history_url, move_tab_space_name,
|
||||
new_profile_name, new_space_name, search_url, settings_page_url, settings_url, space_icon,
|
||||
switch_profile_name, sync_status_url,
|
||||
new_profile_name, new_space_name, reading_list_url, search_url, settings_page_url,
|
||||
settings_url, space_icon, switch_profile_name, sync_status_url,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -57,6 +57,12 @@ impl BrowserCore {
|
||||
self.command_query.clear();
|
||||
}
|
||||
}
|
||||
CommandIntent::ScopedSearch { scope: CommandScope::ReadingList, query } => {
|
||||
if let Some(url) = self.find_reading_list_match(query) {
|
||||
self.open_tab(url);
|
||||
self.command_query.clear();
|
||||
}
|
||||
}
|
||||
CommandIntent::ScopedSearch { scope: CommandScope::Settings, query } => {
|
||||
if let Some(url) = settings_page_url(query)? {
|
||||
self.open_tab(url);
|
||||
@@ -112,6 +118,10 @@ impl BrowserCore {
|
||||
self.open_tab(bookmarks_url()?);
|
||||
Ok(true)
|
||||
}
|
||||
"reading-list" | "open-reading-list" | "open reading list" => {
|
||||
self.open_tab(reading_list_url()?);
|
||||
Ok(true)
|
||||
}
|
||||
"history" | "open-history" | "open history" => {
|
||||
self.open_tab(history_url()?);
|
||||
Ok(true)
|
||||
@@ -140,6 +150,10 @@ impl BrowserCore {
|
||||
self.bookmark_active_tab()?;
|
||||
Ok(true)
|
||||
}
|
||||
"save-reading-list" | "save reading list" | "read-later" | "read later" => {
|
||||
self.save_active_tab_to_reading_list()?;
|
||||
Ok(true)
|
||||
}
|
||||
"pin" | "pin-tab" | "toggle-pin" => {
|
||||
self.toggle_active_tab_pinned()?;
|
||||
Ok(true)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ely_domain::{ReadingListEntry, ReadingListId, UrlText};
|
||||
|
||||
use crate::CoreError;
|
||||
|
||||
use super::BrowserCore;
|
||||
|
||||
impl BrowserCore {
|
||||
pub fn save_active_tab_to_reading_list(&mut self) -> Result<ReadingListId, CoreError> {
|
||||
let active_tab = self.active_tab()?.clone();
|
||||
if let Some(entry) = self.reading_list.iter().find(|entry| {
|
||||
entry.profile_id() == active_tab.profile_id() && entry.source_url() == active_tab.url()
|
||||
}) {
|
||||
return Ok(entry.id().clone());
|
||||
}
|
||||
|
||||
let entry = ReadingListEntry::new(
|
||||
active_tab.profile_id().clone(),
|
||||
active_tab.space_id().clone(),
|
||||
active_tab.title(),
|
||||
active_tab.url().clone(),
|
||||
SystemTime::now(),
|
||||
)?;
|
||||
let entry_id = entry.id().clone();
|
||||
self.reading_list.push(entry);
|
||||
Ok(entry_id)
|
||||
}
|
||||
|
||||
pub(super) fn find_reading_list_match(&self, query: &str) -> Option<UrlText> {
|
||||
let normalized_query = query.trim().to_lowercase();
|
||||
if normalized_query.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.reading_list
|
||||
.iter()
|
||||
.rev()
|
||||
.filter(|entry| entry.profile_id() == &self.active_profile_id)
|
||||
.find(|entry| reading_list_entry_matches_query(entry, &normalized_query))
|
||||
.map(|entry| entry.source_url().clone())
|
||||
}
|
||||
|
||||
pub(super) fn visible_reading_list(&self) -> Vec<ReadingListEntry> {
|
||||
self.reading_list
|
||||
.iter()
|
||||
.filter(|entry| entry.profile_id() == &self.active_profile_id)
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
fn reading_list_entry_matches_query(entry: &ReadingListEntry, normalized_query: &str) -> bool {
|
||||
entry.title().to_lowercase().contains(normalized_query)
|
||||
|| entry.source_url().as_str().to_lowercase().contains(normalized_query)
|
||||
|| entry.display_url().to_lowercase().contains(normalized_query)
|
||||
}
|
||||
@@ -20,6 +20,11 @@ impl BrowserCore {
|
||||
self.bookmarks.len(),
|
||||
SyncObjectState::LocalOnly,
|
||||
),
|
||||
SyncObjectStatus::new(
|
||||
SyncObjectKind::ReadingList,
|
||||
self.reading_list.len(),
|
||||
SyncObjectState::LocalOnly,
|
||||
),
|
||||
SyncObjectStatus::new(
|
||||
SyncObjectKind::Profiles,
|
||||
self.profiles.len(),
|
||||
|
||||
Reference in New Issue
Block a user