Nacre/src/ui/pages/settings.rs
2026-11-11 17:27:07 -06:00

1027 lines
52 KiB
Rust

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! nacre://settings — every setting, in the sections of the original Nacre.
//!
//! The page edits a copy of the settings and writes it back when something changed; the app
//! notices the change after the frame and applies it.
use egui::{RichText, Ui};
use super::super::widgets::{card, number, row, section, segmented, switch, switch_row};
use super::super::Frame;
use crate::actions::Command;
use crate::keys::{Action, Shortcut};
use crate::store::settings::*;
use crate::tabs::Page;
use crate::util;
const SECTIONS: &[(&str, &str)] = &[
("general", "General"),
("appearance", "Appearance"),
("toolbar", "Toolbar"),
("performance", "Performance"),
("privacy", "Privacy"),
("adblock", "Ad blocker"),
("passwords", "Passwords and autofill"),
("downloads", "Downloads"),
("media", "Media"),
("about", "About"),
];
/// Sub-pages reached from a row.
const SUBPAGES: &[(&str, &str)] = &[
("profiles", "Profiles"),
("search", "Search engines"),
("spell", "Spell check"),
("keys", "Keyboard shortcuts"),
("import", "Import from another browser"),
("newtab", "New tab page"),
("permissions", "Site permissions"),
("lists", "Filter lists"),
("managers", "Download managers"),
("discord", "Discord Rich Presence"),
];
pub fn draw(ui: &mut Ui, f: &mut Frame, requested: &str) {
if !requested.is_empty() && f.ui.pages.settings_section != requested {
f.ui.pages.settings_section = requested.to_owned();
// Clear the request so clicking another section works.
if let Some(tab) = f.tab_mut() {
tab.page = Some(Page::Settings(String::new()));
}
}
if f.ui.pages.settings_section.is_empty() {
f.ui.pages.settings_section = "general".into();
}
let mut s = f.shared.settings.borrow().clone();
let before = s.clone();
egui::Panel::left("settings-nav").exact_size(210.0).show(ui, |ui| {
ui.add_space(12.0);
ui.heading("Settings");
ui.add(egui::TextEdit::singleline(&mut f.ui.pages.settings_search).hint_text("Search settings"));
ui.add_space(8.0);
for (key, label) in SECTIONS {
let selected = f.ui.pages.settings_section == *key;
if ui.selectable_label(selected, *label).clicked() {
f.ui.pages.settings_section = (*key).into();
f.ui.pages.settings_search.clear();
}
}
if let Some((_, label)) = SUBPAGES.iter().find(|(k, _)| *k == f.ui.pages.settings_section) {
ui.separator();
ui.label(RichText::new(format!("› {label}")).strong());
}
});
let section = f.ui.pages.settings_section.clone();
let search = f.ui.pages.settings_search.to_lowercase();
super::super::widgets::page_column(ui, "settings-body", 820.0, |ui| {
if !search.is_empty() {
ui.label(RichText::new("Search shows the matching sections; type less to see more.").weak().small());
for (key, label) in SECTIONS {
if label.to_lowercase().contains(&search) || section_keywords(key).contains(&search) {
draw_section(ui, f, &mut s, key);
}
}
return;
}
if SUBPAGES.iter().any(|(k, _)| *k == section) && ui.button("‹ Back").clicked() {
f.ui.pages.settings_section = parent_section(&section).into();
}
draw_section(ui, f, &mut s, &section);
});
if s != before {
*f.shared.settings.borrow_mut() = s;
}
}
fn section_keywords(key: &str) -> &'static str {
match key {
"general" => "startup home page search engine profiles spell keyboard shortcuts import title bar card new tab",
"appearance" => "colour color palette mode dark light theme scheme contrast motion roundness websites force dark scale",
"toolbar" => "buttons navigation bookmarks bar",
"performance" => "memory low-memory energy saver tabs freeze unload preload smooth scrolling save data hardware acceleration gpu",
"privacy" => "vpn tor proxy privacy mode secure dns https site settings permissions delete browsing data do not track google sign-in cookies debugging user agent",
"adblock" => "ads trackers filter lists youtube cosmetic leftovers update rules",
"passwords" => "passwords autofill vault master generator addresses cards",
"downloads" => "save folder ask download managers abdm aria2 jdownloader fdm idm",
"media" => "media button visualizer cava artwork discord rich presence widevine drm",
"about" => "version engine profile updates",
_ => "",
}
}
fn parent_section(sub: &str) -> &'static str {
match sub {
"permissions" => "privacy",
"lists" => "adblock",
"managers" => "downloads",
"discord" => "media",
_ => "general",
}
}
fn draw_section(ui: &mut Ui, f: &mut Frame, s: &mut Settings, key: &str) {
match key {
"general" => general(ui, f, s),
"appearance" => appearance(ui, f, s),
"toolbar" => toolbar(ui, f, s),
"performance" => performance(ui, f, s),
"privacy" => privacy(ui, f, s),
"adblock" => adblock(ui, f, s),
"passwords" => passwords(ui, f, s),
"downloads" => downloads(ui, f, s),
"media" => media(ui, f, s),
"about" => about(ui, f, s),
"profiles" => profiles(ui, f),
"search" => search_engines(ui, f, s),
"spell" => spell(ui, f, s),
"keys" => keys(ui, f, s),
"import" => import(ui, f, s),
"newtab" => newtab(ui, f, s),
"permissions" => permissions(ui, f, s),
"lists" => lists(ui, f, s),
"managers" => managers(ui, f, s),
"discord" => discord(ui, f, s),
_ => {},
}
}
fn open(f: &mut Frame, sub: &str) {
f.ui.pages.settings_section = sub.to_owned();
}
fn general(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "General");
card(ui, |ui| {
if row(ui, "Setup", "Import, colours, privacy and search in one place", |ui| ui.button("Run setup").clicked()) {
f.send(Command::ShowPage(Page::Welcome));
}
row(ui, "On startup", "", |ui| segmented(ui, &mut s.startup.mode, StartupMode::ALL));
row(ui, "Home page", "Used by the Home button and the Home startup option", |ui| ui.add(egui::TextEdit::singleline(&mut s.startup.home_url).desired_width(240.0)));
let engine = s.search_engine_name();
if row(ui, "Search engine", "Used in the address bar and on the new tab page", |ui| ui.button(format!("🔍 {engine}")).clicked()) {
open(f, "search");
}
let profiles = f.shared.paths.profile_list().profiles.len();
if row(ui, "Profiles", &format!("Using {} · {profiles} profile{}", f.shared.paths.profile, if profiles == 1 { "" } else { "s" }), |ui| ui.button("›").clicked()) {
open(f, "profiles");
}
let langs = if s.spell.langs.is_empty() { crate::spell::system_language() } else { s.spell.langs.join(", ") };
if row(ui, "Spell check", &if s.spell.enabled { langs } else { "Off".into() }, |ui| ui.button("›").clicked()) {
open(f, "spell");
}
let custom = s.keys.len();
if row(ui, "Keyboard shortcuts", &if custom == 0 { "Default keys".to_owned() } else { format!("{custom} changed") }, |ui| ui.button("›").clicked()) {
open(f, "keys");
}
if row(ui, "Import from another browser", "Bookmarks, history and settings from Chrome, Firefox, Edge, Brave…", |ui| ui.button("›").clicked()) {
open(f, "import");
}
if row(ui, "New tab page", &format!("{} shortcuts on the new tab page", s.ntp.shortcuts.len()), |ui| ui.button("›").clicked()) {
open(f, "newtab");
}
switch_row(ui, "Custom title bar", "Frameless window with Nacre's own controls (restart to apply)", &mut s.ui.custom_title_bar);
switch_row(ui, "Floating content card", "Rounded page with a margin around it", &mut s.ui.floating_card);
});
}
fn appearance(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Appearance");
card(ui, |ui| {
row(ui, "Colour source", "Website follows each page's theme colour or favicon", |ui| segmented(ui, &mut s.theme.source, ColourSource::ALL));
row(ui, "When a site has no colour", "", |ui| segmented(ui, &mut s.theme.fallback, ColourFallback::ALL));
row(ui, "Palette", "", |ui| {
ui.horizontal(|ui| {
for hex in crate::theme::PRESETS.iter().rev() {
let color = crate::theme::parse_hex(hex).unwrap_or_default();
let selected = s.theme.preset.eq_ignore_ascii_case(hex);
let (rect, r) = ui.allocate_exact_size(egui::vec2(22.0, 22.0), egui::Sense::click());
ui.painter().circle_filled(rect.center(), 10.0, color);
if selected {
ui.painter().circle_stroke(rect.center(), 11.5, egui::Stroke::new(2.0, ui.visuals().text_color()));
}
if r.on_hover_text(*hex).clicked() {
s.theme.preset = (*hex).to_owned();
if s.theme.source == ColourSource::Website || s.theme.source == ColourSource::System {
s.theme.fallback = ColourFallback::Palette;
}
}
}
});
});
row(ui, "Custom colour", "Used when the colour source is Custom", |ui| {
let mut c = crate::theme::parse_hex(&s.theme.custom).unwrap_or(egui::Color32::from_rgb(0x3F, 0x6E, 0xE8));
if ui.color_edit_button_srgba(&mut c).changed() {
s.theme.custom = crate::theme::to_hex(c);
}
});
row(ui, "Mode", "", |ui| segmented(ui, &mut s.theme.mode, ThemeMode::ALL));
row(ui, "Scheme style and contrast", "", |ui| {
ui.add(egui::Slider::new(&mut s.theme.contrast, -1.0..=1.0).text("contrast"));
egui::ComboBox::from_id_salt("variant").selected_text(crate::theme::VARIANTS.iter().find(|(k, _)| *k == s.theme.variant).map(|(_, l)| *l).unwrap_or("Tonal spot")).show_ui(ui, |ui| {
for (k, l) in crate::theme::VARIANTS {
ui.selectable_value(&mut s.theme.variant, (*k).to_owned(), *l);
}
});
});
row(ui, "Motion", "Speed of every animation", |ui| segmented(ui, &mut s.ui.motion, Motion::ALL));
row(ui, "Roundness", "", |ui| segmented(ui, &mut s.ui.roundness, Roundness::ALL));
row(ui, "Interface size", "", |ui| ui.add(egui::Slider::new(&mut s.ui.scale, 0.75..=1.75).step_by(0.05)));
row(ui, "Websites", "Light or dark versions of sites that offer both", |ui| segmented(ui, &mut s.web.scheme, WebScheme::ALL));
switch_row(ui, "Force dark web pages", "Darkens sites that have no dark version (from their next load)", &mut s.web.force_dark);
});
let _ = f;
}
const TOOLBAR_GROUPS: &[(&str, &[(&str, &str)])] = &[
("Navigation", &[("back", "Back"), ("forward", "Forward"), ("reload", "Reload"), ("home", "Home")]),
("Your Nacre", &[("incognito", "New incognito window"), ("passwords", "Password manager"), ("history", "History"), ("downloads", "Downloads"), ("bookmarks", "Bookmarks"), ("apps", "Apps")]),
("Tools and actions", &[("qr", "Create QR code"), ("devtools", "Developer tools"), ("adblock", "Ad blocker"), ("media", "Media"), ("vpn", "VPN"), ("pip", "Picture in picture"), ("screenshot", "Save as PDF or image")]),
];
fn toolbar(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Toolbar");
card(ui, |ui| {
for (group, items) in TOOLBAR_GROUPS {
let shown: Vec<&str> = items.iter().filter(|(k, _)| s.toolbar_has(k)).map(|(_, l)| *l).collect();
ui.collapsing(format!("{group} — {} of {} shown", shown.len(), items.len()), |ui| {
for (key, label) in *items {
let mut on = s.toolbar_has(key);
if switch_row(ui, label, "", &mut on) {
if on {
s.ui.toolbar.push((*key).to_owned());
} else {
s.ui.toolbar.retain(|k| k != key);
}
}
}
});
ui.separator();
}
row(ui, "Bookmarks bar", "Under the toolbar (Ctrl+Shift+B shows or hides it)", |ui| segmented(ui, &mut s.ui.bookmarks_bar, BookmarksBar::ALL));
row(ui, "Bookmarks", "Folders, order, import and export", |ui| {
if ui.button("Bookmark manager").clicked() {
f.send(Command::ShowPage(Page::Bookmarks));
}
});
});
}
fn performance(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Performance");
card(ui, |ui| {
let own = crate::perf::own_memory();
let threads = crate::perf::own_threads();
let (total, available) = crate::perf::system_memory();
let desc = format!("Nacre is using {} · {threads} threads · {} of {} free", util::format_bytes(own), util::format_bytes(available), util::format_bytes(total));
if row(ui, "Memory", &desc, |ui| ui.button("Free up memory").clicked()) {
f.send(Command::FreeMemory);
}
let auto_note = if crate::perf::low_end() { "Auto: on for this PC (about 4 GB of memory or two threads)" } else { "Auto: off for this PC; it turns on with about 4 GB of memory or two threads" };
row(ui, "Low-memory mode", &format!("{auto_note}. Fewer threads, tabs rest sooner (restart for the engine part)"), |ui| segmented(ui, &mut s.perf.lite, AutoOnOff::ALL));
row(ui, "Energy saver", "Background tabs rest sooner and the new tab background stands still", |ui| segmented(ui, &mut s.perf.energy, EnergySaver::ALL));
});
ui.label(RichText::new("Tabs").strong());
card(ui, |ui| {
row(ui, "Memory saver", "Unloads tabs you haven't looked at; they load again when you return", |ui| {
let mut v = s.perf.discard_min;
let opts: &[(u32, &str)] = &[(0, "Off"), (15, "15 min"), (30, "30 min"), (60, "1 h"), (120, "2 h")];
segmented(ui, &mut v, opts);
s.perf.discard_min = v;
});
row(ui, "Freeze background tabs", "Hidden tabs stop drawing after a while (Servo can't pause their scripts; unloading frees memory)", |ui| {
let mut v = s.perf.freeze_min;
let opts: &[(u32, &str)] = &[(0, "Never"), (1, "1 min"), (5, "5 min"), (15, "15 min")];
segmented(ui, &mut v, opts);
s.perf.freeze_min = v;
});
ui.collapsing(format!("Always keep these sites active — {}", if s.perf.keep_active.is_empty() { "none".to_owned() } else { s.perf.keep_active.join(", ") }), |ui| {
let mut remove = None;
for (i, host) in s.perf.keep_active.iter().enumerate() {
ui.horizontal(|ui| {
ui.label(host);
if ui.small_button("Remove").clicked() {
remove = Some(i);
}
});
}
if let Some(i) = remove {
s.perf.keep_active.remove(i);
}
ui.horizontal(|ui| {
ui.add(egui::TextEdit::singleline(&mut f.ui.pages.keep_active_input).hint_text("example.com"));
if ui.button("Add").clicked() && !f.ui.pages.keep_active_input.trim().is_empty() {
s.perf.keep_active.push(f.ui.pages.keep_active_input.trim().trim_start_matches("www.").to_owned());
f.ui.pages.keep_active_input.clear();
}
if let Some(host) = f.tab().map(|t| t.host()).filter(|h| !h.is_empty())
&& ui.button(format!("Add {host}")).clicked()
{
s.perf.keep_active.push(host);
}
});
});
ui.separator();
switch_row(ui, "Load restored tabs when opened", "On startup only the tabs you open load", &mut s.perf.lazy_restore);
});
ui.label(RichText::new("Speed").strong());
card(ui, |ui| {
switch_row(ui, "Preload pages", "Looks up the addresses of links on a page ahead of time", &mut s.web.preload);
switch_row(ui, "Smooth scrolling", "Animated scrolling (off in low-memory mode)", &mut s.web.smooth_scroll);
switch_row(ui, "Still new tab background", "No animation on the new tab page", &mut s.perf.still_ntp);
switch_row(ui, "Save data", "Tells pages to be lighter and stops videos preloading (Servo can't send the Save-Data header)", &mut s.privacy.save_data);
row(ui, "Hardware acceleration", "Use the GPU. Turn off if pages show up black or blank (restart to apply)", |ui| segmented(ui, &mut s.web.gpu, AutoOnOff::ALL));
});
}
fn privacy(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Privacy");
card(ui, |ui| {
let status = match &*f.shared.vpn_status.borrow() {
crate::net::VpnStatus::Off => "Off — routes Nacre through Tor or your own proxy".to_owned(),
crate::net::VpnStatus::Connecting(w) => w.clone(),
crate::net::VpnStatus::On(w) => format!("On: {w}"),
crate::net::VpnStatus::Failed(w) => w.clone(),
};
row(ui, "VPN", &status, |ui| switch(ui, &mut s.vpn.enabled));
if s.vpn.enabled || s.vpn.provider == VpnProvider::Custom {
row(ui, "VPN provider", "Tor, or a SOCKS5 / HTTP proxy from a VPN service, ssh -D and so on", |ui| {
segmented(ui, &mut s.vpn.provider, VpnProvider::ALL);
});
if s.vpn.provider == VpnProvider::Custom {
row(ui, "Proxy address", "socks5://host:port or http://user:password@host:port", |ui| ui.add(egui::TextEdit::singleline(&mut s.vpn.custom).desired_width(260.0)));
}
}
row(ui, "Privacy mode", "Hides your browser's fingerprint (canvas, WebGL, screen and hardware details)", |ui| switch(ui, &mut s.privacy.mode));
switch_row(ui, "Privacy mode in incognito windows", "", &mut s.privacy.mode_incognito);
row(ui, "Secure DNS", "Looks up addresses over HTTPS so your network can't see or change them (not used while the VPN is on)", |ui| {
egui::ComboBox::from_id_salt("doh").selected_text(s.privacy.doh.label()).show_ui(ui, |ui| {
for (v, l) in DohProvider::ALL {
ui.selectable_value(&mut s.privacy.doh, *v, *l);
}
});
});
if s.privacy.doh == DohProvider::Custom {
row(ui, "Secure DNS address", "https://…/dns-query", |ui| ui.add(egui::TextEdit::singleline(&mut s.privacy.doh_custom).desired_width(260.0)));
}
row(ui, "HTTPS-only mode", "Loads every site over a secure connection and asks before using one that isn't", |ui| switch(ui, &mut s.privacy.https_only));
if !s.privacy.https_exceptions.is_empty() {
ui.collapsing("Sites allowed without HTTPS", |ui| {
let mut remove = None;
for (i, h) in s.privacy.https_exceptions.iter().enumerate() {
ui.horizontal(|ui| {
ui.label(h);
if ui.small_button("Remove").clicked() {
remove = Some(i);
}
});
}
if let Some(i) = remove {
s.privacy.https_exceptions.remove(i);
}
});
}
if row(ui, "Site settings", "Location, camera, microphone, notifications, pop-ups and other permissions", |ui| ui.button("›").clicked()) {
open(f, "permissions");
}
if row(ui, "Delete browsing data", "History, cookies, cache and more", |ui| ui.button("Delete…").clicked()) {
f.send(Command::ShowPage(Page::ClearData));
}
row(ui, "Delete when Nacre closes", "", |ui| {
for (key, label) in [("history", "History"), ("cookies", "Cookies"), ("cache", "Cache"), ("downloads", "Downloads list")] {
let mut on = s.privacy.clear_on_exit.iter().any(|k| k == key);
if ui.checkbox(&mut on, label).changed() {
if on {
s.privacy.clear_on_exit.push(key.to_owned());
} else {
s.privacy.clear_on_exit.retain(|k| k != key);
}
}
}
});
switch_row(ui, "Send Do Not Track and Global Privacy Control", "Pages see navigator.globalPrivacyControl; Servo can't add the request headers yet", &mut s.privacy.dnt);
switch_row(ui, "Remove tracking parameters", "Strips utm_, fbclid, gclid and similar from links before they load", &mut s.privacy.strip_params);
row(ui, "Block third-party cookies", "Not available with this engine yet (Servo 0.7 has no cookie policy setting)", |ui| ui.add_enabled(false, egui::Button::new("Unavailable")));
switch_row(ui, "Google sign-in", "Looks like Firefox on accounts.google.com so Google lets you sign in", &mut s.privacy.google_signin);
ui.collapsing(format!("Sites where ad blocking is paused — {}", if s.adblock.allow.is_empty() { "none".to_owned() } else { s.adblock.allow.join(", ") }), |ui| {
let mut remove = None;
for (i, h) in s.adblock.allow.iter().enumerate() {
ui.horizontal(|ui| {
ui.label(h);
if ui.small_button("Block ads here again").clicked() {
remove = Some(i);
}
});
}
if let Some(i) = remove {
s.adblock.allow.remove(i);
}
});
ui.separator();
row(ui, "Remote debugging", "Lets Firefox's developer tools connect to Nacre on localhost:6080 (restart to apply)", |ui| switch(ui, &mut s.web.remote_debugging));
row(ui, "User agent", "Empty uses the engine's default", |ui| ui.add(egui::TextEdit::singleline(&mut s.web.user_agent).hint_text("default").desired_width(260.0)));
});
}
fn adblock(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Ad blocker");
card(ui, |ui| {
switch_row(ui, "Block ads and trackers", "", &mut s.adblock.enabled);
let status = f.shared.adblock_status.borrow().clone();
let age = if s.adblock.last_update > 0 { format!(" · updated {}", util::format_ago(s.adblock.last_update)) } else { String::new() };
if row(ui, "Filter engine", &format!("adblock-rust · {status}{age} · {} blocked in total", s.adblock.total), |ui| ui.button("Update now").clicked()) {
f.send(Command::UpdateFilterLists);
}
let on = s.adblock.lists.len();
if row(ui, "Filter lists", &format!("{on} of {} on", crate::adblock::LISTS.len()), |ui| ui.button("›").clicked()) {
open(f, "lists");
}
switch_row(ui, "Hide ad leftovers", "Cosmetic (##) rules from the lists", &mut s.adblock.cosmetic);
switch_row(ui, "Animate ad removal", "Ads you can see squish away", &mut s.adblock.animate);
switch_row(ui, "Block YouTube ads", "Strips ad data from the player and skips any that still play", &mut s.adblock.youtube);
row(ui, "Update lists automatically", "Only re-downloads lists that changed", |ui| {
let mut v = s.adblock.update_days;
let opts: &[(u32, &str)] = &[(0, "Manually"), (1, "Daily"), (7, "Weekly"), (30, "Monthly")];
segmented(ui, &mut v, opts);
s.adblock.update_days = v;
});
});
}
fn lists(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Filter lists");
let dir = f.shared.paths.filter_lists();
let failures = f.shared.adblock.failures.read().map(|m| m.clone()).unwrap_or_default();
let mut group = "";
card(ui, |ui| {
for list in crate::adblock::LISTS {
if list.group != group {
group = list.group;
ui.label(RichText::new(group).strong());
}
let mut on = s.adblock.lists.iter().any(|k| k == list.key);
let age = crate::adblock::AdBlocker::list_age(&dir, list.key).map(|a| format!(" · updated {}", util::format_ago(util::now().saturating_sub(a)))).unwrap_or_else(|| " · not downloaded yet".into());
let fail = failures.get(list.key).map(|e| format!(" · last update failed: {e}")).unwrap_or_default();
if switch_row(ui, list.name, &format!("{}{age}{fail}", list.description), &mut on) {
if on {
s.adblock.lists.push(list.key.to_owned());
} else {
s.adblock.lists.retain(|k| k != list.key);
}
}
}
});
ui.label(RichText::new("Your lists").strong());
card(ui, |ui| {
let mut remove = None;
for (i, url) in s.adblock.custom.iter().enumerate() {
ui.horizontal(|ui| {
ui.label(util::ellipsize(url, 80));
if ui.small_button("Remove").clicked() {
remove = Some(i);
}
});
}
if let Some(i) = remove {
s.adblock.custom.remove(i);
}
ui.horizontal(|ui| {
ui.add(egui::TextEdit::singleline(&mut f.ui.pages.new_list_url).hint_text("https://… filter list or hosts file").desired_width(420.0));
if ui.button("Add list").clicked() && f.ui.pages.new_list_url.starts_with("http") {
s.adblock.custom.push(f.ui.pages.new_list_url.trim().to_owned());
f.ui.pages.new_list_url.clear();
}
});
ui.label(RichText::new("Your own rules (Adblock Plus / uBlock syntax, one per line)").small());
ui.add(egui::TextEdit::multiline(&mut s.adblock.own_rules).code_editor().desired_rows(6).desired_width(f32::INFINITY));
});
}
fn passwords(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Passwords and autofill");
card(ui, |ui| {
switch_row(ui, "Offer to save passwords", "", &mut s.vault.enabled);
switch_row(ui, "Sign in automatically", "Fills the login when a site has exactly one saved", &mut s.vault.autofill);
switch_row(ui, "Fill addresses and cards", "Suggests saved addresses and payment cards in forms", &mut s.vault.autofill_forms);
row(ui, "Lock after", "With a master password: lock after this many idle minutes (0 = never)", |ui| number(ui, &mut s.vault.autolock_min, 0..=1440, " min"));
switch_row(ui, "Ask for the master password before showing passwords", "", &mut s.vault.reauth);
row(ui, "…then trust this session for", "", |ui| number(ui, &mut s.vault.reauth_min, 0..=240, " min"));
row(ui, "Generated passwords", "", |ui| {
ui.checkbox(&mut s.vault.gen_symbols, "Symbols");
number(ui, &mut s.vault.gen_length, 8..=128, " characters");
});
row(ui, "Clear copied passwords from the clipboard after", "0 = never", |ui| number(ui, &mut s.vault.clipboard_clear, 0..=600, " s"));
if row(ui, "Saved passwords, addresses and cards", "", |ui| ui.button("Open").clicked()) {
f.send(Command::ShowPage(Page::Passwords));
}
});
}
fn downloads(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Downloads");
card(ui, |ui| {
let dir = s.downloads.dir.display().to_string();
if row(ui, "Save to", &dir, |ui| ui.button("📂 Change").clicked())
&& let Some(path) = rfd::FileDialog::new().set_directory(&s.downloads.dir).pick_folder()
{
s.downloads.dir = path;
}
switch_row(ui, "Ask where to save each file", "", &mut s.downloads.ask);
switch_row(ui, "Show downloads when they start", "", &mut s.downloads.auto_open);
let using = if s.downloads.manager == "builtin" { "Nacre".to_owned() } else { crate::net::dlm::by_key(&s.downloads.manager).map(|m| m.name.to_owned()).unwrap_or_default() };
if row(ui, "Download managers", &format!("New downloads go to {using}"), |ui| ui.button("›").clicked()) {
open(f, "managers");
}
});
}
fn managers(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Download managers");
ui.label(RichText::new("Hand downloads to another program. Local ports are never reached through the VPN. If the manager doesn't answer, Nacre downloads the file itself.").weak());
card(ui, |ui| {
row(ui, "New downloads go to", "", |ui| {
egui::ComboBox::from_id_salt("dlm").selected_text(if s.downloads.manager == "builtin" { "Nacre" } else { crate::net::dlm::by_key(&s.downloads.manager).map(|m| m.name).unwrap_or("Nacre") }).show_ui(ui, |ui| {
ui.selectable_value(&mut s.downloads.manager, "builtin".to_owned(), "Nacre");
for m in crate::net::dlm::available().filter(|m| s.downloads.managers.iter().any(|k| k == m.key)) {
ui.selectable_value(&mut s.downloads.manager, m.key.to_owned(), m.name);
}
});
});
});
let statuses = f.shared.dlm_status.borrow().clone();
for m in crate::net::dlm::available() {
card(ui, |ui| {
let mut on = s.downloads.managers.iter().any(|k| k == m.key);
let status = match statuses.get(m.key) {
Some(Ok(where_)) => format!("Found · {where_}"),
Some(Err(why)) => why.clone(),
None => "Checking…".into(),
};
if switch_row(ui, m.name, &format!("{} · {status}", m.hint), &mut on) {
if on {
s.downloads.managers.push(m.key.to_owned());
} else {
s.downloads.managers.retain(|k| k != m.key);
if s.downloads.manager == m.key {
s.downloads.manager = "builtin".into();
}
}
}
if on {
match m.key {
"abdm" => {
row(ui, "Port", "", |ui| ui.add(egui::DragValue::new(&mut s.downloads.abdm_port).range(1..=65535)));
},
"aria2" => {
row(ui, "RPC port", "", |ui| ui.add(egui::DragValue::new(&mut s.downloads.aria2_port).range(1..=65535)));
row(ui, "RPC secret", "optional", |ui| ui.add(egui::TextEdit::singleline(&mut s.downloads.aria2_secret).password(true)));
},
"jdownloader" => {
row(ui, "Port", "", |ui| ui.add(egui::DragValue::new(&mut s.downloads.jd_port).range(1..=65535)));
},
"fdm" => {
row(ui, "Program", "found automatically when empty", |ui| ui.add(egui::TextEdit::singleline(&mut s.downloads.fdm_path)));
},
"idm" => {
row(ui, "Program", "found automatically when empty", |ui| ui.add(egui::TextEdit::singleline(&mut s.downloads.idm_path)));
},
_ => {},
}
}
});
}
if ui.button("Check again").clicked() {
f.send(Command::PingManagers);
}
}
fn media(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Media");
card(ui, |ui| {
row(ui, "Media button", "Toolbar button that opens the player", |ui| segmented(ui, &mut s.media.button, MediaButton::ALL));
let cava = if crate::media::Cava::available() { "Auto uses cava for real system-audio levels" } else { "Auto uses real levels when cava is installed, else a simulation" };
row(ui, "Visualizer", cava, |ui| segmented(ui, &mut s.media.visualizer, Visualizer::ALL));
switch_row(ui, "Spin artwork while playing", "", &mut s.media.spin);
let status = if s.rpc.enabled { f.shared.presence_status.borrow().clone() } else { "Off".into() };
if row(ui, "Discord Rich Presence", &status, |ui| ui.button("›").clicked()) {
open(f, "discord");
}
row(ui, "Protected content (Widevine)", "Netflix, Hulu, Spotify and other DRM video can't play: the Servo engine has no DRM support", |ui| ui.add_enabled(false, egui::Button::new("Not available")));
if !s.media.muted_sites.is_empty() {
ui.collapsing("Muted sites", |ui| {
let mut remove = None;
for (i, h) in s.media.muted_sites.iter().enumerate() {
ui.horizontal(|ui| {
ui.label(h);
if ui.small_button("Unmute").clicked() {
remove = Some(i);
}
});
}
if let Some(i) = remove {
s.media.muted_sites.remove(i);
}
});
}
});
}
fn discord(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Discord Rich Presence");
ui.label(RichText::new("Shows what you watch or listen to on your Discord profile, through the Discord app or arRPC (Vesktop).").weak());
card(ui, |ui| {
let status = f.shared.presence_status.borrow().clone();
switch_row(ui, "Show activity on Discord", &format!("Status: {status}"), &mut s.rpc.enabled);
row(ui, "Send to", "", |ui| segmented(ui, &mut s.rpc.target, RpcTarget::ALL));
row(ui, "Application ID", "From discord.com/developers → New Application; its name shows as the activity", |ui| ui.add(egui::TextEdit::singleline(&mut s.rpc.client_id).desired_width(200.0)));
row(ui, "Report other tabs", "Off, the site's name, or the page title", |ui| segmented(ui, &mut s.rpc.browsing, RpcBrowsing::ALL));
row(ui, "Show other tabs as", "Never as \"Playing\", which games use", |ui| segmented(ui, &mut s.rpc.browse_type, RpcBrowseType::ALL));
row(ui, "Member list shows", "", |ui| segmented(ui, &mut s.rpc.display, RpcDisplay::ALL));
switch_row(ui, "Buttons", "\"Watch on YouTube\" and similar links on the activity", &mut s.rpc.button);
switch_row(ui, "Keep paused media", "Shows it as paused instead of clearing the activity", &mut s.rpc.show_paused);
});
ui.label(RichText::new("Supported sites").strong());
card(ui, |ui| {
for (key, name, kind, _) in crate::discord::SITES {
ui.horizontal(|ui| {
let mut on = !s.rpc.disabled_sites.iter().any(|k| k == key);
if switch(ui, &mut on) {
if on {
s.rpc.disabled_sites.retain(|k| k != key);
} else {
s.rpc.disabled_sites.push((*key).to_owned());
}
}
ui.label(format!("{name} ({kind})"));
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let mut id = s.rpc.site_ids.get(*key).cloned().unwrap_or_default();
if ui.add(egui::TextEdit::singleline(&mut id).hint_text("own app ID").desired_width(160.0)).changed() {
if id.trim().is_empty() {
s.rpc.site_ids.remove(*key);
} else {
s.rpc.site_ids.insert((*key).to_owned(), id.trim().to_owned());
}
}
});
});
}
ui.separator();
ui.label("More sites to report (host names, comma separated)");
let mut custom = s.rpc.custom.join(", ");
if ui.add(egui::TextEdit::singleline(&mut custom).desired_width(f32::INFINITY)).changed() {
s.rpc.custom = custom.split(',').map(|h| h.trim().to_owned()).filter(|h| !h.is_empty()).collect();
}
});
let _ = f;
}
fn about(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "About");
card(ui, |ui| {
row(ui, &format!("Nacre {}", crate::updates::current_version()), "A web browser built on the Servo engine", |_| ());
row(ui, "Engine", "Servo 0.7.0 (Rust) · SpiderMonkey · WebRender · interface in egui", |_| ());
let (accent, dark) = (f.palette().accent, f.palette().dark);
row(ui, "Colour", &format!("{} · {}", crate::theme::to_hex(accent), if dark { "dark" } else { "light" }), |_| ());
let p = &f.shared.paths;
row(ui, "Profile", &format!("{}\n{}\n{}", p.config.display(), p.data.display(), p.cache.display()), |ui| {
if ui.button("📂").on_hover_text("Open the data folder").clicked() {
util::open_external(&p.data.to_string_lossy());
}
});
row(ui, "Updates", "Where Nacre's releases are published (Forgejo, Gitea or GitHub)", |ui| ui.add(egui::TextEdit::singleline(&mut s.update.repo).desired_width(300.0)));
switch_row(ui, "Check for updates automatically", "Once a day", &mut s.update.auto_check);
let status = f.shared.update_status.borrow().clone();
if row(ui, "Check for updates", &status, |ui| ui.button("Check now").clicked()) {
f.send(Command::CheckUpdates);
}
});
}
fn profiles(ui: &mut Ui, f: &mut Frame) {
section(ui, "Profiles");
ui.label(RichText::new("Each profile has its own history, bookmarks, passwords, cookies and settings.").weak());
let list = f.shared.paths.profile_list();
card(ui, |ui| {
for name in &list.profiles {
ui.horizontal(|ui| {
let current = *name == f.shared.paths.profile;
ui.label(if current { RichText::new(format!("{name} (this one)")).strong() } else { RichText::new(name) });
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if !current {
if ui.small_button("Delete").on_hover_text("Deletes the profile and all its data").clicked() {
match f.shared.paths.delete_profile(name) {
Ok(()) => f.shared.toast(format!("Profile {name} deleted")),
Err(e) => f.shared.toast(e),
}
}
if ui.small_button("Open").clicked() {
f.send(Command::SwitchProfile(name.clone()));
}
}
});
});
}
ui.separator();
ui.horizontal(|ui| {
ui.add(egui::TextEdit::singleline(&mut f.ui.pages.new_profile).hint_text("New profile name"));
if ui.button("Add and open").clicked() && !f.ui.pages.new_profile.trim().is_empty() {
let name = f.shared.paths.add_profile(&f.ui.pages.new_profile);
f.ui.pages.new_profile.clear();
f.send(Command::SwitchProfile(name));
}
});
});
}
fn search_engines(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Search engines");
card(ui, |ui| {
for (key, name, url, _) in s.search_engines() {
ui.horizontal(|ui| {
ui.radio_value(&mut s.startup.search_engine, key.clone(), name.as_str());
ui.label(RichText::new(util::ellipsize(&url, 60)).weak().small());
if let Some(custom) = key.strip_prefix("custom:")
&& ui.small_button("Remove").clicked()
{
s.startup.custom_engines.retain(|(n, _)| n != custom);
if s.startup.search_engine == key {
s.startup.search_engine = "duckduckgo".into();
}
}
});
}
ui.separator();
ui.horizontal(|ui| {
ui.add(egui::TextEdit::singleline(&mut f.ui.pages.new_engine.0).hint_text("Name").desired_width(120.0));
ui.add(egui::TextEdit::singleline(&mut f.ui.pages.new_engine.1).hint_text("https://example.com/search?q=%s").desired_width(320.0));
let ok = !f.ui.pages.new_engine.0.trim().is_empty() && f.ui.pages.new_engine.1.contains("%s");
if ui.add_enabled(ok, egui::Button::new("Add")).clicked() {
let (name, url) = std::mem::take(&mut f.ui.pages.new_engine);
s.startup.custom_engines.push((name.trim().to_owned(), url.trim().to_owned()));
}
});
switch_row(ui, "Search suggestions", "Sends what you type in the address bar to the search engine for suggestions (never in incognito)", &mut s.startup.search_suggestions);
});
}
fn spell(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Spell check");
card(ui, |ui| {
switch_row(ui, "Check spelling in text fields", "Misspelled words get a red underline; right-click for suggestions", &mut s.spell.enabled);
row(ui, "Dictionaries", &f.shared.spell_status.borrow().clone(), |ui| {
if ui.button("Reload").clicked() {
f.send(Command::ReloadSpeller);
}
});
ui.label(RichText::new("Languages (none chosen = the system language). Missing dictionaries are downloaded once.").small().weak());
ui.horizontal_wrapped(|ui| {
for (code, name) in crate::spell::LANGUAGES {
let mut on = s.spell.langs.iter().any(|l| l == code);
if ui.checkbox(&mut on, *name).changed() {
if on {
s.spell.langs.push((*code).to_owned());
} else {
s.spell.langs.retain(|l| l != code);
}
}
}
});
});
}
fn keys(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Keyboard shortcuts");
ui.label(RichText::new("Click a shortcut and press the new keys. Esc cancels, Backspace removes it.").weak());
// Record a key press for the action being changed.
if let Some(action) = f.ui.pages.capture_key {
let pressed = ui.input(|i| i.events.iter().find_map(|e| if let egui::Event::Key { key, pressed: true, modifiers, .. } = e { Some((*key, *modifiers)) } else { None }));
if let Some((key, mods)) = pressed {
match key {
egui::Key::Escape => {},
egui::Key::Backspace => {
s.keys.insert(action.key().to_owned(), String::new());
},
_ => {
let mut text = String::new();
if mods.ctrl || mods.command {
text.push_str("Ctrl+");
}
if mods.alt {
text.push_str("Alt+");
}
if mods.shift {
text.push_str("Shift+");
}
text.push_str(key.name());
if let Some(shortcut) = Shortcut::parse(&text) {
if shortcut.safe_alone() {
s.keys.insert(action.key().to_owned(), text);
} else {
f.shared.toast("Use Ctrl, Alt or a function key, or typing would trigger it");
}
}
},
}
f.ui.pages.capture_key = None;
}
}
let map = crate::keys::Keymap::new(&s.keys);
card(ui, |ui| {
egui::Grid::new("keys").num_columns(3).striped(true).show(ui, |ui| {
for (action, key, label, _) in Action::ALL {
ui.label(*label);
let shortcuts: Vec<String> = map.shortcuts(*action).iter().map(Shortcut::label).collect();
let text = if f.ui.pages.capture_key == Some(*action) { "Press keys…".to_owned() } else if shortcuts.is_empty() { "—".to_owned() } else { shortcuts.join(", ") };
if ui.button(text).clicked() {
f.ui.pages.capture_key = Some(*action);
}
if s.keys.contains_key(*key) {
if ui.small_button("Reset").clicked() {
s.keys.remove(*key);
}
} else {
ui.label("");
}
ui.end_row();
}
});
});
if !s.keys.is_empty() && ui.button("Reset all shortcuts").clicked() {
s.keys.clear();
}
}
fn import(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Import from another browser");
let sources = f.shared.import_sources.borrow().clone();
card(ui, |ui| {
if sources.is_empty() {
ui.label(RichText::new("No other browsers found on this computer.").weak());
}
for (i, src) in sources.iter().enumerate() {
let id = egui::Id::new(("import-choice", i));
let (mut b, mut h, mut st) = ui.data_mut(|d| d.get_temp::<(bool, bool, bool)>(id)).unwrap_or((true, true, false));
ui.horizontal(|ui| {
let done = s.startup.import_done.contains(&src.name());
ui.label(RichText::new(src.name()).strong());
if done {
ui.label(RichText::new("imported before").weak().small());
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.button("Import").clicked() {
f.send(Command::Import { source: i, bookmarks: b, history: h, settings: st });
}
ui.checkbox(&mut st, "Home page and search engine");
ui.checkbox(&mut h, "History");
ui.checkbox(&mut b, "Bookmarks");
});
});
ui.data_mut(|d| d.insert_temp(id, (b, h, st)));
ui.separator();
}
let status = f.shared.import_status.borrow().clone();
if !status.is_empty() {
ui.label(RichText::new(status).weak());
}
});
card(ui, |ui| {
if row(ui, "Bookmarks from a file", "An HTML bookmarks file exported from any browser", |ui| ui.button("Choose file").clicked()) {
f.send(Command::ImportBookmarksFile);
}
if row(ui, "Passwords", "Export a CSV from the other browser's password settings, then import it here", |ui| ui.button("Import CSV").clicked()) {
f.send(Command::ImportPasswords);
}
});
}
fn newtab(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "New tab page");
ui.label(RichText::new("What shows, in order").strong());
card(ui, |ui| {
let mut swap = None;
let len = s.ntp.elements.len();
for i in 0..len {
ui.horizontal(|ui| {
let (name, on) = &mut s.ntp.elements[i];
switch(ui, on);
ui.label(element_label(name));
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if i + 1 < len && ui.small_button("⬇").clicked() {
swap = Some((i, i + 1));
}
if i > 0 && ui.small_button("⬆").clicked() {
swap = Some((i, i - 1));
}
});
});
}
if let Some((a, b)) = swap {
s.ntp.elements.swap(a, b);
}
});
card(ui, |ui| {
switch_row(ui, "24-hour clock", "", &mut s.ntp.clock24);
switch_row(ui, "Show seconds", "", &mut s.ntp.seconds);
row(ui, "Your name", "For the greeting", |ui| ui.add(egui::TextEdit::singleline(&mut s.ntp.name)));
row(ui, "City", "For the weather (Open-Meteo)", |ui| ui.add(egui::TextEdit::singleline(&mut s.ntp.city)));
row(ui, "Units", "", |ui| {
let mut u = s.ntp.units.clone();
ui.selectable_value(&mut u, "auto".to_owned(), "Auto");
ui.selectable_value(&mut u, "c".to_owned(), "°C");
ui.selectable_value(&mut u, "f".to_owned(), "°F");
s.ntp.units = u;
});
});
ui.label(RichText::new("Background").strong());
card(ui, |ui| {
row(ui, "Animation", "", |ui| segmented(ui, &mut s.ntp.bg, NtpBackground::ALL));
row(ui, "Density", "", |ui| {
for d in ["low", "medium", "high"] {
ui.selectable_value(&mut s.ntp.bg_density, d.to_owned(), d);
}
});
row(ui, "Speed", "", |ui| {
for d in ["slow", "normal", "fast"] {
ui.selectable_value(&mut s.ntp.bg_speed, d.to_owned(), d);
}
});
switch_row(ui, "Follows the mouse", "", &mut s.ntp.bg_mouse);
let image = if s.ntp.bg_image.is_empty() { "None".to_owned() } else { s.ntp.bg_image.clone() };
row(ui, "Image", &image, |ui| {
if !s.ntp.bg_image.is_empty() && ui.button("Remove").clicked() {
s.ntp.bg_image.clear();
}
if ui.button("Choose…").clicked()
&& let Some(path) = rfd::FileDialog::new().add_filter("Images", &["png", "jpg", "jpeg", "webp", "gif", "bmp"]).pick_file()
{
let name = format!("ntp-bg-{}.{}", util::now(), path.extension().and_then(|e| e.to_str()).unwrap_or("png"));
if std::fs::copy(&path, f.shared.paths.data.join(&name)).is_ok() {
s.ntp.bg_image = name;
}
}
});
row(ui, "Dim", "", |ui| ui.add(egui::Slider::new(&mut s.ntp.bg_dim, 0.0..=0.9)));
row(ui, "Blur", "", |ui| ui.add(egui::Slider::new(&mut s.ntp.bg_blur, 0.0..=40.0)));
});
ui.label(RichText::new("Shortcuts").strong());
card(ui, |ui| {
let mut remove = None;
for (i, (title, url)) in s.ntp.shortcuts.iter_mut().enumerate() {
ui.horizontal(|ui| {
ui.add(egui::TextEdit::singleline(title).desired_width(140.0));
ui.add(egui::TextEdit::singleline(url).desired_width(360.0));
if ui.small_button("Remove").clicked() {
remove = Some(i);
}
});
}
if let Some(i) = remove {
s.ntp.shortcuts.remove(i);
}
ui.horizontal(|ui| {
ui.add(egui::TextEdit::singleline(&mut f.ui.pages.new_shortcut.0).hint_text("Name").desired_width(140.0));
ui.add(egui::TextEdit::singleline(&mut f.ui.pages.new_shortcut.1).hint_text("https://…").desired_width(360.0));
if ui.button("Add").clicked() && !f.ui.pages.new_shortcut.1.trim().is_empty() {
let (title, url) = std::mem::take(&mut f.ui.pages.new_shortcut);
let url = if url.contains("://") { url } else { format!("https://{}", url.trim()) };
let title = if title.trim().is_empty() { util::host_of_str(&url) } else { title.trim().to_owned() };
s.ntp.shortcuts.push((title, url));
}
});
});
}
fn element_label(key: &str) -> &'static str {
match key {
"clock" => "Clock and date",
"greeting" => "Greeting",
"search" => "Search box",
"shortcuts" => "Shortcuts",
"media" => "Now playing",
"weather" => "Weather",
"notes" => "Notes",
"reading" => "Reading list",
"recent" => "Recently visited",
_ => "Other",
}
}
fn permissions(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
section(ui, "Site permissions");
ui.label(RichText::new("What sites may do when they haven't been asked. Each site's own answers are in Site settings.").weak());
card(ui, |ui| {
for kind in crate::store::permissions::Kind::ALL {
let mut value = s.privacy.permission_defaults.get(kind.key()).copied().unwrap_or_else(|| kind.builtin_default());
let before = value;
row(ui, kind.label(), "", |ui| segmented(ui, &mut value, PermissionDefault::ALL));
if value != before {
if value == kind.builtin_default() {
s.privacy.permission_defaults.remove(kind.key());
} else {
s.privacy.permission_defaults.insert(kind.key().to_owned(), value);
}
}
}
});
if ui.button("Every site's permissions").clicked() {
f.send(Command::ShowPage(Page::SiteSettings(String::new())));
}
}