Add bookmarks internal page
This commit is contained in:
@@ -16,6 +16,7 @@ pub(crate) fn tab_title(url: &UrlText) -> String {
|
||||
fn internal_page_title(url: &str) -> Option<&'static str> {
|
||||
match url {
|
||||
"ely://new-tab" => Some("New Tab"),
|
||||
"ely://bookmarks" => Some("Bookmarks"),
|
||||
"ely://downloads" => Some("Downloads"),
|
||||
"ely://history" => Some("History"),
|
||||
"ely://archive" => Some("Archived Tabs"),
|
||||
@@ -84,6 +85,10 @@ pub(crate) fn downloads_url() -> Result<UrlText, CoreError> {
|
||||
internal_page_url("ely://downloads")
|
||||
}
|
||||
|
||||
pub(crate) fn bookmarks_url() -> Result<UrlText, CoreError> {
|
||||
internal_page_url("ely://bookmarks")
|
||||
}
|
||||
|
||||
pub(crate) fn history_url() -> Result<UrlText, CoreError> {
|
||||
internal_page_url("ely://history")
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ely_domain::{
|
||||
ArchivedTab, BrowserTab, DomainError, DownloadEntry, DownloadPolicy, HistoryEntry, Profile,
|
||||
ProfileId, ProfileKind, Space, SpaceId, SyncStatus, TabId, UrlText,
|
||||
ArchivedTab, BookmarkEntry, BrowserTab, DomainError, DownloadEntry, DownloadPolicy,
|
||||
HistoryEntry, Profile, ProfileId, ProfileKind, Space, SpaceId, SyncStatus, TabId, UrlText,
|
||||
};
|
||||
|
||||
use crate::CoreError;
|
||||
|
||||
mod bookmarks;
|
||||
mod commands;
|
||||
mod downloads;
|
||||
mod history;
|
||||
@@ -42,6 +43,7 @@ pub struct BrowserSnapshot {
|
||||
pub favorites: Vec<BrowserTab>,
|
||||
pub pinned_tabs: Vec<BrowserTab>,
|
||||
pub archived_tabs: Vec<ArchivedTab>,
|
||||
pub bookmarks: Vec<BookmarkEntry>,
|
||||
pub download_entries: Vec<DownloadEntry>,
|
||||
pub history_entries: Vec<HistoryEntry>,
|
||||
pub installed_plugins: Vec<InstalledPlugin>,
|
||||
@@ -64,6 +66,7 @@ pub struct BrowserCore {
|
||||
profiles: Vec<Profile>,
|
||||
tabs: Vec<BrowserTab>,
|
||||
archived_tabs: Vec<ArchivedTab>,
|
||||
bookmarks: Vec<BookmarkEntry>,
|
||||
download_entries: Vec<DownloadEntry>,
|
||||
history_entries: Vec<HistoryEntry>,
|
||||
installed_plugins: Vec<InstalledPlugin>,
|
||||
@@ -108,6 +111,7 @@ impl BrowserCore {
|
||||
profiles: vec![profile],
|
||||
tabs: vec![tab],
|
||||
archived_tabs: Vec::new(),
|
||||
bookmarks: Vec::new(),
|
||||
download_entries: Vec::new(),
|
||||
history_entries: Vec::new(),
|
||||
installed_plugins: Vec::new(),
|
||||
@@ -182,21 +186,14 @@ impl BrowserCore {
|
||||
}
|
||||
|
||||
pub fn snapshot(&self) -> Result<BrowserSnapshot, CoreError> {
|
||||
let active_space = self
|
||||
.spaces
|
||||
.iter()
|
||||
.find(|space| space.id() == &self.active_space_id)
|
||||
.ok_or(CoreError::MissingActiveTab)?;
|
||||
let active_profile = self
|
||||
.profiles
|
||||
.iter()
|
||||
.find(|profile| profile.id() == &self.active_profile_id)
|
||||
.ok_or(CoreError::MissingActiveTab)?;
|
||||
let active_space = self.active_space()?;
|
||||
let active_profile = self.active_profile()?;
|
||||
|
||||
Ok(BrowserSnapshot {
|
||||
favorites: self.favorites(),
|
||||
pinned_tabs: self.pinned_tabs(),
|
||||
archived_tabs: self.archived_tabs.clone(),
|
||||
bookmarks: self.visible_bookmarks(),
|
||||
download_entries: self.visible_downloads(),
|
||||
history_entries: self.visible_history(),
|
||||
installed_plugins: self.installed_plugins.clone(),
|
||||
@@ -219,7 +216,14 @@ impl BrowserCore {
|
||||
self.profiles
|
||||
.iter()
|
||||
.find(|profile| profile.id() == &self.active_profile_id)
|
||||
.ok_or(CoreError::MissingActiveTab)
|
||||
.ok_or_else(|| CoreError::ProfileNotFound { id: self.active_profile_id.clone() })
|
||||
}
|
||||
|
||||
fn active_space(&self) -> Result<&Space, CoreError> {
|
||||
self.spaces
|
||||
.iter()
|
||||
.find(|space| space.id() == &self.active_space_id)
|
||||
.ok_or_else(|| CoreError::SpaceNotFound { id: self.active_space_id.clone() })
|
||||
}
|
||||
|
||||
fn favorites(&self) -> Vec<BrowserTab> {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ely_domain::{BookmarkEntry, BookmarkId, UrlText};
|
||||
|
||||
use crate::CoreError;
|
||||
|
||||
use super::BrowserCore;
|
||||
|
||||
impl BrowserCore {
|
||||
pub fn bookmark_active_tab(&mut self) -> Result<BookmarkId, CoreError> {
|
||||
let active_tab = self.active_tab()?.clone();
|
||||
if let Some(bookmark) = self.bookmarks.iter().find(|bookmark| {
|
||||
bookmark.profile_id() == active_tab.profile_id()
|
||||
&& bookmark.space_id() == active_tab.space_id()
|
||||
&& bookmark.url() == active_tab.url()
|
||||
}) {
|
||||
return Ok(bookmark.id().clone());
|
||||
}
|
||||
|
||||
let collection_name = self.active_space()?.name().to_string();
|
||||
let bookmark = BookmarkEntry::new(
|
||||
active_tab.profile_id().clone(),
|
||||
active_tab.space_id().clone(),
|
||||
collection_name,
|
||||
active_tab.title(),
|
||||
active_tab.url().clone(),
|
||||
SystemTime::now(),
|
||||
)?;
|
||||
let bookmark_id = bookmark.id().clone();
|
||||
self.bookmarks.push(bookmark);
|
||||
Ok(bookmark_id)
|
||||
}
|
||||
|
||||
pub(super) fn find_bookmark_match(&self, query: &str) -> Option<UrlText> {
|
||||
let normalized_query = query.trim().to_lowercase();
|
||||
if normalized_query.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.bookmarks
|
||||
.iter()
|
||||
.rev()
|
||||
.filter(|bookmark| bookmark.profile_id() == &self.active_profile_id)
|
||||
.find(|bookmark| bookmark_matches_query(bookmark, &normalized_query))
|
||||
.map(|bookmark| bookmark.url().clone())
|
||||
}
|
||||
|
||||
pub(super) fn visible_bookmarks(&self) -> Vec<BookmarkEntry> {
|
||||
self.bookmarks
|
||||
.iter()
|
||||
.filter(|bookmark| bookmark.profile_id() == &self.active_profile_id)
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
fn bookmark_matches_query(bookmark: &BookmarkEntry, normalized_query: &str) -> bool {
|
||||
bookmark.title().to_lowercase().contains(normalized_query)
|
||||
|| bookmark.url().as_str().to_lowercase().contains(normalized_query)
|
||||
|| bookmark.display_url().to_lowercase().contains(normalized_query)
|
||||
|| bookmark.collection_name().to_lowercase().contains(normalized_query)
|
||||
|| bookmark.tags().iter().any(|tag| tag.to_lowercase().contains(normalized_query))
|
||||
|| bookmark.note().is_some_and(|note| note.to_lowercase().contains(normalized_query))
|
||||
}
|
||||
@@ -3,8 +3,8 @@ use ely_domain::{CommandIntent, CommandScope, ProfileId, ProfileKind, SpaceId};
|
||||
use crate::{
|
||||
CoreError,
|
||||
navigation::{
|
||||
about_url, downloads_url, history_url, move_tab_space_name, new_profile_name,
|
||||
new_space_name, search_url, settings_page_url, settings_url, space_icon,
|
||||
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,
|
||||
},
|
||||
};
|
||||
@@ -51,6 +51,12 @@ impl BrowserCore {
|
||||
self.command_query.clear();
|
||||
}
|
||||
}
|
||||
CommandIntent::ScopedSearch { scope: CommandScope::Bookmarks, query } => {
|
||||
if let Some(url) = self.find_bookmark_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);
|
||||
@@ -102,6 +108,10 @@ impl BrowserCore {
|
||||
self.open_tab(downloads_url()?);
|
||||
Ok(true)
|
||||
}
|
||||
"bookmarks" | "open-bookmarks" | "open bookmarks" => {
|
||||
self.open_tab(bookmarks_url()?);
|
||||
Ok(true)
|
||||
}
|
||||
"history" | "open-history" | "open history" => {
|
||||
self.open_tab(history_url()?);
|
||||
Ok(true)
|
||||
@@ -126,6 +136,10 @@ impl BrowserCore {
|
||||
self.toggle_active_tab_favorite()?;
|
||||
Ok(true)
|
||||
}
|
||||
"bookmark" | "add-bookmark" | "add bookmark" => {
|
||||
self.bookmark_active_tab()?;
|
||||
Ok(true)
|
||||
}
|
||||
"pin" | "pin-tab" | "toggle-pin" => {
|
||||
self.toggle_active_tab_pinned()?;
|
||||
Ok(true)
|
||||
|
||||
@@ -15,6 +15,11 @@ impl BrowserCore {
|
||||
self.tabs.len(),
|
||||
SyncObjectState::LocalOnly,
|
||||
),
|
||||
SyncObjectStatus::new(
|
||||
SyncObjectKind::Bookmarks,
|
||||
self.bookmarks.len(),
|
||||
SyncObjectState::LocalOnly,
|
||||
),
|
||||
SyncObjectStatus::new(
|
||||
SyncObjectKind::Profiles,
|
||||
self.profiles.len(),
|
||||
|
||||
Reference in New Issue
Block a user