Add general new tab settings

This commit is contained in:
2026-05-08 03:13:37 -04:00
parent 6750f60d52
commit 4bdbf5e0c5
14 changed files with 369 additions and 22 deletions
+3 -1
View File
@@ -25,6 +25,7 @@ fn internal_page_title(url: &str) -> Option<&'static str> {
url if SiteOrigin::from_site_route(url).ok().flatten().is_some() => Some("Site Settings"),
"ely://about" => Some("About ELY Browser"),
"ely://settings" => Some("Settings"),
"ely://settings/general" => Some("General Settings"),
"ely://settings/sidebar-tabs" => Some("Sidebar & Tabs Settings"),
"ely://settings/search" => Some("Search Settings"),
"ely://settings/spaces" => Some("Space Settings"),
@@ -154,7 +155,8 @@ pub(crate) fn settings_page_url(query: &str) -> Result<Option<UrlText>, CoreErro
fn settings_page_route(query: &str) -> Option<&'static str> {
match query {
"settings" | "general" | "browser" => Some("ely://settings"),
"settings" => Some("ely://settings"),
"general" | "browser" | "new tab" | "new-tab" | "startup" => Some("ely://settings/general"),
"about" | "about ely browser" => Some("ely://about"),
"sidebar" | "tabs" | "sidebar tabs" | "sidebar & tabs" => {
Some("ely://settings/sidebar-tabs")
+29 -12
View File
@@ -2,12 +2,12 @@ use std::{collections::BTreeMap, time::SystemTime};
use ely_domain::{
ArchivePolicy, ArchivedTab, BookmarkEntry, BrowserTab, DomainError, DownloadEntry,
DownloadPolicy, HistoryEntry, Profile, ProfileId, ProfileKind, ReadingListEntry, SearchEngine,
SitePermissionAuditEvent, SitePermissionEntry, Space, SpaceId, SplitLayout, SyncStatus, TabId,
UrlText,
DownloadPolicy, HistoryEntry, NewTabDestination, Profile, ProfileId, ProfileKind,
ReadingListEntry, SearchEngine, SitePermissionAuditEvent, SitePermissionEntry, Space, SpaceId,
SplitLayout, SyncStatus, TabId, UrlText,
};
use crate::CoreError;
use crate::{CoreError, navigation::tab_title};
mod bookmarks;
mod commands;
@@ -28,7 +28,7 @@ pub struct InitialBrowserConfig {
pub space_name: String,
pub space_icon: String,
pub profile_name: String,
pub initial_url: UrlText,
pub new_tab_destination: NewTabDestination,
}
impl InitialBrowserConfig {
@@ -37,7 +37,7 @@ impl InitialBrowserConfig {
space_name: "Work".to_string(),
space_icon: "W".to_string(),
profile_name: "Default".to_string(),
initial_url: UrlText::parse("ely://new-tab")?,
new_tab_destination: NewTabDestination::default(),
})
}
}
@@ -67,6 +67,7 @@ pub struct BrowserSnapshot {
pub active_profile_name: String,
pub active_download_policy: DownloadPolicy,
pub search_engine: SearchEngine,
pub new_tab_destination: NewTabDestination,
pub command_query: String,
}
@@ -92,22 +93,24 @@ pub struct BrowserCore {
active_tabs_by_space: BTreeMap<SpaceId, TabId>,
active_tabs_by_space_profile: BTreeMap<(SpaceId, ProfileId), TabId>,
search_engine: SearchEngine,
new_tab_destination: NewTabDestination,
command_query: String,
new_tab_url: UrlText,
}
impl BrowserCore {
pub fn new(config: InitialBrowserConfig) -> Result<Self, CoreError> {
let space = Space::new(config.space_name, config.space_icon, 0xf54e00);
let profile = Profile::new(config.profile_name, 0x26251e, ProfileKind::Standard);
let new_tab_url = config.initial_url;
let new_tab_destination = config.new_tab_destination;
let new_tab_url = new_tab_destination.url()?;
let new_tab_title = tab_title(&new_tab_url);
let active_space_id = space.id().clone();
let active_profile_id = profile.id().clone();
let tab = BrowserTab::new(
TabId::new(),
active_space_id.clone(),
active_profile_id.clone(),
"New Tab",
new_tab_title,
new_tab_url.clone(),
);
let active_tab_id = tab.id().clone();
@@ -124,6 +127,7 @@ impl BrowserCore {
active_tabs_by_space,
active_tabs_by_space_profile,
search_engine: SearchEngine::default(),
new_tab_destination,
spaces: vec![space],
profiles: vec![profile],
tabs: vec![tab],
@@ -139,7 +143,6 @@ impl BrowserCore {
installed_plugins: Vec::new(),
plugin_audit_events: Vec::new(),
command_query: String::new(),
new_tab_url,
})
}
@@ -154,7 +157,7 @@ impl BrowserCore {
let tab = self.build_tab_for(
space_id.clone(),
self.active_profile_id.clone(),
self.new_tab_url.clone(),
self.new_tab_url()?,
);
let tab_id = tab.id().clone();
@@ -190,7 +193,7 @@ impl BrowserCore {
let tab = self.build_tab_for(
space_id.clone(),
self.active_profile_id.clone(),
self.new_tab_url.clone(),
self.new_tab_url()?,
);
let tab_id = tab.id().clone();
self.tabs.push(tab);
@@ -229,6 +232,15 @@ impl BrowserCore {
self.search_engine
}
pub fn set_new_tab_destination(&mut self, destination: NewTabDestination) {
self.new_tab_destination = destination;
}
#[must_use]
pub fn new_tab_destination(&self) -> NewTabDestination {
self.new_tab_destination
}
pub fn set_command_query(&mut self, query: impl Into<String>) {
self.command_query = query.into();
}
@@ -266,10 +278,15 @@ impl BrowserCore {
active_profile_name: active_profile.name().to_string(),
active_download_policy: active_profile.download_policy().clone(),
search_engine: self.search_engine,
new_tab_destination: self.new_tab_destination,
command_query: self.command_query.clone(),
})
}
pub(super) fn new_tab_url(&self) -> Result<UrlText, CoreError> {
self.new_tab_destination.url().map_err(CoreError::from)
}
fn active_profile(&self) -> Result<&Profile, CoreError> {
self.profiles
.iter()
@@ -126,7 +126,7 @@ impl BrowserCore {
match command.to_ascii_lowercase().as_str() {
"new-tab" => {
self.open_tab(self.new_tab_url.clone());
self.open_new_tab()?;
Ok(true)
}
"split-right" | "split right" => {
@@ -53,7 +53,7 @@ impl BrowserCore {
let tab = self.build_tab_for(
self.active_space_id.clone(),
profile_id.clone(),
self.new_tab_url.clone(),
self.new_tab_url()?,
);
let tab_id = tab.id().clone();
let insert_index = self
+2 -2
View File
@@ -75,7 +75,7 @@ impl BrowserCore {
let active_profile_id = self.tabs[active_index].profile_id().clone();
let split_id = self.split_id_for_new_pane(&active_tab_id)?;
let mut new_tab =
self.build_tab_for(active_space_id, active_profile_id, self.new_tab_url.clone());
self.build_tab_for(active_space_id, active_profile_id, self.new_tab_url()?);
let new_tab_id = new_tab.id().clone();
new_tab.set_split_id(split_id.clone());
@@ -276,7 +276,7 @@ impl BrowserCore {
let replacement = self.build_tab_for(
closed_space_id.clone(),
closed_profile_id.clone(),
self.new_tab_url.clone(),
self.new_tab_url()?,
);
let replacement_id = replacement.id().clone();
self.tabs.insert(start_index.min(self.tabs.len()), replacement);
+7 -2
View File
@@ -14,6 +14,11 @@ use super::BrowserCore;
const DEFAULT_FAVORITE_LIMIT: usize = 12;
impl BrowserCore {
pub fn open_new_tab(&mut self) -> Result<TabId, CoreError> {
let url = self.new_tab_url()?;
Ok(self.open_tab(url))
}
pub fn open_tab(&mut self, url: UrlText) -> TabId {
let tab = self.build_tab(url);
let tab_id = tab.id().clone();
@@ -62,7 +67,7 @@ impl BrowserCore {
let tab = self.build_tab_for(
source_space_id.clone(),
self.active_profile_id.clone(),
self.new_tab_url.clone(),
self.new_tab_url()?,
);
let replacement_id = tab.id().clone();
self.tabs.insert(tab_index, tab);
@@ -125,7 +130,7 @@ impl BrowserCore {
let tab = self.build_tab_for(
closed_space_id.clone(),
closed_profile_id.clone(),
self.new_tab_url.clone(),
self.new_tab_url()?,
);
let replacement_id = tab.id().clone();
self.tabs.insert(close_index.min(self.tabs.len()), tab);