1314 lines
69 KiB
Rust
1314 lines
69 KiB
Rust
//! nacre://settings — every setting, in the sections of the original Nacre: a navigation rail on the left (icons only
|
||
//! on narrow pages), the section's cards of rows on the right. Search looks through every row of every section.
|
||
//!
|
||
//! 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::{Align2, Color32, Id, Rect, RichText, Sense, Shape, Stroke, StrokeKind, Ui, UiBuilder, Vec2, pos2, vec2};
|
||
|
||
use super::super::Frame;
|
||
use super::super::widgets::{
|
||
ButtonKind, button, card, choice_chips, chip, focus_ring, highlight_rows, highlighted, icon, icon_button, icon_link_row, icon_row, icon_toggle, input_chip, interaction,
|
||
limited_row, number, row, section, segmented, slider, switch, switch_row, text_field, toggle_chips, unavailable_row, wide_row,
|
||
};
|
||
use crate::actions::Command;
|
||
use crate::keys::{Action, Shortcut};
|
||
use crate::store::settings::*;
|
||
use crate::tabs::Page;
|
||
use crate::theme::{self, Palette, Weight};
|
||
use crate::ui::icons;
|
||
use crate::util;
|
||
|
||
/// Rail entries: key, label, icon.
|
||
const SECTIONS: &[(&str, &str, &str)] = &[
|
||
("general", "General", icons::TUNE),
|
||
("appearance", "Appearance", icons::PALETTE),
|
||
("toolbar", "Toolbar", icons::TOOLBAR),
|
||
("performance", "Performance", icons::SPEED),
|
||
("privacy", "Privacy", icons::LOCK),
|
||
("adblock", "Ad blocker", icons::SHIELD),
|
||
("passwords", "Passwords and autofill", icons::KEY),
|
||
("downloads", "Downloads", icons::DOWNLOAD),
|
||
("media", "Media", icons::MUSIC_NOTE),
|
||
("about", "About", icons::INFO),
|
||
];
|
||
|
||
/// Sub-pages reached from a row: key, label, the section they belong to.
|
||
const SUBPAGES: &[(&str, &str, &str)] = &[
|
||
("profiles", "Profiles", "general"),
|
||
("search", "Search engines", "general"),
|
||
("spell", "Spell check", "general"),
|
||
("keys", "Keyboard shortcuts", "general"),
|
||
("import", "Import from another browser", "general"),
|
||
("newtab", "New tab page", "general"),
|
||
("permissions", "Site permissions", "privacy"),
|
||
("lists", "Filter lists", "adblock"),
|
||
("managers", "Download managers", "downloads"),
|
||
("discord", "Discord Rich Presence", "media"),
|
||
];
|
||
|
||
/// Below this page width the rail shows icons only.
|
||
const COMPACT: f32 = 760.0;
|
||
const RAIL: f32 = 264.0;
|
||
const RAIL_COMPACT: f32 = 88.0;
|
||
/// Height of a rail entry (wide) and of an icon-and-label entry (compact).
|
||
const ITEM: f32 = 48.0;
|
||
const ITEM_COMPACT: f32 = 60.0;
|
||
const COLUMN: f32 = 760.0;
|
||
|
||
pub fn draw(ui: &mut Ui, f: &mut Frame, requested: &str) {
|
||
// nacre://settings/<section>, or nacre://settings/?search=<words>.
|
||
if let Some(query) = requested.strip_prefix("?search=") {
|
||
f.ui.pages.settings_search = util::percent_decode(query);
|
||
if let Some(tab) = f.tab_mut() {
|
||
tab.page = Some(Page::Settings(String::new()));
|
||
}
|
||
} else if !requested.is_empty() && f.ui.pages.settings_section != requested {
|
||
f.ui.pages.settings_section = requested.to_owned();
|
||
f.ui.pages.settings_search.clear();
|
||
// 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();
|
||
let area = ui.available_rect_before_wrap();
|
||
let compact = area.width() < COMPACT;
|
||
let rail_width = if compact { RAIL_COMPACT } else { RAIL };
|
||
let rail_rect = Rect::from_min_size(area.min, vec2(rail_width, area.height()));
|
||
let body_rect = Rect::from_min_max(pos2(area.left() + rail_width, area.top()), area.max);
|
||
let mut rail_ui = ui.new_child(UiBuilder::new().max_rect(rail_rect).id_salt("settings-rail"));
|
||
rail(&mut rail_ui, f, compact);
|
||
let mut body = ui.new_child(UiBuilder::new().max_rect(body_rect).id_salt("settings-body"));
|
||
super::super::widgets::page_column(&mut body, "settings-body", COLUMN, |ui| {
|
||
if compact {
|
||
search_field(ui, f);
|
||
ui.add_space(theme::GAP_S);
|
||
}
|
||
let search = f.ui.pages.settings_search.trim().to_lowercase();
|
||
if search.is_empty() {
|
||
let section = f.ui.pages.settings_section.clone();
|
||
if header(ui, §ion) {
|
||
f.ui.pages.settings_section = parent_section(§ion).into();
|
||
}
|
||
draw_section(ui, f, &mut s, §ion);
|
||
} else {
|
||
search_results(ui, f, &mut s, &search);
|
||
}
|
||
});
|
||
ui.advance_cursor_after_rect(area);
|
||
if s != before {
|
||
*f.shared.settings.borrow_mut() = s;
|
||
}
|
||
}
|
||
|
||
fn label_of(key: &str) -> &'static str {
|
||
SECTIONS.iter().map(|(k, l, _)| (k, l)).chain(SUBPAGES.iter().map(|(k, l, _)| (k, l))).find(|(k, _)| **k == key).map(|(_, l)| *l).unwrap_or("Settings")
|
||
}
|
||
|
||
fn parent_section(sub: &str) -> &'static str {
|
||
SUBPAGES.iter().find(|(k, _, _)| *k == sub).map(|(_, _, parent)| *parent).unwrap_or("general")
|
||
}
|
||
|
||
/// The rail entry that shows as selected: the section itself, or the one a sub-page belongs to.
|
||
fn rail_key(section: &str) -> &str {
|
||
if SUBPAGES.iter().any(|(k, _, _)| *k == section) { parent_section(section) } else { section }
|
||
}
|
||
|
||
fn rail(ui: &mut Ui, f: &mut Frame, compact: bool) {
|
||
let p = theme::palette(ui.ctx());
|
||
let pad = if compact { theme::GAP_S } else { theme::GAP_M };
|
||
ui.add_space(theme::GAP_L);
|
||
if !compact {
|
||
ui.horizontal(|ui| {
|
||
ui.add_space(pad + theme::GAP_L);
|
||
ui.label(RichText::new("Settings").font(theme::font(theme::HEADLINE, Weight::Medium)).color(p.on_surface));
|
||
});
|
||
ui.add_space(theme::GAP_M);
|
||
ui.horizontal(|ui| {
|
||
ui.add_space(pad);
|
||
ui.vertical(|ui| {
|
||
ui.set_width(RAIL - 2.0 * pad);
|
||
search_field(ui, f);
|
||
});
|
||
});
|
||
ui.add_space(theme::GAP_S);
|
||
}
|
||
let searching = !f.ui.pages.settings_search.trim().is_empty();
|
||
let selected = SECTIONS.iter().position(|(k, _, _)| *k == rail_key(&f.ui.pages.settings_section));
|
||
egui::ScrollArea::vertical().id_salt("settings-rail-scroll").auto_shrink([false, false]).show(ui, |ui| {
|
||
let height = if compact { ITEM_COMPACT } else { ITEM };
|
||
let width = ui.available_width() - 2.0 * pad;
|
||
let (column, _) = ui.allocate_exact_size(vec2(ui.available_width(), height * SECTIONS.len() as f32 + theme::GAP_L), Sense::hover());
|
||
let top = column.top();
|
||
let left = column.left() + pad;
|
||
// The selection pill slides between entries; it fades while search results show instead of a section.
|
||
let shown = theme::effect(ui.ctx(), Id::new("settings-rail-pill-shown"), selected.is_some() && !searching);
|
||
let y = theme::spring(ui.ctx(), Id::new("settings-rail-pill"), selected.unwrap_or(0) as f32 * height, theme::DEFAULT);
|
||
let pill = |y: f32| {
|
||
if compact {
|
||
Rect::from_center_size(pos2(column.center().x, top + y + 4.0 + 16.0), vec2(56.0, 32.0))
|
||
} else {
|
||
Rect::from_min_size(pos2(left, top + y), vec2(width, height))
|
||
}
|
||
};
|
||
if shown > 0.0 {
|
||
ui.painter().rect_filled(pill(y), theme::corner_radius(theme::FULL), p.secondary_container.gamma_multiply(shown));
|
||
}
|
||
for (i, (key, label, glyph)) in SECTIONS.iter().enumerate() {
|
||
let item = Rect::from_min_size(pos2(left, top + i as f32 * height), vec2(width, height));
|
||
let response = ui.interact(item, ui.id().with(("rail", key)), Sense::click());
|
||
let on = theme::effect(ui.ctx(), response.id.with("on"), selected == Some(i) && !searching);
|
||
let st = interaction(ui, &response);
|
||
let content = theme::layer(p.on_surface_variant, p.on_secondary_container, on);
|
||
let target = pill(i as f32 * height);
|
||
if st.amount() > 0.0 {
|
||
ui.painter().rect_filled(target, theme::corner_radius(theme::FULL), p.on_surface.gamma_multiply(st.amount()));
|
||
}
|
||
if compact {
|
||
icon(ui, target.center(), glyph, theme::ICON, on > 0.5, content);
|
||
let short = match *key {
|
||
"adblock" => "Ads",
|
||
_ => label.split(' ').next().unwrap_or(label),
|
||
};
|
||
ui.painter().text(pos2(item.center().x, target.bottom() + theme::GAP_XS), Align2::CENTER_TOP, short, theme::font(theme::SMALL, Weight::Medium), theme::layer(p.on_surface_variant, p.on_surface, on));
|
||
} else {
|
||
icon(ui, pos2(item.left() + theme::GAP_L + theme::ICON / 2.0, item.center().y), glyph, theme::ICON, on > 0.5, content);
|
||
let weight = if on > 0.5 { Weight::Medium } else { Weight::Regular };
|
||
ui.painter().text(pos2(item.left() + theme::GAP_L + theme::ICON + theme::GAP_M, item.center().y), Align2::LEFT_CENTER, *label, theme::font(theme::BODY, weight), theme::layer(p.on_surface_variant, p.on_secondary_container, on));
|
||
}
|
||
if st.focus {
|
||
focus_ring(ui, target, target.height() / 2.0, &p);
|
||
}
|
||
let response = if compact { response.on_hover_text(*label) } else { response };
|
||
if response.clicked() {
|
||
f.ui.pages.settings_section = (*key).into();
|
||
f.ui.pages.settings_search.clear();
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
/// The search pill. Escape clears it.
|
||
fn search_field(ui: &mut Ui, f: &mut Frame) {
|
||
let p = theme::palette(ui.ctx());
|
||
let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), theme::CONTROL), Sense::hover());
|
||
let id = Id::new("settings-search");
|
||
let focused = ui.memory(|m| m.has_focus(id));
|
||
let ring = theme::effect(ui.ctx(), id.with("ring"), focused);
|
||
ui.painter().rect_filled(rect, theme::corner_radius(theme::FULL), p.surface_container_high);
|
||
if ring > 0.0 {
|
||
ui.painter().rect_stroke(rect, theme::corner_radius(theme::FULL), Stroke::new(2.0, p.primary.gamma_multiply(ring)), StrokeKind::Inside);
|
||
}
|
||
icon(ui, pos2(rect.left() + theme::GAP_L + theme::ICON / 2.0, rect.center().y), icons::SEARCH, theme::ICON, false, p.on_surface_variant);
|
||
let clear = !f.ui.pages.settings_search.is_empty();
|
||
let field = Rect::from_min_max(pos2(rect.left() + theme::GAP_L + theme::ICON + theme::GAP_M, rect.top()), pos2(rect.right() - if clear { 40.0 } else { theme::GAP_L }, rect.bottom()));
|
||
let mut child = ui.new_child(UiBuilder::new().max_rect(field).layout(egui::Layout::left_to_right(egui::Align::Center)));
|
||
let edit = egui::TextEdit::singleline(&mut f.ui.pages.settings_search).id(id).frame(egui::Frame::NONE).hint_text("Search settings").font(theme::font(theme::BODY, Weight::Regular)).desired_width(field.width());
|
||
let response = child.add(edit);
|
||
if response.has_focus() && ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||
f.ui.pages.settings_search.clear();
|
||
}
|
||
if clear {
|
||
let mut x = ui.new_child(UiBuilder::new().max_rect(Rect::from_center_size(pos2(rect.right() - 24.0, rect.center().y), Vec2::splat(theme::CONTROL_SMALL))));
|
||
if icon_button(&mut x, icons::CLOSE, "Clear search").clicked() {
|
||
f.ui.pages.settings_search.clear();
|
||
}
|
||
}
|
||
}
|
||
|
||
/// The page title; a sub-page gets a back button and its section's name above. Returns true when Back was clicked.
|
||
fn header(ui: &mut Ui, section: &str) -> bool {
|
||
let p = theme::palette(ui.ctx());
|
||
let sub = SUBPAGES.iter().any(|(k, _, _)| *k == section);
|
||
let mut back = false;
|
||
ui.add_space(theme::GAP_S);
|
||
ui.horizontal(|ui| {
|
||
ui.set_min_height(theme::CONTROL);
|
||
if sub {
|
||
back = icon_button(ui, icons::ARROW_BACK, &format!("Back to {}", label_of(parent_section(section)))).clicked();
|
||
ui.add_space(theme::GAP_XS);
|
||
} else {
|
||
ui.add_space(theme::GAP_L - ui.spacing().item_spacing.x);
|
||
}
|
||
ui.vertical(|ui| {
|
||
if sub {
|
||
ui.label(RichText::new(label_of(parent_section(section))).font(theme::font(theme::SMALL, Weight::Medium)).color(p.on_surface_variant));
|
||
}
|
||
ui.label(RichText::new(label_of(section)).font(theme::font(theme::HEADLINE, Weight::Medium)).color(p.on_surface));
|
||
});
|
||
});
|
||
ui.add_space(theme::GAP_XS);
|
||
back
|
||
}
|
||
|
||
/// Words that find a section besides its rows' own text.
|
||
fn section_keywords(key: &str) -> &'static str {
|
||
match key {
|
||
"general" => "startup home page title bar card",
|
||
"appearance" => "colour color palette dark light theme scheme seed wallpaper material you accent",
|
||
"toolbar" => "buttons icons",
|
||
"performance" => "memory energy battery gpu",
|
||
"privacy" => "proxy tor dns cookies fingerprint tracking",
|
||
"adblock" => "ads ublock easylist",
|
||
"passwords" => "vault login master",
|
||
"downloads" => "folder save",
|
||
"media" => "music video player drm",
|
||
"about" => "version update",
|
||
"newtab" => "new tab page clock greeting weather background shortcuts customize",
|
||
"keys" => "hotkeys keybindings",
|
||
_ => "",
|
||
}
|
||
}
|
||
|
||
/// Every section and sub-page that has a row matching `query`, with those rows highlighted. Sections are first
|
||
/// drawn unseen to count their matches, so search covers every row without a separate index.
|
||
fn search_results(ui: &mut Ui, f: &mut Frame, s: &mut Settings, query: &str) {
|
||
let p = theme::palette(ui.ctx());
|
||
let keys: Vec<&str> = SECTIONS.iter().map(|(k, _, _)| *k).chain(SUBPAGES.iter().map(|(k, _, _)| *k)).collect();
|
||
let mut hits = Vec::new();
|
||
let mut total = 0;
|
||
for key in keys {
|
||
highlight_rows(ui.ctx(), query);
|
||
let mut probe = ui.new_child(UiBuilder::new().max_rect(ui.max_rect()).id_salt(("settings-probe", key)).invisible());
|
||
draw_section(&mut probe, f, s, key);
|
||
let n = highlighted(ui.ctx());
|
||
total += n;
|
||
if n > 0 || label_of(key).to_lowercase().contains(query) || section_keywords(key).contains(query) {
|
||
hits.push(key);
|
||
}
|
||
}
|
||
ui.add_space(theme::GAP_S);
|
||
ui.horizontal(|ui| {
|
||
ui.add_space(theme::GAP_L - ui.spacing().item_spacing.x);
|
||
ui.vertical(|ui| {
|
||
ui.label(RichText::new("Search results").font(theme::font(theme::HEADLINE, Weight::Medium)).color(p.on_surface));
|
||
let text = match total {
|
||
0 if hits.is_empty() => String::new(),
|
||
0 => "Sections about this".to_owned(),
|
||
1 => "1 matching setting".to_owned(),
|
||
n => format!("{n} matching settings"),
|
||
};
|
||
if !text.is_empty() {
|
||
ui.label(RichText::new(text).font(theme::font(theme::SMALL, Weight::Regular)).color(p.on_surface_variant));
|
||
}
|
||
});
|
||
});
|
||
if hits.is_empty() {
|
||
ui.add_space(theme::GAP_XL * 2.0);
|
||
ui.vertical_centered(|ui| {
|
||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(theme::ICON_LARGE * 2.0), Sense::hover());
|
||
icon(ui, rect.center(), icons::SEARCH, theme::ICON_LARGE * 1.5, false, p.on_surface_variant);
|
||
ui.label(RichText::new(format!("No settings match \"{}\"", f.ui.pages.settings_search.trim())).font(theme::font(theme::TITLE, Weight::Medium)).color(p.on_surface));
|
||
ui.label(RichText::new("Try a shorter or different word, like colour, cookies or downloads").color(p.on_surface_variant));
|
||
});
|
||
highlight_rows(ui.ctx(), "");
|
||
return;
|
||
}
|
||
highlight_rows(ui.ctx(), query);
|
||
for key in hits {
|
||
ui.add_space(theme::GAP_L);
|
||
let glyph = SECTIONS.iter().find(|(k, _, _)| *k == rail_key(key)).map(|(_, _, g)| *g).unwrap_or(icons::SETTINGS);
|
||
let title = if SUBPAGES.iter().any(|(k, _, _)| *k == key) { format!("{} · {}", label_of(parent_section(key)), label_of(key)) } else { label_of(key).to_owned() };
|
||
let (line, _) = ui.allocate_exact_size(vec2(ui.available_width(), theme::CONTROL), Sense::hover());
|
||
icon(ui, pos2(line.left() + theme::GAP_L + theme::ICON / 2.0, line.center().y), glyph, theme::ICON, false, p.primary);
|
||
ui.painter().text(pos2(line.left() + theme::GAP_L + theme::ICON + theme::GAP_M, line.center().y), Align2::LEFT_CENTER, title, theme::font(theme::TITLE, Weight::Medium), p.on_surface);
|
||
let mut right = ui.new_child(UiBuilder::new().max_rect(line).layout(egui::Layout::right_to_left(egui::Align::Center)));
|
||
if button(&mut right, ButtonKind::Text, None, "Open").clicked() {
|
||
f.ui.pages.settings_section = key.to_owned();
|
||
f.ui.pages.settings_search.clear();
|
||
}
|
||
draw_section(ui, f, s, key);
|
||
}
|
||
highlight_rows(ui.ctx(), "");
|
||
}
|
||
|
||
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();
|
||
f.ui.pages.settings_search.clear();
|
||
}
|
||
|
||
/// A line of explanation above a section's cards.
|
||
fn intro(ui: &mut Ui, text: &str) {
|
||
let p = theme::palette(ui.ctx());
|
||
ui.add_space(theme::GAP_S);
|
||
ui.horizontal(|ui| {
|
||
ui.add_space(theme::GAP_L - ui.spacing().item_spacing.x);
|
||
ui.label(RichText::new(text).color(p.on_surface_variant));
|
||
});
|
||
}
|
||
|
||
/// A plain line inside a wide row, for an empty list.
|
||
fn none(ui: &mut Ui, text: &str) {
|
||
let p = theme::palette(ui.ctx());
|
||
ui.label(RichText::new(text).font(theme::font(theme::SMALL, Weight::Regular)).color(p.on_surface_variant));
|
||
}
|
||
|
||
/// Hosts as input chips; × removes one.
|
||
fn host_chips(ui: &mut Ui, hosts: &mut Vec<String>, remove: &str, empty: &str) {
|
||
if hosts.is_empty() {
|
||
none(ui, empty);
|
||
}
|
||
let mut gone = None;
|
||
for (i, host) in hosts.iter().enumerate() {
|
||
if input_chip(ui, host, remove) {
|
||
gone = Some(i);
|
||
}
|
||
}
|
||
if let Some(i) = gone {
|
||
hosts.remove(i);
|
||
}
|
||
}
|
||
|
||
fn general(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
section(ui, "Startup and search");
|
||
card(ui, |ui| {
|
||
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| text_field(ui, &mut s.startup.home_url, "https://…", 260.0));
|
||
let engine = s.search_engine_name();
|
||
if icon_link_row(ui, icons::SEARCH, "Search engine", &format!("{engine} · used in the address bar and on the new tab page")) {
|
||
open(f, "search");
|
||
}
|
||
});
|
||
section(ui, "Your browser");
|
||
card(ui, |ui| {
|
||
let profiles = f.shared.paths.profile_list().profiles.len();
|
||
if icon_link_row(ui, icons::ACCOUNT_CIRCLE, "Profiles", &format!("Using {} · {profiles} profile{}", f.shared.paths.profile, if profiles == 1 { "" } else { "s" })) {
|
||
open(f, "profiles");
|
||
}
|
||
if icon_link_row(ui, icons::DASHBOARD_CUSTOMIZE, "New tab page", "Shortcuts, background and what shows") {
|
||
open(f, "newtab");
|
||
}
|
||
let langs = if s.spell.langs.is_empty() { crate::spell::system_language() } else { s.spell.langs.join(", ") };
|
||
if icon_link_row(ui, icons::SPELLCHECK, "Spell check", &if s.spell.enabled { langs } else { "Off".into() }) {
|
||
open(f, "spell");
|
||
}
|
||
let custom = s.keys.len();
|
||
if icon_link_row(ui, icons::KEYBOARD, "Keyboard shortcuts", &if custom == 0 { "Default keys".to_owned() } else { format!("{custom} changed") }) {
|
||
open(f, "keys");
|
||
}
|
||
if icon_link_row(ui, icons::INPUT, "Import from another browser", "Bookmarks, history and settings from Chrome, Firefox, Edge, Brave and others") {
|
||
open(f, "import");
|
||
}
|
||
if icon_row(ui, icons::RESTART_ALT, "Setup", "Import, colours, privacy and search in one place", |ui| button(ui, ButtonKind::Tonal, None, "Run setup").clicked()) {
|
||
f.send(Command::ShowPage(Page::Welcome));
|
||
}
|
||
});
|
||
section(ui, "Window");
|
||
card(ui, |ui| {
|
||
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) {
|
||
let dark = f.palette().dark;
|
||
section(ui, "Colour");
|
||
card(ui, |ui| {
|
||
scheme_preview(ui, s);
|
||
row(ui, "Colour source", "Where the interface takes its colour from", |ui| segmented(ui, &mut s.theme.source, ColourSource::ALL));
|
||
if s.theme.source == ColourSource::Website {
|
||
row(ui, "When a site has no colour", "Website follows each page's theme colour or favicon", |ui| segmented(ui, &mut s.theme.fallback, ColourFallback::ALL));
|
||
}
|
||
let using_palette = s.theme.source == ColourSource::Palette || (s.theme.source == ColourSource::Website && s.theme.fallback == ColourFallback::Palette);
|
||
let palette_note = if using_palette { "Each colour makes a whole scheme" } else { "Picking one switches the colour source to Palette" };
|
||
wide_row(ui, "Palette", palette_note, |ui| {
|
||
if let Some(hex) = swatches(ui, s, dark, using_palette) {
|
||
s.theme.preset = hex.to_owned();
|
||
match s.theme.source {
|
||
ColourSource::Website => s.theme.fallback = ColourFallback::Palette,
|
||
_ => s.theme.source = ColourSource::Palette,
|
||
}
|
||
}
|
||
});
|
||
row(ui, "Custom colour", "Any colour as the seed; picking one switches the colour source to Custom", |ui| {
|
||
let before = s.theme.custom.clone();
|
||
custom_colour(ui, &mut s.theme.custom);
|
||
if s.theme.custom != before && crate::theme::parse_hex(&s.theme.custom).is_some() {
|
||
s.theme.source = ColourSource::Custom;
|
||
}
|
||
});
|
||
wide_row(ui, "Style", "How much colour the scheme takes from the seed", |ui| {
|
||
let mut v = s.theme.variant.clone();
|
||
let options: Vec<(String, &str)> = crate::theme::VARIANTS.iter().map(|(k, l)| ((*k).to_owned(), *l)).collect();
|
||
if choice_chips(ui, &mut v, &options) {
|
||
s.theme.variant = v;
|
||
}
|
||
});
|
||
row(ui, "Contrast", &contrast_label(s.theme.contrast), |ui| {
|
||
if slider(ui, &mut s.theme.contrast, -1.0..=1.0, 200.0, "Contrast") {
|
||
// Snap to the M3 levels near them, so Standard is easy to get back to.
|
||
for level in [-1.0, 0.0, 0.5, 1.0] {
|
||
if (s.theme.contrast - level).abs() < 0.04 {
|
||
s.theme.contrast = level;
|
||
}
|
||
}
|
||
}
|
||
});
|
||
});
|
||
section(ui, "Mode and shape");
|
||
card(ui, |ui| {
|
||
row(ui, "Mode", "", |ui| segmented(ui, &mut s.theme.mode, ThemeMode::ALL));
|
||
row(ui, "Motion", "Speed of every animation; Off stops them", |ui| segmented(ui, &mut s.ui.motion, Motion::ALL));
|
||
row(ui, "Roundness", "Corners of cards, buttons and fields", |ui| segmented(ui, &mut s.ui.roundness, Roundness::ALL));
|
||
row(ui, "Interface size", &format!("{:.0} %", s.ui.scale * 100.0), |ui| {
|
||
let mut v = s.ui.scale;
|
||
if slider(ui, &mut v, 0.75..=1.75, 200.0, "Interface size") {
|
||
s.ui.scale = (v * 20.0).round() / 20.0;
|
||
}
|
||
});
|
||
});
|
||
section(ui, "Websites");
|
||
card(ui, |ui| {
|
||
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);
|
||
});
|
||
}
|
||
|
||
fn contrast_label(c: f32) -> String {
|
||
let name = match c {
|
||
c if c < -0.25 => "Reduced",
|
||
c if c < 0.25 => "Standard",
|
||
c if c < 0.75 => "Medium",
|
||
_ => "High",
|
||
};
|
||
format!("{name} ({c:+.2})")
|
||
}
|
||
|
||
/// The scheme as it is now: a small browser drawn in its roles, and the four key colours.
|
||
fn scheme_preview(ui: &mut Ui, s: &Settings) {
|
||
let p = theme::palette(ui.ctx());
|
||
let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), 168.0), Sense::hover());
|
||
let painter = ui.painter();
|
||
let inner = rect.shrink2(vec2(theme::GAP_L, theme::GAP_M));
|
||
let r = |token| theme::corner_radius(theme::radius(ui.ctx(), token));
|
||
let mock = Rect::from_min_size(inner.min, vec2((inner.width() * 0.62).min(360.0), inner.height()));
|
||
// Window: chrome, a tab, the address pill, then the page card.
|
||
painter.rect_filled(mock, r(theme::M), p.surface_container_high);
|
||
let tab = Rect::from_min_size(mock.min + vec2(theme::GAP_S, theme::GAP_S), vec2(72.0, 18.0));
|
||
painter.rect_filled(tab, theme::corner_radius(theme::FULL), p.secondary_container);
|
||
painter.rect_filled(Rect::from_min_size(tab.min + vec2(theme::GAP_S, 7.0), vec2(40.0, 4.0)), theme::corner_radius(2.0), p.on_secondary_container.gamma_multiply(0.7));
|
||
let address = Rect::from_min_max(pos2(mock.left() + theme::GAP_S, tab.bottom() + theme::GAP_XS + 2.0), pos2(mock.right() - theme::GAP_S, tab.bottom() + 26.0));
|
||
painter.rect_filled(address, theme::corner_radius(theme::FULL), p.surface_container_highest);
|
||
painter.circle_filled(pos2(address.right() - 10.0, address.center().y), 4.0, p.primary);
|
||
let page = Rect::from_min_max(pos2(mock.left() + theme::GAP_S, address.bottom() + theme::GAP_S), mock.max - vec2(theme::GAP_S, theme::GAP_S));
|
||
painter.rect_filled(page, r(theme::S), p.surface_container_lowest);
|
||
let x = page.left() + theme::GAP_M;
|
||
painter.rect_filled(Rect::from_min_size(pos2(x, page.top() + theme::GAP_M), vec2(page.width() * 0.45, 8.0)), theme::corner_radius(4.0), p.on_surface);
|
||
painter.rect_filled(Rect::from_min_size(pos2(x, page.top() + theme::GAP_M + 14.0), vec2(page.width() * 0.6, 5.0)), theme::corner_radius(3.0), p.on_surface_variant.gamma_multiply(0.6));
|
||
let y = page.bottom() - theme::GAP_M - 20.0;
|
||
painter.rect_filled(Rect::from_min_size(pos2(x, y), vec2(64.0, 20.0)), theme::corner_radius(theme::FULL), p.primary);
|
||
painter.rect_filled(Rect::from_min_size(pos2(x + 8.0 + 64.0, y), vec2(52.0, 20.0)), r(theme::XS), p.tertiary_container);
|
||
let track = Rect::from_min_size(pos2(page.right() - theme::GAP_M - 36.0, y), vec2(36.0, 20.0));
|
||
painter.rect_filled(track, theme::corner_radius(10.0), p.primary);
|
||
painter.circle_filled(pos2(track.right() - 10.0, track.center().y), 7.0, p.on_primary);
|
||
// Key colours.
|
||
let roles = [("Primary", p.primary), ("Secondary", p.secondary), ("Tertiary", p.tertiary), ("Neutral", p.on_surface_variant)];
|
||
let column = Rect::from_min_max(pos2(mock.right() + theme::GAP_XL, inner.top() + 20.0), inner.max);
|
||
let step = column.height() / roles.len() as f32;
|
||
for (i, (name, colour)) in roles.iter().enumerate() {
|
||
let cy = column.top() + step * (i as f32 + 0.5);
|
||
painter.circle_filled(pos2(column.left() + 12.0, cy), 12.0, *colour);
|
||
painter.circle_stroke(pos2(column.left() + 12.0, cy), 12.0, Stroke::new(1.0, p.outline_variant));
|
||
painter.text(pos2(column.left() + 32.0, cy), Align2::LEFT_CENTER, *name, theme::font(theme::SMALL, Weight::Medium), p.on_surface);
|
||
}
|
||
let source = match s.theme.source {
|
||
ColourSource::Website => "From the website",
|
||
ColourSource::System => "System accent",
|
||
ColourSource::Palette => "Palette colour",
|
||
ColourSource::Custom => "Custom colour",
|
||
};
|
||
painter.text(pos2(column.left(), inner.top()), Align2::LEFT_TOP, source, theme::font(theme::SMALL, Weight::Regular), p.on_surface_variant);
|
||
}
|
||
|
||
/// Each preset as a scheme swatch (primary over secondary and tertiary, like a wallpaper colour). Returns the hex
|
||
/// of the one clicked.
|
||
fn swatches(ui: &mut Ui, s: &Settings, dark: bool, using_palette: bool) -> Option<&'static str> {
|
||
let p = theme::palette(ui.ctx());
|
||
// Building a scheme takes a moment, so keep them while the mode, style and contrast stay.
|
||
let key = format!("{dark}-{}-{:.2}", s.theme.variant, s.theme.contrast);
|
||
let cache_id = Id::new("settings-swatches");
|
||
let cached: Option<(String, Vec<[Color32; 3]>)> = ui.data(|d| d.get_temp(cache_id));
|
||
let colours = match cached {
|
||
Some((k, c)) if k == key => c,
|
||
_ => {
|
||
let c: Vec<[Color32; 3]> = crate::theme::PRESETS
|
||
.iter()
|
||
.map(|hex| {
|
||
let seed = crate::theme::parse_hex(hex).unwrap_or_default();
|
||
let q = Palette::new(seed, dark, &s.theme.variant, s.theme.contrast);
|
||
[q.primary, q.secondary_container, q.tertiary_container]
|
||
})
|
||
.collect();
|
||
ui.data_mut(|d| d.insert_temp(cache_id, (key, c.clone())));
|
||
c
|
||
},
|
||
};
|
||
let mut picked = None;
|
||
ui.spacing_mut().item_spacing = vec2(theme::GAP_S, theme::GAP_S);
|
||
for (hex, [top, left, right]) in crate::theme::PRESETS.iter().zip(colours) {
|
||
let (rect, response) = ui.allocate_exact_size(Vec2::splat(52.0), Sense::click());
|
||
let selected = using_palette && s.theme.preset.eq_ignore_ascii_case(hex);
|
||
let st = interaction(ui, &response);
|
||
let on = theme::effect(ui.ctx(), response.id.with("on"), selected);
|
||
let c = rect.center();
|
||
// Selected swatches shrink inside a ring; press squeezes.
|
||
let radius = 22.0 - 4.0 * on - 2.0 * st.press.clamp(0.0, 1.0);
|
||
if st.amount() > 0.0 {
|
||
ui.painter().circle_filled(c, 26.0, p.on_surface.gamma_multiply(st.amount()));
|
||
}
|
||
let arc = |from: f32, to: f32| -> Vec<egui::Pos2> {
|
||
let steps = 24;
|
||
let mut pts = vec![c];
|
||
pts.extend((0..=steps).map(|i| {
|
||
let a = from + (to - from) * i as f32 / steps as f32;
|
||
c + radius * Vec2::angled(a)
|
||
}));
|
||
pts
|
||
};
|
||
use std::f32::consts::PI;
|
||
ui.painter().add(Shape::convex_polygon(arc(PI, 2.0 * PI), top, Stroke::NONE));
|
||
ui.painter().add(Shape::convex_polygon(arc(PI / 2.0, PI), left, Stroke::NONE));
|
||
ui.painter().add(Shape::convex_polygon(arc(0.0, PI / 2.0), right, Stroke::NONE));
|
||
ui.painter().circle_stroke(c, radius, Stroke::new(1.0, p.outline_variant));
|
||
if on > 0.0 {
|
||
ui.painter().circle_stroke(c, 24.0, Stroke::new(2.5, p.primary.gamma_multiply(on)));
|
||
ui.painter().circle_filled(c, 10.0 * on, p.surface_container_lowest);
|
||
icon(ui, c, icons::CHECK, 16.0 * on, false, p.primary);
|
||
}
|
||
if st.focus {
|
||
focus_ring(ui, rect.shrink(1.0), 25.0, &p);
|
||
}
|
||
if response.on_hover_text(*hex).clicked() {
|
||
picked = Some(*hex);
|
||
}
|
||
}
|
||
picked
|
||
}
|
||
|
||
/// The custom colour: a hex field and a round swatch that opens a colour picker.
|
||
fn custom_colour(ui: &mut Ui, hex: &mut String) {
|
||
let p = theme::palette(ui.ctx());
|
||
let mut colour = crate::theme::parse_hex(hex).unwrap_or(Color32::from_rgb(0x3F, 0x6E, 0xE8));
|
||
let (rect, response) = ui.allocate_exact_size(Vec2::splat(theme::CONTROL), Sense::click());
|
||
let st = interaction(ui, &response);
|
||
if st.amount() > 0.0 {
|
||
ui.painter().circle_filled(rect.center(), 20.0, p.on_surface.gamma_multiply(st.amount()));
|
||
}
|
||
ui.painter().circle_filled(rect.center(), 15.0 - 2.0 * st.press.clamp(0.0, 1.0), colour);
|
||
ui.painter().circle_stroke(rect.center(), 15.0, Stroke::new(1.0, p.outline));
|
||
if st.focus {
|
||
focus_ring(ui, rect, 20.0, &p);
|
||
}
|
||
let response = response.on_hover_text("Pick a colour");
|
||
egui::Popup::from_toggle_button_response(&response).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).frame(super::super::menus::surface(&p, ui.ctx())).show(|ui| {
|
||
if egui::widgets::color_picker::color_picker_color32(ui, &mut colour, egui::widgets::color_picker::Alpha::Opaque) {
|
||
*hex = crate::theme::to_hex(colour);
|
||
}
|
||
});
|
||
text_field(ui, hex, "#3F6EE8", 96.0);
|
||
}
|
||
|
||
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) {
|
||
for (group, items) in TOOLBAR_GROUPS {
|
||
let shown = items.iter().filter(|(k, _)| s.toolbar_has(k)).count();
|
||
section(ui, &format!("{group} · {shown} of {} shown", items.len()));
|
||
card(ui, |ui| {
|
||
for (key, label) in *items {
|
||
let mut on = s.toolbar_has(key);
|
||
if icon_row(ui, super::super::widgets::glyph(key), label, "", |ui| switch(ui, &mut on)) {
|
||
if on {
|
||
s.ui.toolbar.push((*key).to_owned());
|
||
} else {
|
||
s.ui.toolbar.retain(|k| k != key);
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
section(ui, "Bookmarks");
|
||
card(ui, |ui| {
|
||
row(ui, "Bookmarks bar", "Under the toolbar (Ctrl+Shift+B shows or hides it)", |ui| segmented(ui, &mut s.ui.bookmarks_bar, BookmarksBar::ALL));
|
||
if icon_link_row(ui, icons::BOOKMARKS, "Bookmark manager", "Folders, order, import and export") {
|
||
f.send(Command::ShowPage(Page::Bookmarks));
|
||
}
|
||
});
|
||
}
|
||
|
||
fn performance(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
section(ui, "Memory");
|
||
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 icon_row(ui, icons::MEMORY, "Memory", &desc, |ui| button(ui, ButtonKind::Tonal, None, "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));
|
||
});
|
||
section(ui, "Tabs");
|
||
card(ui, |ui| {
|
||
row(ui, "Memory saver", "Unloads tabs you haven't looked at; they load again when you return", |ui| {
|
||
let opts: &[(u32, &str)] = &[(0, "Off"), (15, "15 min"), (30, "30 min"), (60, "1 h"), (120, "2 h")];
|
||
segmented(ui, &mut s.perf.discard_min, opts)
|
||
});
|
||
limited_row(ui, "Freeze background tabs", "Hidden tabs stop drawing after a while", "Servo can't pause their scripts; unloading frees memory", |ui| {
|
||
let opts: &[(u32, &str)] = &[(0, "Never"), (1, "1 min"), (5, "5 min"), (15, "15 min")];
|
||
segmented(ui, &mut s.perf.freeze_min, opts)
|
||
});
|
||
wide_row(ui, "Always keep these sites active", "Never unloaded or frozen", |ui| {
|
||
host_chips(ui, &mut s.perf.keep_active, "Remove", "No sites yet");
|
||
ui.end_row();
|
||
text_field(ui, &mut f.ui.pages.keep_active_input, "example.com", 200.0);
|
||
let typed = f.ui.pages.keep_active_input.trim().trim_start_matches("www.").to_owned();
|
||
if ui.add_enabled_ui(!typed.is_empty(), |ui| button(ui, ButtonKind::Tonal, Some(icons::ADD), "Add")).inner.clicked() {
|
||
s.perf.keep_active.push(typed);
|
||
f.ui.pages.keep_active_input.clear();
|
||
}
|
||
if let Some(host) = f.tab().map(|t| t.host()).filter(|h| !h.is_empty() && !s.perf.keep_active.contains(h))
|
||
&& button(ui, ButtonKind::Text, None, &format!("Add {host}")).clicked()
|
||
{
|
||
s.perf.keep_active.push(host);
|
||
}
|
||
});
|
||
switch_row(ui, "Load restored tabs when opened", "On startup only the tabs you open load", &mut s.perf.lazy_restore);
|
||
});
|
||
section(ui, "Speed");
|
||
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);
|
||
limited_row(ui, "Save data", "Tells pages to be lighter and stops videos preloading", "Servo can't send the Save-Data header", |ui| switch(ui, &mut s.privacy.save_data));
|
||
row(ui, "Hardware acceleration", "Use the GPU. Turn off if pages show up black or blank; Off uses software rendering (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, "Connection");
|
||
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(),
|
||
};
|
||
icon_row(ui, icons::VPN_LOCK, "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| text_field(ui, &mut s.vpn.custom, "socks5://127.0.0.1:1080", 260.0));
|
||
}
|
||
}
|
||
wide_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| {
|
||
choice_chips(ui, &mut s.privacy.doh, DohProvider::ALL);
|
||
});
|
||
if s.privacy.doh == DohProvider::Custom {
|
||
row(ui, "Secure DNS address", "https://…/dns-query", |ui| text_field(ui, &mut s.privacy.doh_custom, "https://dns.example/dns-query", 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() {
|
||
wide_row(ui, "Sites allowed without HTTPS", "", |ui| host_chips(ui, &mut s.privacy.https_exceptions, "Ask again on this site", ""));
|
||
}
|
||
});
|
||
section(ui, "Tracking and fingerprinting");
|
||
card(ui, |ui| {
|
||
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);
|
||
limited_row(ui, "Send Do Not Track and Global Privacy Control", "Pages see navigator.globalPrivacyControl", "Servo can't add the request headers yet", |ui| switch(ui, &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);
|
||
unavailable_row(ui, "Block third-party cookies", "Servo 0.7 has no cookie policy setting");
|
||
switch_row(ui, "Google sign-in", "Looks like Firefox on accounts.google.com so Google lets you sign in", &mut s.privacy.google_signin);
|
||
});
|
||
section(ui, "Site data");
|
||
card(ui, |ui| {
|
||
if icon_link_row(ui, icons::TUNE, "Site settings", "Location, camera, microphone, notifications, pop-ups and other permissions") {
|
||
open(f, "permissions");
|
||
}
|
||
if icon_row(ui, icons::DELETE, "Delete browsing data", "History, cookies, cache and more", |ui| button(ui, ButtonKind::Tonal, None, "Delete…").clicked()) {
|
||
f.send(Command::ShowPage(Page::ClearData));
|
||
}
|
||
wide_row(ui, "Delete when Nacre closes", "", |ui| {
|
||
toggle_chips(ui, &mut s.privacy.clear_on_exit, &[("history", "History"), ("cookies", "Cookies"), ("cache", "Cache"), ("downloads", "Downloads list")]);
|
||
});
|
||
wide_row(ui, "Sites where ad blocking is paused", "", |ui| host_chips(ui, &mut s.adblock.allow, "Block ads here again", "None"));
|
||
});
|
||
section(ui, "Developers");
|
||
card(ui, |ui| {
|
||
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| text_field(ui, &mut s.web.user_agent, "Default", 260.0));
|
||
});
|
||
}
|
||
|
||
fn adblock(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
section(ui, "Blocking");
|
||
card(ui, |ui| {
|
||
icon_row(ui, icons::SHIELD, "Block ads and trackers", &format!("{} blocked in total", s.adblock.total), |ui| switch(ui, &mut s.adblock.enabled));
|
||
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);
|
||
});
|
||
section(ui, "Filter lists");
|
||
card(ui, |ui| {
|
||
let on = s.adblock.lists.len();
|
||
if icon_link_row(ui, icons::FILTER_LIST, "Filter lists", &format!("{on} of {} on", crate::adblock::LISTS.len())) {
|
||
open(f, "lists");
|
||
}
|
||
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}"), |ui| button(ui, ButtonKind::Tonal, Some(icons::SYNC), "Update now").clicked()) {
|
||
f.send(Command::UpdateFilterLists);
|
||
}
|
||
row(ui, "Update lists automatically", "Only re-downloads lists that changed", |ui| {
|
||
let opts: &[(u32, &str)] = &[(0, "Manually"), (1, "Daily"), (7, "Weekly"), (30, "Monthly")];
|
||
segmented(ui, &mut s.adblock.update_days, opts)
|
||
});
|
||
});
|
||
}
|
||
|
||
fn lists(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
let dir = f.shared.paths.filter_lists();
|
||
let failures = f.shared.adblock.failures.read().map(|m| m.clone()).unwrap_or_default();
|
||
let mut groups: Vec<&str> = Vec::new();
|
||
for list in crate::adblock::LISTS {
|
||
if !groups.contains(&list.group) {
|
||
groups.push(list.group);
|
||
}
|
||
}
|
||
for group in groups {
|
||
section(ui, group);
|
||
card(ui, |ui| {
|
||
for list in crate::adblock::LISTS.iter().filter(|l| l.group == group) {
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
section(ui, "Your lists");
|
||
card(ui, |ui| {
|
||
wide_row(ui, "Lists from the web", "Any Adblock Plus filter list or hosts file", |ui| {
|
||
if s.adblock.custom.is_empty() {
|
||
none(ui, "None added");
|
||
}
|
||
let mut remove = None;
|
||
for (i, url) in s.adblock.custom.iter().enumerate() {
|
||
if input_chip(ui, &util::ellipsize(url, 60), "Remove this list") {
|
||
remove = Some(i);
|
||
}
|
||
}
|
||
if let Some(i) = remove {
|
||
s.adblock.custom.remove(i);
|
||
}
|
||
ui.end_row();
|
||
text_field(ui, &mut f.ui.pages.new_list_url, "https://… filter list or hosts file", 360.0);
|
||
let ok = f.ui.pages.new_list_url.trim().starts_with("http");
|
||
if ui.add_enabled_ui(ok, |ui| button(ui, ButtonKind::Tonal, Some(icons::ADD), "Add list")).inner.clicked() {
|
||
s.adblock.custom.push(f.ui.pages.new_list_url.trim().to_owned());
|
||
f.ui.pages.new_list_url.clear();
|
||
}
|
||
});
|
||
wide_row(ui, "Your own rules", "Adblock Plus / uBlock syntax, one per line", |ui| {
|
||
ui.add(egui::TextEdit::multiline(&mut s.adblock.own_rules).code_editor().desired_rows(6).desired_width(f32::INFINITY).margin(vec2(theme::GAP_M, theme::GAP_S)));
|
||
});
|
||
});
|
||
}
|
||
|
||
fn passwords(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
section(ui, "Saving and filling");
|
||
card(ui, |ui| {
|
||
if icon_link_row(ui, icons::PASSWORD, "Saved passwords, addresses and cards", "Open the password manager") {
|
||
f.send(Command::ShowPage(Page::Passwords));
|
||
}
|
||
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);
|
||
});
|
||
section(ui, "Security");
|
||
card(ui, |ui| {
|
||
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, "Clear copied passwords from the clipboard after", "0 = never", |ui| number(ui, &mut s.vault.clipboard_clear, 0..=600, " s"));
|
||
});
|
||
section(ui, "Generated passwords");
|
||
card(ui, |ui| {
|
||
row(ui, "Length", "", |ui| number(ui, &mut s.vault.gen_length, 8..=128, " characters"));
|
||
switch_row(ui, "Symbols", "Adds characters like ! # % to generated passwords", &mut s.vault.gen_symbols);
|
||
});
|
||
}
|
||
|
||
fn downloads(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
section(ui, "Saving");
|
||
card(ui, |ui| {
|
||
let dir = s.downloads.dir.display().to_string();
|
||
if icon_row(ui, icons::FOLDER, "Save to", &dir, |ui| button(ui, ButtonKind::Outlined, Some(icons::FOLDER_OPEN), "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 icon_link_row(ui, icons::DOWNLOAD, "Download managers", &format!("New downloads go to {using}")) {
|
||
open(f, "managers");
|
||
}
|
||
});
|
||
}
|
||
|
||
fn managers(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
intro(ui, "Hand downloads to another program. Local ports are never reached through the VPN. If the manager doesn't answer, Nacre downloads the file itself.");
|
||
section(ui, "Where downloads go");
|
||
card(ui, |ui| {
|
||
wide_row(ui, "New downloads go to", "Turn a manager on below to choose it here", |ui| {
|
||
let mut options = vec![("builtin".to_owned(), "Nacre")];
|
||
options.extend(crate::net::dlm::available().filter(|m| s.downloads.managers.iter().any(|k| k == m.key)).map(|m| (m.key.to_owned(), m.name)));
|
||
choice_chips(ui, &mut s.downloads.manager, &options);
|
||
});
|
||
});
|
||
let statuses = f.shared.dlm_status.borrow().clone();
|
||
section(ui, "Managers");
|
||
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 {
|
||
let port = |ui: &mut Ui, v: &mut u16| ui.add(egui::DragValue::new(v).range(1..=65535));
|
||
match m.key {
|
||
"abdm" => {
|
||
row(ui, "Port", "", |ui| port(ui, &mut s.downloads.abdm_port));
|
||
},
|
||
"aria2" => {
|
||
row(ui, "RPC port", "", |ui| port(ui, &mut s.downloads.aria2_port));
|
||
row(ui, "RPC secret", "Optional", |ui| ui.add(egui::TextEdit::singleline(&mut s.downloads.aria2_secret).password(true).desired_width(200.0).margin(vec2(theme::GAP_M, theme::GAP_S))));
|
||
},
|
||
"jdownloader" => {
|
||
row(ui, "Port", "", |ui| port(ui, &mut s.downloads.jd_port));
|
||
},
|
||
"fdm" => {
|
||
row(ui, "Program", "Found automatically when empty", |ui| text_field(ui, &mut s.downloads.fdm_path, "Automatic", 260.0));
|
||
},
|
||
"idm" => {
|
||
row(ui, "Program", "Found automatically when empty", |ui| text_field(ui, &mut s.downloads.idm_path, "Automatic", 260.0));
|
||
},
|
||
_ => {},
|
||
}
|
||
}
|
||
});
|
||
ui.add_space(theme::GAP_S);
|
||
}
|
||
ui.horizontal(|ui| {
|
||
ui.add_space(theme::GAP_S);
|
||
if button(ui, ButtonKind::Outlined, Some(icons::REFRESH), "Check again").clicked() {
|
||
f.send(Command::PingManagers);
|
||
}
|
||
});
|
||
}
|
||
|
||
fn media(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
section(ui, "Player");
|
||
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);
|
||
if !s.media.muted_sites.is_empty() {
|
||
wide_row(ui, "Muted sites", "", |ui| host_chips(ui, &mut s.media.muted_sites, "Unmute", ""));
|
||
}
|
||
});
|
||
section(ui, "More");
|
||
card(ui, |ui| {
|
||
let status = if s.rpc.enabled { f.shared.presence_status.borrow().clone() } else { "Off".into() };
|
||
if icon_link_row(ui, icons::SPORTS_ESPORTS, "Discord Rich Presence", &status) {
|
||
open(f, "discord");
|
||
}
|
||
unavailable_row(ui, "Protected content (Widevine)", "Netflix, Hulu, Spotify and other DRM video can't play: the Servo engine has no DRM support");
|
||
});
|
||
}
|
||
|
||
fn discord(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
intro(ui, "Shows what you watch or listen to on your Discord profile, through the Discord app or arRPC (Vesktop).");
|
||
section(ui, "Activity");
|
||
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| text_field(ui, &mut s.rpc.client_id, "Application ID", 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);
|
||
});
|
||
section(ui, "Supported sites");
|
||
card(ui, |ui| {
|
||
for (key, name, kind, _) in crate::discord::SITES {
|
||
row(ui, name, kind, |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());
|
||
}
|
||
}
|
||
let mut id = s.rpc.site_ids.get(*key).cloned().unwrap_or_default();
|
||
if text_field(ui, &mut id, "Own app ID", 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());
|
||
}
|
||
}
|
||
});
|
||
}
|
||
wide_row(ui, "More sites to report", "Host names, comma separated", |ui| {
|
||
let mut custom = s.rpc.custom.join(", ");
|
||
if text_field(ui, &mut custom, "example.com, music.example.org", ui.available_width()).changed() {
|
||
s.rpc.custom = custom.split(',').map(|h| h.trim().to_owned()).filter(|h| !h.is_empty()).collect();
|
||
}
|
||
});
|
||
});
|
||
}
|
||
|
||
fn about(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
section(ui, "Nacre");
|
||
card(ui, |ui| {
|
||
icon_row(ui, icons::INFO, &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" }), |ui| {
|
||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(theme::CONTROL_SMALL), Sense::hover());
|
||
ui.painter().circle_filled(rect.center(), 12.0, accent);
|
||
});
|
||
let p = &f.shared.paths;
|
||
row(ui, "Profile", &format!("{}\n{}\n{}", p.config.display(), p.data.display(), p.cache.display()), |ui| {
|
||
if icon_button(ui, icons::FOLDER_OPEN, "Open the data folder").clicked() {
|
||
util::open_external(&p.data.to_string_lossy());
|
||
}
|
||
});
|
||
});
|
||
section(ui, "Updates");
|
||
card(ui, |ui| {
|
||
let status = f.shared.update_status.borrow().clone();
|
||
if row(ui, "Check for updates", &status, |ui| button(ui, ButtonKind::Tonal, Some(icons::SYNC), "Check now").clicked()) {
|
||
f.send(Command::CheckUpdates);
|
||
}
|
||
switch_row(ui, "Check for updates automatically", "Once a day", &mut s.update.auto_check);
|
||
row(ui, "Release page", "Where Nacre's releases are published (Forgejo, Gitea or GitHub)", |ui| text_field(ui, &mut s.update.repo, "https://…", 300.0));
|
||
});
|
||
}
|
||
|
||
fn profiles(ui: &mut Ui, f: &mut Frame) {
|
||
intro(ui, "Each profile has its own history, bookmarks, passwords, cookies and settings.");
|
||
let list = f.shared.paths.profile_list();
|
||
section(ui, "Profiles");
|
||
card(ui, |ui| {
|
||
for name in &list.profiles {
|
||
let current = *name == f.shared.paths.profile;
|
||
icon_row(ui, icons::ACCOUNT_CIRCLE, name, if current { "This profile" } else { "" }, |ui| {
|
||
if !current {
|
||
if button(ui, ButtonKind::Tonal, None, "Open").clicked() {
|
||
f.send(Command::SwitchProfile(name.clone()));
|
||
}
|
||
if button(ui, ButtonKind::Text, None, "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),
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
wide_row(ui, "New profile", "", |ui| {
|
||
text_field(ui, &mut f.ui.pages.new_profile, "Name", 220.0);
|
||
let ok = !f.ui.pages.new_profile.trim().is_empty();
|
||
if ui.add_enabled_ui(ok, |ui| button(ui, ButtonKind::Filled, Some(icons::ADD), "Add and open")).inner.clicked() {
|
||
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 with");
|
||
card(ui, |ui| {
|
||
for (key, name, url, _) in s.search_engines() {
|
||
let chosen = s.startup.search_engine == key;
|
||
row(ui, &name, &util::ellipsize(&url, 60), |ui| {
|
||
if let Some(custom) = key.strip_prefix("custom:")
|
||
&& icon_button(ui, icons::DELETE, "Remove this search engine").clicked()
|
||
{
|
||
s.startup.custom_engines.retain(|(n, _)| n != custom);
|
||
if s.startup.search_engine == key {
|
||
s.startup.search_engine = "duckduckgo".into();
|
||
}
|
||
}
|
||
let glyph = if chosen { icons::CHECK_CIRCLE } else { icons::RADIO_BUTTON_UNCHECKED };
|
||
if icon_toggle(ui, glyph, &format!("Search with {name}"), chosen).clicked() {
|
||
s.startup.search_engine = key.clone();
|
||
}
|
||
});
|
||
}
|
||
wide_row(ui, "Add a search engine", "%s in the address stands for what you search for", |ui| {
|
||
text_field(ui, &mut f.ui.pages.new_engine.0, "Name", 140.0);
|
||
text_field(ui, &mut f.ui.pages.new_engine.1, "https://example.com/search?q=%s", 300.0);
|
||
let ok = !f.ui.pages.new_engine.0.trim().is_empty() && f.ui.pages.new_engine.1.contains("%s");
|
||
if ui.add_enabled_ui(ok, |ui| button(ui, ButtonKind::Tonal, Some(icons::ADD), "Add")).inner.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()));
|
||
}
|
||
});
|
||
});
|
||
section(ui, "Suggestions");
|
||
card(ui, |ui| {
|
||
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);
|
||
if row(ui, "Dictionaries", &f.shared.spell_status.borrow().clone(), |ui| button(ui, ButtonKind::Text, Some(icons::REFRESH), "Reload").clicked()) {
|
||
f.send(Command::ReloadSpeller);
|
||
}
|
||
wide_row(ui, "Languages", "None chosen uses the system language. Missing dictionaries are downloaded once.", |ui| {
|
||
toggle_chips(ui, &mut s.spell.langs, crate::spell::LANGUAGES);
|
||
});
|
||
});
|
||
}
|
||
|
||
fn keys(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
intro(ui, "Click a shortcut and press the new keys. Esc cancels, Backspace removes it.");
|
||
// Record a key press for the action being changed (not in the unseen pass that search makes).
|
||
if let Some(action) = f.ui.pages.capture_key
|
||
&& ui.is_visible()
|
||
{
|
||
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);
|
||
section(ui, "Shortcuts");
|
||
card(ui, |ui| {
|
||
for (action, key, label, _) in Action::ALL {
|
||
let shortcuts: Vec<String> = map.shortcuts(*action).iter().map(Shortcut::label).collect();
|
||
let capturing = f.ui.pages.capture_key == Some(*action);
|
||
let changed = s.keys.contains_key(*key);
|
||
row(ui, label, if changed { "Changed" } else { "" }, |ui| {
|
||
if changed && icon_button(ui, icons::UNDO, "Reset to the default").clicked() {
|
||
s.keys.remove(*key);
|
||
}
|
||
let text = if capturing { "Press keys…".to_owned() } else if shortcuts.is_empty() { "None".to_owned() } else { shortcuts.join(", ") };
|
||
let kind = if capturing { ButtonKind::Tonal } else { ButtonKind::Outlined };
|
||
if button(ui, kind, None, &text).clicked() {
|
||
f.ui.pages.capture_key = Some(*action);
|
||
}
|
||
});
|
||
}
|
||
});
|
||
if !s.keys.is_empty() {
|
||
ui.add_space(theme::GAP_M);
|
||
ui.horizontal(|ui| {
|
||
ui.add_space(theme::GAP_S);
|
||
if button(ui, ButtonKind::Outlined, Some(icons::UNDO), "Reset all shortcuts").clicked() {
|
||
s.keys.clear();
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
fn import(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
let sources = f.shared.import_sources.borrow().clone();
|
||
section(ui, "Browsers on this computer");
|
||
card(ui, |ui| {
|
||
if sources.is_empty() {
|
||
row(ui, "No other browsers found", "Chrome, Firefox, Edge, Brave and others show here when they are installed", |_| ());
|
||
}
|
||
for (i, src) in sources.iter().enumerate() {
|
||
let id = 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));
|
||
let done = s.startup.import_done.contains(&src.name());
|
||
wide_row(ui, &src.name(), if done { "Imported before" } else { "" }, |ui| {
|
||
for (on, label) in [(&mut b, "Bookmarks"), (&mut h, "History"), (&mut st, "Home page and search engine")] {
|
||
if chip(ui, on.then_some(icons::CHECK), label, *on).clicked() {
|
||
*on = !*on;
|
||
}
|
||
}
|
||
if ui.add_enabled_ui(b || h || st, |ui| button(ui, ButtonKind::Filled, Some(icons::INPUT), "Import")).inner.clicked() {
|
||
f.send(Command::Import { source: i, bookmarks: b, history: h, settings: st });
|
||
}
|
||
});
|
||
ui.data_mut(|d| d.insert_temp(id, (b, h, st)));
|
||
}
|
||
let status = f.shared.import_status.borrow().clone();
|
||
if !status.is_empty() {
|
||
row(ui, "Last import", &status, |_| ());
|
||
}
|
||
});
|
||
section(ui, "From files");
|
||
card(ui, |ui| {
|
||
if row(ui, "Bookmarks from a file", "An HTML bookmarks file exported from any browser", |ui| button(ui, ButtonKind::Outlined, Some(icons::FOLDER_OPEN), "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| button(ui, ButtonKind::Outlined, Some(icons::FOLDER_OPEN), "Import CSV").clicked()) {
|
||
f.send(Command::ImportPasswords);
|
||
}
|
||
});
|
||
}
|
||
|
||
/// The new tab page's own settings live in its Customize panel; shortcuts are edited here.
|
||
fn newtab(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
section(ui, "Page");
|
||
card(ui, |ui| {
|
||
if icon_link_row(ui, icons::DASHBOARD_CUSTOMIZE, "Customize the new tab page", "Background, image, what shows and in which order, clock, your name, weather place and units") {
|
||
f.ui.pages.ntp_customize = true;
|
||
f.send(Command::ShowPage(Page::NewTab));
|
||
}
|
||
});
|
||
section(ui, "Shortcuts");
|
||
card(ui, |ui| {
|
||
let mut remove = None;
|
||
for (i, (title, url)) in s.ntp.shortcuts.iter_mut().enumerate() {
|
||
let host = util::host_of_str(url);
|
||
row(ui, &host, "", |ui| {
|
||
if icon_button(ui, icons::DELETE, "Remove this shortcut").clicked() {
|
||
remove = Some(i);
|
||
}
|
||
text_field(ui, url, "https://…", 260.0);
|
||
text_field(ui, title, "Name", 140.0);
|
||
});
|
||
}
|
||
if let Some(i) = remove {
|
||
s.ntp.shortcuts.remove(i);
|
||
}
|
||
if s.ntp.shortcuts.is_empty() {
|
||
row(ui, "No shortcuts yet", "Add one here or with the dashed circle on the new tab page", |_| ());
|
||
}
|
||
wide_row(ui, "Add a shortcut", "", |ui| {
|
||
text_field(ui, &mut f.ui.pages.new_shortcut.0, "Name", 140.0);
|
||
text_field(ui, &mut f.ui.pages.new_shortcut.1, "https://…", 300.0);
|
||
let ok = !f.ui.pages.new_shortcut.1.trim().is_empty();
|
||
if ui.add_enabled_ui(ok, |ui| button(ui, ButtonKind::Tonal, Some(icons::ADD), "Add")).inner.clicked() {
|
||
let (title, url) = std::mem::take(&mut f.ui.pages.new_shortcut);
|
||
let url = if url.contains("://") { url.trim().to_owned() } 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 permissions(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||
intro(ui, "What sites may do when they haven't been asked. Each site's own answers are in Site settings.");
|
||
section(ui, "Defaults");
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
});
|
||
section(ui, "Sites");
|
||
card(ui, |ui| {
|
||
if icon_link_row(ui, icons::PUBLIC, "Every site's permissions", "What each site you visited was allowed or refused") {
|
||
f.send(Command::ShowPage(Page::SiteSettings(String::new())));
|
||
}
|
||
});
|
||
}
|