Add bookmarks internal page
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
mod about;
|
mod about;
|
||||||
|
mod bookmarks;
|
||||||
mod download_actions;
|
mod download_actions;
|
||||||
mod download_labels;
|
mod download_labels;
|
||||||
mod downloads;
|
mod downloads;
|
||||||
@@ -25,6 +26,7 @@ impl ElyShell {
|
|||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> AnyElement {
|
) -> AnyElement {
|
||||||
match tab.url().as_str() {
|
match tab.url().as_str() {
|
||||||
|
"ely://bookmarks" => self.render_bookmarks_page(snapshot, cx),
|
||||||
"ely://downloads" => self.render_downloads_page(snapshot, cx),
|
"ely://downloads" => self.render_downloads_page(snapshot, cx),
|
||||||
"ely://history" => self.render_history_page(snapshot, cx),
|
"ely://history" => self.render_history_page(snapshot, cx),
|
||||||
"ely://archive" => self.render_archive_page(snapshot, cx),
|
"ely://archive" => self.render_archive_page(snapshot, cx),
|
||||||
|
|||||||
@@ -0,0 +1,162 @@
|
|||||||
|
use ely_browser_core::BrowserSnapshot;
|
||||||
|
use ely_design_system::colors;
|
||||||
|
use ely_domain::BookmarkEntry;
|
||||||
|
use gpui::{
|
||||||
|
AnyElement, Context, InteractiveElement, IntoElement, ParentElement, SharedString,
|
||||||
|
StatefulInteractiveElement, Styled, div, px, rgb,
|
||||||
|
};
|
||||||
|
use gpui_component::{IconName, StyledExt, scroll::ScrollableElement};
|
||||||
|
|
||||||
|
use super::{ElyShell, render_canvas_surface};
|
||||||
|
|
||||||
|
impl ElyShell {
|
||||||
|
pub(super) fn render_bookmarks_page(
|
||||||
|
&mut self,
|
||||||
|
snapshot: &BrowserSnapshot,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> AnyElement {
|
||||||
|
render_canvas_surface(
|
||||||
|
div()
|
||||||
|
.size_full()
|
||||||
|
.p_8()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_5()
|
||||||
|
.child(render_bookmarks_header(snapshot))
|
||||||
|
.child(self.render_bookmark_list(snapshot, cx)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_bookmark_list(
|
||||||
|
&mut self,
|
||||||
|
snapshot: &BrowserSnapshot,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> AnyElement {
|
||||||
|
if snapshot.bookmarks.is_empty() {
|
||||||
|
return div()
|
||||||
|
.flex_1()
|
||||||
|
.border_t_1()
|
||||||
|
.border_color(rgb(colors::HAIRLINE))
|
||||||
|
.pt_5()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(rgb(colors::MUTED))
|
||||||
|
.child("No bookmarks in this Profile.")
|
||||||
|
.into_any_element();
|
||||||
|
}
|
||||||
|
|
||||||
|
div()
|
||||||
|
.flex_1()
|
||||||
|
.min_h_0()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.overflow_y_scrollbar()
|
||||||
|
.border_t_1()
|
||||||
|
.border_color(rgb(colors::HAIRLINE))
|
||||||
|
.children(
|
||||||
|
snapshot
|
||||||
|
.bookmarks
|
||||||
|
.iter()
|
||||||
|
.rev()
|
||||||
|
.map(|bookmark| self.render_bookmark_row(bookmark, cx)),
|
||||||
|
)
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_bookmark_row(
|
||||||
|
&mut self,
|
||||||
|
bookmark: &BookmarkEntry,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> AnyElement {
|
||||||
|
let url = bookmark.url().clone();
|
||||||
|
|
||||||
|
div()
|
||||||
|
.id(SharedString::from(format!("bookmark-{}", bookmark.id().as_str())))
|
||||||
|
.py_3()
|
||||||
|
.border_b_1()
|
||||||
|
.border_color(rgb(colors::HAIRLINE))
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_between()
|
||||||
|
.gap_4()
|
||||||
|
.cursor_pointer()
|
||||||
|
.hover(|style| style.bg(rgb(colors::CANVAS_SOFT)))
|
||||||
|
.active(|style| style.opacity(0.82))
|
||||||
|
.on_click(cx.listener(move |shell, _, window, cx| {
|
||||||
|
shell.open_url(url.clone(), window, cx);
|
||||||
|
}))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.min_w_0()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.gap_3()
|
||||||
|
.child(div().text_color(rgb(colors::MUTED_SOFT)).child(IconName::BookOpen))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.min_w_0()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_1()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.font_semibold()
|
||||||
|
.truncate()
|
||||||
|
.text_color(rgb(colors::INK))
|
||||||
|
.child(bookmark.title().to_string()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.truncate()
|
||||||
|
.text_color(rgb(colors::MUTED))
|
||||||
|
.child(bookmark.display_url()),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.max_w(px(180.0))
|
||||||
|
.truncate()
|
||||||
|
.text_xs()
|
||||||
|
.font_semibold()
|
||||||
|
.text_color(rgb(colors::MUTED))
|
||||||
|
.child(bookmark.collection_name().to_string()),
|
||||||
|
)
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_bookmarks_header(snapshot: &BrowserSnapshot) -> AnyElement {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.items_end()
|
||||||
|
.justify_between()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_2()
|
||||||
|
.child(div().text_size(px(26.0)).text_color(rgb(colors::INK)).child("Bookmarks"))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(rgb(colors::MUTED))
|
||||||
|
.child(format!("Profile: {}", snapshot.active_profile_name)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(rgb(colors::MUTED))
|
||||||
|
.child(bookmark_count_label(snapshot.bookmarks.len())),
|
||||||
|
)
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bookmark_count_label(count: usize) -> String {
|
||||||
|
match count {
|
||||||
|
1 => "1 bookmark".to_string(),
|
||||||
|
count => format!("{count} bookmarks"),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -151,6 +151,7 @@ fn sync_object_kind_label(kind: &SyncObjectKind) -> &'static str {
|
|||||||
match kind {
|
match kind {
|
||||||
SyncObjectKind::Spaces => "Spaces",
|
SyncObjectKind::Spaces => "Spaces",
|
||||||
SyncObjectKind::Tabs => "Tabs",
|
SyncObjectKind::Tabs => "Tabs",
|
||||||
|
SyncObjectKind::Bookmarks => "Bookmarks",
|
||||||
SyncObjectKind::Profiles => "Profiles",
|
SyncObjectKind::Profiles => "Profiles",
|
||||||
SyncObjectKind::History => "History",
|
SyncObjectKind::History => "History",
|
||||||
SyncObjectKind::PluginSettings => "Plugin settings",
|
SyncObjectKind::PluginSettings => "Plugin settings",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub(crate) fn tab_title(url: &UrlText) -> String {
|
|||||||
fn internal_page_title(url: &str) -> Option<&'static str> {
|
fn internal_page_title(url: &str) -> Option<&'static str> {
|
||||||
match url {
|
match url {
|
||||||
"ely://new-tab" => Some("New Tab"),
|
"ely://new-tab" => Some("New Tab"),
|
||||||
|
"ely://bookmarks" => Some("Bookmarks"),
|
||||||
"ely://downloads" => Some("Downloads"),
|
"ely://downloads" => Some("Downloads"),
|
||||||
"ely://history" => Some("History"),
|
"ely://history" => Some("History"),
|
||||||
"ely://archive" => Some("Archived Tabs"),
|
"ely://archive" => Some("Archived Tabs"),
|
||||||
@@ -84,6 +85,10 @@ pub(crate) fn downloads_url() -> Result<UrlText, CoreError> {
|
|||||||
internal_page_url("ely://downloads")
|
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> {
|
pub(crate) fn history_url() -> Result<UrlText, CoreError> {
|
||||||
internal_page_url("ely://history")
|
internal_page_url("ely://history")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use ely_domain::{
|
use ely_domain::{
|
||||||
ArchivedTab, BrowserTab, DomainError, DownloadEntry, DownloadPolicy, HistoryEntry, Profile,
|
ArchivedTab, BookmarkEntry, BrowserTab, DomainError, DownloadEntry, DownloadPolicy,
|
||||||
ProfileId, ProfileKind, Space, SpaceId, SyncStatus, TabId, UrlText,
|
HistoryEntry, Profile, ProfileId, ProfileKind, Space, SpaceId, SyncStatus, TabId, UrlText,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::CoreError;
|
use crate::CoreError;
|
||||||
|
|
||||||
|
mod bookmarks;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod downloads;
|
mod downloads;
|
||||||
mod history;
|
mod history;
|
||||||
@@ -42,6 +43,7 @@ pub struct BrowserSnapshot {
|
|||||||
pub favorites: Vec<BrowserTab>,
|
pub favorites: Vec<BrowserTab>,
|
||||||
pub pinned_tabs: Vec<BrowserTab>,
|
pub pinned_tabs: Vec<BrowserTab>,
|
||||||
pub archived_tabs: Vec<ArchivedTab>,
|
pub archived_tabs: Vec<ArchivedTab>,
|
||||||
|
pub bookmarks: Vec<BookmarkEntry>,
|
||||||
pub download_entries: Vec<DownloadEntry>,
|
pub download_entries: Vec<DownloadEntry>,
|
||||||
pub history_entries: Vec<HistoryEntry>,
|
pub history_entries: Vec<HistoryEntry>,
|
||||||
pub installed_plugins: Vec<InstalledPlugin>,
|
pub installed_plugins: Vec<InstalledPlugin>,
|
||||||
@@ -64,6 +66,7 @@ pub struct BrowserCore {
|
|||||||
profiles: Vec<Profile>,
|
profiles: Vec<Profile>,
|
||||||
tabs: Vec<BrowserTab>,
|
tabs: Vec<BrowserTab>,
|
||||||
archived_tabs: Vec<ArchivedTab>,
|
archived_tabs: Vec<ArchivedTab>,
|
||||||
|
bookmarks: Vec<BookmarkEntry>,
|
||||||
download_entries: Vec<DownloadEntry>,
|
download_entries: Vec<DownloadEntry>,
|
||||||
history_entries: Vec<HistoryEntry>,
|
history_entries: Vec<HistoryEntry>,
|
||||||
installed_plugins: Vec<InstalledPlugin>,
|
installed_plugins: Vec<InstalledPlugin>,
|
||||||
@@ -108,6 +111,7 @@ impl BrowserCore {
|
|||||||
profiles: vec![profile],
|
profiles: vec![profile],
|
||||||
tabs: vec![tab],
|
tabs: vec![tab],
|
||||||
archived_tabs: Vec::new(),
|
archived_tabs: Vec::new(),
|
||||||
|
bookmarks: Vec::new(),
|
||||||
download_entries: Vec::new(),
|
download_entries: Vec::new(),
|
||||||
history_entries: Vec::new(),
|
history_entries: Vec::new(),
|
||||||
installed_plugins: Vec::new(),
|
installed_plugins: Vec::new(),
|
||||||
@@ -182,21 +186,14 @@ impl BrowserCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn snapshot(&self) -> Result<BrowserSnapshot, CoreError> {
|
pub fn snapshot(&self) -> Result<BrowserSnapshot, CoreError> {
|
||||||
let active_space = self
|
let active_space = self.active_space()?;
|
||||||
.spaces
|
let active_profile = self.active_profile()?;
|
||||||
.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)?;
|
|
||||||
|
|
||||||
Ok(BrowserSnapshot {
|
Ok(BrowserSnapshot {
|
||||||
favorites: self.favorites(),
|
favorites: self.favorites(),
|
||||||
pinned_tabs: self.pinned_tabs(),
|
pinned_tabs: self.pinned_tabs(),
|
||||||
archived_tabs: self.archived_tabs.clone(),
|
archived_tabs: self.archived_tabs.clone(),
|
||||||
|
bookmarks: self.visible_bookmarks(),
|
||||||
download_entries: self.visible_downloads(),
|
download_entries: self.visible_downloads(),
|
||||||
history_entries: self.visible_history(),
|
history_entries: self.visible_history(),
|
||||||
installed_plugins: self.installed_plugins.clone(),
|
installed_plugins: self.installed_plugins.clone(),
|
||||||
@@ -219,7 +216,14 @@ impl BrowserCore {
|
|||||||
self.profiles
|
self.profiles
|
||||||
.iter()
|
.iter()
|
||||||
.find(|profile| profile.id() == &self.active_profile_id)
|
.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> {
|
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::{
|
use crate::{
|
||||||
CoreError,
|
CoreError,
|
||||||
navigation::{
|
navigation::{
|
||||||
about_url, downloads_url, history_url, move_tab_space_name, new_profile_name,
|
about_url, bookmarks_url, downloads_url, history_url, move_tab_space_name,
|
||||||
new_space_name, search_url, settings_page_url, settings_url, space_icon,
|
new_profile_name, new_space_name, search_url, settings_page_url, settings_url, space_icon,
|
||||||
switch_profile_name, sync_status_url,
|
switch_profile_name, sync_status_url,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -51,6 +51,12 @@ impl BrowserCore {
|
|||||||
self.command_query.clear();
|
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 } => {
|
CommandIntent::ScopedSearch { scope: CommandScope::Settings, query } => {
|
||||||
if let Some(url) = settings_page_url(query)? {
|
if let Some(url) = settings_page_url(query)? {
|
||||||
self.open_tab(url);
|
self.open_tab(url);
|
||||||
@@ -102,6 +108,10 @@ impl BrowserCore {
|
|||||||
self.open_tab(downloads_url()?);
|
self.open_tab(downloads_url()?);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
"bookmarks" | "open-bookmarks" | "open bookmarks" => {
|
||||||
|
self.open_tab(bookmarks_url()?);
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
"history" | "open-history" | "open history" => {
|
"history" | "open-history" | "open history" => {
|
||||||
self.open_tab(history_url()?);
|
self.open_tab(history_url()?);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
@@ -126,6 +136,10 @@ impl BrowserCore {
|
|||||||
self.toggle_active_tab_favorite()?;
|
self.toggle_active_tab_favorite()?;
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
"bookmark" | "add-bookmark" | "add bookmark" => {
|
||||||
|
self.bookmark_active_tab()?;
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
"pin" | "pin-tab" | "toggle-pin" => {
|
"pin" | "pin-tab" | "toggle-pin" => {
|
||||||
self.toggle_active_tab_pinned()?;
|
self.toggle_active_tab_pinned()?;
|
||||||
Ok(true)
|
Ok(true)
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ impl BrowserCore {
|
|||||||
self.tabs.len(),
|
self.tabs.len(),
|
||||||
SyncObjectState::LocalOnly,
|
SyncObjectState::LocalOnly,
|
||||||
),
|
),
|
||||||
|
SyncObjectStatus::new(
|
||||||
|
SyncObjectKind::Bookmarks,
|
||||||
|
self.bookmarks.len(),
|
||||||
|
SyncObjectState::LocalOnly,
|
||||||
|
),
|
||||||
SyncObjectStatus::new(
|
SyncObjectStatus::new(
|
||||||
SyncObjectKind::Profiles,
|
SyncObjectKind::Profiles,
|
||||||
self.profiles.len(),
|
self.profiles.len(),
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
use std::error::Error;
|
||||||
|
|
||||||
|
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
||||||
|
use ely_domain::{CommandIntent, CommandScope, ProfileKind, UrlText};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bookmark_active_tab_records_current_context() -> Result<(), Box<dyn Error>> {
|
||||||
|
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
|
let tab_id = core.open_tab(UrlText::parse("https://example.com/research")?);
|
||||||
|
let active_profile_id = core.active_tab()?.profile_id().clone();
|
||||||
|
let active_space_id = core.active_tab()?.space_id().clone();
|
||||||
|
|
||||||
|
let bookmark_id = core.bookmark_active_tab()?;
|
||||||
|
let snapshot = core.snapshot()?;
|
||||||
|
let [bookmark] = snapshot.bookmarks.as_slice() else {
|
||||||
|
return Err(format!("expected 1 bookmark, got {}", snapshot.bookmarks.len()).into());
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(snapshot.active_tab_id, tab_id);
|
||||||
|
assert_eq!(bookmark.id(), &bookmark_id);
|
||||||
|
assert_eq!(bookmark.profile_id(), &active_profile_id);
|
||||||
|
assert_eq!(bookmark.space_id(), &active_space_id);
|
||||||
|
assert_eq!(bookmark.collection_name(), "Work");
|
||||||
|
assert_eq!(bookmark.title(), "example.com");
|
||||||
|
assert_eq!(bookmark.url().as_str(), "https://example.com/research");
|
||||||
|
assert!(bookmark.tags().is_empty());
|
||||||
|
assert_eq!(bookmark.note(), None);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bookmark_active_tab_reuses_existing_bookmark() -> Result<(), Box<dyn Error>> {
|
||||||
|
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
|
core.open_tab(UrlText::parse("https://example.com/research")?);
|
||||||
|
|
||||||
|
let first_id = core.bookmark_active_tab()?;
|
||||||
|
let second_id = core.bookmark_active_tab()?;
|
||||||
|
|
||||||
|
assert_eq!(first_id, second_id);
|
||||||
|
assert_eq!(core.snapshot()?.bookmarks.len(), 1);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bookmarks_scoped_search_opens_matching_bookmark() -> Result<(), Box<dyn Error>> {
|
||||||
|
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
|
core.open_tab(UrlText::parse("https://example.com/research")?);
|
||||||
|
core.bookmark_active_tab()?;
|
||||||
|
|
||||||
|
core.set_command_query("@bookmarks research");
|
||||||
|
let intent = core.submit_command()?;
|
||||||
|
let snapshot = core.snapshot()?;
|
||||||
|
let active_tab = core.active_tab()?;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
intent,
|
||||||
|
Some(CommandIntent::ScopedSearch {
|
||||||
|
scope: CommandScope::Bookmarks,
|
||||||
|
query: "research".to_string()
|
||||||
|
})
|
||||||
|
);
|
||||||
|
assert_eq!(active_tab.url().as_str(), "https://example.com/research");
|
||||||
|
assert_eq!(snapshot.command_query, "");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bookmarks_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();
|
||||||
|
let personal_profile_id = core.create_profile("Personal", 0xf54e00, ProfileKind::Standard)?;
|
||||||
|
|
||||||
|
core.open_tab(UrlText::parse("https://example.com/personal")?);
|
||||||
|
core.bookmark_active_tab()?;
|
||||||
|
core.select_profile(&default_profile_id)?;
|
||||||
|
|
||||||
|
core.set_command_query("@bookmarks personal");
|
||||||
|
let intent = core.submit_command()?;
|
||||||
|
let snapshot = core.snapshot()?;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
intent,
|
||||||
|
Some(CommandIntent::ScopedSearch {
|
||||||
|
scope: CommandScope::Bookmarks,
|
||||||
|
query: "personal".to_string()
|
||||||
|
})
|
||||||
|
);
|
||||||
|
assert_eq!(core.active_tab()?.profile_id(), &default_profile_id);
|
||||||
|
assert_ne!(core.active_tab()?.profile_id(), &personal_profile_id);
|
||||||
|
assert!(snapshot.bookmarks.is_empty());
|
||||||
|
assert_eq!(snapshot.command_query, "@bookmarks personal");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn open_bookmarks_command_opens_bookmarks_page() -> Result<(), Box<dyn Error>> {
|
||||||
|
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
|
|
||||||
|
core.set_command_query(">open-bookmarks");
|
||||||
|
let intent = core.submit_command()?;
|
||||||
|
let active_tab = core.active_tab()?;
|
||||||
|
|
||||||
|
assert_eq!(intent, Some(CommandIntent::Command("open-bookmarks".to_string())));
|
||||||
|
assert_eq!(active_tab.title(), "Bookmarks");
|
||||||
|
assert_eq!(active_tab.url().as_str(), "ely://bookmarks");
|
||||||
|
assert_eq!(core.snapshot()?.command_query, "");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ fn default_sync_status_reflects_local_browser_state() -> Result<(), Box<dyn Erro
|
|||||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
core.create_space("Research", "R", 0xf54e00)?;
|
core.create_space("Research", "R", 0xf54e00)?;
|
||||||
core.open_tab(UrlText::parse("https://example.com/research")?);
|
core.open_tab(UrlText::parse("https://example.com/research")?);
|
||||||
|
core.bookmark_active_tab()?;
|
||||||
|
|
||||||
let snapshot = core.snapshot()?;
|
let snapshot = core.snapshot()?;
|
||||||
let status = &snapshot.sync_status;
|
let status = &snapshot.sync_status;
|
||||||
@@ -20,6 +21,7 @@ fn default_sync_status_reflects_local_browser_state() -> Result<(), Box<dyn Erro
|
|||||||
&[
|
&[
|
||||||
SyncObjectStatus::new(SyncObjectKind::Spaces, 2, SyncObjectState::LocalOnly),
|
SyncObjectStatus::new(SyncObjectKind::Spaces, 2, SyncObjectState::LocalOnly),
|
||||||
SyncObjectStatus::new(SyncObjectKind::Tabs, 3, SyncObjectState::LocalOnly),
|
SyncObjectStatus::new(SyncObjectKind::Tabs, 3, SyncObjectState::LocalOnly),
|
||||||
|
SyncObjectStatus::new(SyncObjectKind::Bookmarks, 1, SyncObjectState::LocalOnly),
|
||||||
SyncObjectStatus::new(SyncObjectKind::Profiles, 1, SyncObjectState::LocalOnly),
|
SyncObjectStatus::new(SyncObjectKind::Profiles, 1, SyncObjectState::LocalOnly),
|
||||||
SyncObjectStatus::new(SyncObjectKind::History, 1, SyncObjectState::PrivacyControlled),
|
SyncObjectStatus::new(SyncObjectKind::History, 1, SyncObjectState::PrivacyControlled),
|
||||||
SyncObjectStatus::new(SyncObjectKind::PluginSettings, 0, SyncObjectState::LocalOnly),
|
SyncObjectStatus::new(SyncObjectKind::PluginSettings, 0, SyncObjectState::LocalOnly),
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
use crate::{BookmarkId, DomainError, ProfileId, SpaceId, UrlText};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub struct BookmarkEntry {
|
||||||
|
id: BookmarkId,
|
||||||
|
profile_id: ProfileId,
|
||||||
|
space_id: SpaceId,
|
||||||
|
collection_name: String,
|
||||||
|
title: String,
|
||||||
|
url: UrlText,
|
||||||
|
tags: Vec<String>,
|
||||||
|
note: Option<String>,
|
||||||
|
added_at: SystemTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BookmarkEntry {
|
||||||
|
pub fn new(
|
||||||
|
profile_id: ProfileId,
|
||||||
|
space_id: SpaceId,
|
||||||
|
collection_name: impl Into<String>,
|
||||||
|
title: impl Into<String>,
|
||||||
|
url: UrlText,
|
||||||
|
added_at: SystemTime,
|
||||||
|
) -> Result<Self, DomainError> {
|
||||||
|
let collection_name = non_empty_text("bookmark collection", collection_name.into())?;
|
||||||
|
let title = non_empty_text("bookmark title", title.into())?;
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
id: BookmarkId::new(),
|
||||||
|
profile_id,
|
||||||
|
space_id,
|
||||||
|
collection_name,
|
||||||
|
title,
|
||||||
|
url,
|
||||||
|
tags: Vec::new(),
|
||||||
|
note: None,
|
||||||
|
added_at,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn id(&self) -> &BookmarkId {
|
||||||
|
&self.id
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn profile_id(&self) -> &ProfileId {
|
||||||
|
&self.profile_id
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn space_id(&self) -> &SpaceId {
|
||||||
|
&self.space_id
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn collection_name(&self) -> &str {
|
||||||
|
&self.collection_name
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn title(&self) -> &str {
|
||||||
|
&self.title
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn url(&self) -> &UrlText {
|
||||||
|
&self.url
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn display_url(&self) -> String {
|
||||||
|
self.url.display_url()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn tags(&self) -> &[String] {
|
||||||
|
&self.tags
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn note(&self) -> Option<&str> {
|
||||||
|
self.note.as_deref()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn added_at(&self) -> SystemTime {
|
||||||
|
self.added_at
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn non_empty_text(field: &'static str, value: String) -> Result<String, DomainError> {
|
||||||
|
let trimmed = value.trim();
|
||||||
|
if trimmed.is_empty() {
|
||||||
|
return Err(DomainError::EmptyField { field });
|
||||||
|
}
|
||||||
|
Ok(trimmed.to_string())
|
||||||
|
}
|
||||||
@@ -39,3 +39,4 @@ entity_id!(ProfileId, "profile");
|
|||||||
entity_id!(SplitId, "split");
|
entity_id!(SplitId, "split");
|
||||||
entity_id!(WebViewId, "webview");
|
entity_id!(WebViewId, "webview");
|
||||||
entity_id!(DownloadId, "download");
|
entity_id!(DownloadId, "download");
|
||||||
|
entity_id!(BookmarkId, "bookmark");
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
mod archive;
|
mod archive;
|
||||||
|
mod bookmark;
|
||||||
mod command;
|
mod command;
|
||||||
mod download;
|
mod download;
|
||||||
mod error;
|
mod error;
|
||||||
@@ -13,6 +14,7 @@ mod tab;
|
|||||||
mod url_text;
|
mod url_text;
|
||||||
|
|
||||||
pub use archive::{ArchiveSource, ArchivedTab};
|
pub use archive::{ArchiveSource, ArchivedTab};
|
||||||
|
pub use bookmark::BookmarkEntry;
|
||||||
pub use command::{CommandIntent, CommandScope};
|
pub use command::{CommandIntent, CommandScope};
|
||||||
pub use download::{
|
pub use download::{
|
||||||
DownloadChecksum, DownloadChecksumAlgorithm, DownloadDestination, DownloadEntry,
|
DownloadChecksum, DownloadChecksumAlgorithm, DownloadDestination, DownloadEntry,
|
||||||
@@ -20,7 +22,7 @@ pub use download::{
|
|||||||
};
|
};
|
||||||
pub use error::DomainError;
|
pub use error::DomainError;
|
||||||
pub use history::HistoryEntry;
|
pub use history::HistoryEntry;
|
||||||
pub use identifiers::{DownloadId, ProfileId, SpaceId, SplitId, TabId, WebViewId};
|
pub use identifiers::{BookmarkId, DownloadId, ProfileId, SpaceId, SplitId, TabId, WebViewId};
|
||||||
pub use plugin::{
|
pub use plugin::{
|
||||||
PluginContributionPoint, PluginId, PluginManifest, PluginPermission, PluginPermissionRisk,
|
PluginContributionPoint, PluginId, PluginManifest, PluginPermission, PluginPermissionRisk,
|
||||||
PluginSignature, PluginSignatureAlgorithm,
|
PluginSignature, PluginSignatureAlgorithm,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ pub enum SyncConnectionState {
|
|||||||
pub enum SyncObjectKind {
|
pub enum SyncObjectKind {
|
||||||
Spaces,
|
Spaces,
|
||||||
Tabs,
|
Tabs,
|
||||||
|
Bookmarks,
|
||||||
Profiles,
|
Profiles,
|
||||||
History,
|
History,
|
||||||
PluginSettings,
|
PluginSettings,
|
||||||
|
|||||||
Reference in New Issue
Block a user