Fixes R1-01 (icon glyphs) and R1-02 (clock contrast). Co-Authored-By: Claude Opus 5.5 <[email protected]>
353 lines
16 KiB
Rust
353 lines
16 KiB
Rust
//! Smaller pages: site settings, delete browsing data, about, first-run setup, task manager,
|
||
//! page source, and errors.
|
||
|
||
use egui::{RichText, Ui};
|
||
|
||
use super::super::widgets::{card, page_column, row, segmented, switch, switch_row};
|
||
use super::super::Frame;
|
||
use crate::actions::Command;
|
||
use crate::store::permissions::{Decision, Kind};
|
||
use crate::store::settings::{ColourSource, DohProvider, ThemeMode};
|
||
use crate::tabs::Page;
|
||
use crate::util;
|
||
use crate::ui::icons;
|
||
|
||
pub fn site_settings(ui: &mut Ui, f: &mut Frame, host: &str) {
|
||
page_column(ui, "site-settings", 860.0, |ui| {
|
||
if host.is_empty() {
|
||
ui.heading("Site settings");
|
||
ui.label(RichText::new("Sites you answered a permission request for. Defaults are in Settings → Privacy → Site settings.").weak());
|
||
ui.add(egui::TextEdit::singleline(&mut f.ui.pages.site_search).hint_text("Search sites").desired_width(f32::INFINITY));
|
||
let all = f.shared.permissions.borrow().all();
|
||
let mut hosts: Vec<String> = all.iter().map(|(h, ..)| h.clone()).collect();
|
||
hosts.dedup();
|
||
let q = f.ui.pages.site_search.to_lowercase();
|
||
card(ui, |ui| {
|
||
if hosts.is_empty() {
|
||
ui.label(RichText::new("No sites yet.").weak());
|
||
}
|
||
for h in hosts.iter().filter(|h| q.is_empty() || h.contains(&q)) {
|
||
let summary: Vec<String> = all.iter().filter(|(x, ..)| x == h).map(|(_, k, d)| format!("{} {}", k.label(), if *d == Decision::Allow { icons::CHECK } else { icons::CLOSE })).collect();
|
||
if row(ui, h, &summary.join(" · "), |ui| ui.button(icons::CHEVRON_RIGHT).clicked()) {
|
||
f.send(Command::ShowPage(Page::SiteSettings(h.clone())));
|
||
}
|
||
}
|
||
});
|
||
return;
|
||
}
|
||
if ui.button("‹ All sites").clicked() {
|
||
f.send(Command::ShowPage(Page::SiteSettings(String::new())));
|
||
}
|
||
ui.heading(host);
|
||
let mut s = f.shared.settings.borrow().clone();
|
||
let before = s.clone();
|
||
card(ui, |ui| {
|
||
for kind in Kind::ALL {
|
||
let current = f.shared.permissions.borrow().site_decision(host, *kind);
|
||
let mut value: u8 = match current {
|
||
None => 0,
|
||
Some(Decision::Allow) => 1,
|
||
Some(Decision::Block) => 2,
|
||
};
|
||
let default = s.privacy.permission_defaults.get(kind.key()).copied().unwrap_or_else(|| kind.builtin_default());
|
||
let opts: &[(u8, &str)] = &[(0, "Default"), (1, "Allow"), (2, "Block")];
|
||
let changed = row(ui, kind.label(), &format!("Default: {}", default.label()), |ui| segmented(ui, &mut value, opts));
|
||
if changed {
|
||
let decision = match value {
|
||
1 => Some(Decision::Allow),
|
||
2 => Some(Decision::Block),
|
||
_ => None,
|
||
};
|
||
f.shared.permissions.borrow_mut().set(host, *kind, decision);
|
||
}
|
||
}
|
||
});
|
||
card(ui, |ui| {
|
||
let mut ads = !s.adblock_paused_on(host);
|
||
if switch_row(ui, "Block ads on this site", "", &mut ads) {
|
||
if ads {
|
||
s.adblock.allow.retain(|h| !util::host_matches(host, h));
|
||
} else {
|
||
s.adblock.allow.push(host.to_owned());
|
||
}
|
||
}
|
||
let mut active = s.keeps_active(host);
|
||
if switch_row(ui, "Always keep active", "Its tabs are never frozen or unloaded", &mut active) {
|
||
if active {
|
||
s.perf.keep_active.push(host.to_owned());
|
||
} else {
|
||
s.perf.keep_active.retain(|h| !util::host_matches(host, h));
|
||
}
|
||
}
|
||
let mut muted = s.site_muted(host);
|
||
if switch_row(ui, "Mute", "", &mut muted) {
|
||
f.send(Command::ToggleMuteSite(host.to_owned()));
|
||
}
|
||
let mut http = s.privacy.https_exceptions.iter().any(|h| h == host);
|
||
if switch_row(ui, "Allow without HTTPS", "Only matters when HTTPS-only mode is on", &mut http) {
|
||
if http {
|
||
s.privacy.https_exceptions.push(host.to_owned());
|
||
} else {
|
||
s.privacy.https_exceptions.retain(|h| h != host);
|
||
}
|
||
}
|
||
if let Some(zoom) = s.web.zoom_sites.get(host).copied() {
|
||
if row(ui, "Zoom", &format!("{:.0}%", zoom * 100.0), |ui| ui.button("Reset").clicked()) {
|
||
s.web.zoom_sites.remove(host);
|
||
}
|
||
}
|
||
if row(ui, "Cookies and site data", "Stored by this site in Nacre", |ui| ui.button("Delete").clicked()) {
|
||
f.send(Command::ClearSiteData(host.to_owned()));
|
||
}
|
||
});
|
||
if s != before {
|
||
*f.shared.settings.borrow_mut() = s;
|
||
}
|
||
});
|
||
}
|
||
|
||
const RANGES: &[(&str, u64)] = &[("Last hour", 3600), ("Last 24 hours", 86_400), ("Last 7 days", 7 * 86_400), ("Last 4 weeks", 28 * 86_400), ("All time", 0)];
|
||
const WHAT: &[(&str, &str, &str)] = &[
|
||
("history", "Browsing history", "Pages you visited and recently closed tabs"),
|
||
("cookies", "Cookies and site data", "Signs you out of most sites"),
|
||
("cache", "Cached files", "Pages load a little slower the first time"),
|
||
("downloads", "Download list", "Files stay on disk"),
|
||
("permissions", "Site permissions", ""),
|
||
("passwords", "Passwords", ""),
|
||
("autofill", "Addresses and cards", ""),
|
||
];
|
||
|
||
pub fn clear_data(ui: &mut Ui, f: &mut Frame) {
|
||
if f.ui.pages.clear_what.is_empty() {
|
||
f.ui.pages.clear_what = vec!["history".into(), "cookies".into(), "cache".into()];
|
||
}
|
||
page_column(ui, "clear-data", 640.0, |ui| {
|
||
ui.heading("Delete browsing data");
|
||
card(ui, |ui| {
|
||
let mut range = f.ui.pages.clear_range;
|
||
let opts: Vec<(usize, &str)> = RANGES.iter().enumerate().map(|(i, (l, _))| (i, *l)).collect();
|
||
row(ui, "Time range", "", |ui| segmented(ui, &mut range, &opts));
|
||
f.ui.pages.clear_range = range;
|
||
for (key, label, desc) in WHAT {
|
||
let mut on = f.ui.pages.clear_what.iter().any(|k| k == key);
|
||
if switch_row(ui, label, desc, &mut on) {
|
||
if on {
|
||
f.ui.pages.clear_what.push((*key).to_owned());
|
||
} else {
|
||
f.ui.pages.clear_what.retain(|k| k != key);
|
||
}
|
||
}
|
||
}
|
||
});
|
||
ui.label(RichText::new("Cookies, cache, permissions and passwords are deleted whatever the time range; Servo keeps no dates for them.").weak().small());
|
||
if ui.button(RichText::new("Delete data").strong()).clicked() {
|
||
let seconds = RANGES[f.ui.pages.clear_range.min(RANGES.len() - 1)].1;
|
||
let since = if seconds == 0 { 0 } else { util::now().saturating_sub(seconds) };
|
||
f.send(Command::ClearData { since, what: f.ui.pages.clear_what.clone() });
|
||
}
|
||
});
|
||
}
|
||
|
||
pub fn about(ui: &mut Ui, f: &mut Frame) {
|
||
page_column(ui, "about", 640.0, |ui| {
|
||
ui.vertical_centered(|ui| {
|
||
ui.add_space(20.0);
|
||
ui.label(RichText::new("Nacre").size(40.0).strong());
|
||
ui.label(format!("Version {}", crate::updates::current_version()));
|
||
ui.label(RichText::new("Servo 0.7.0 engine · written in Rust").weak());
|
||
});
|
||
ui.add_space(16.0);
|
||
card(ui, |ui| {
|
||
let status = f.shared.update_status.borrow().clone();
|
||
if row(ui, "Updates", if status.is_empty() { "Not checked yet" } else { &status }, |ui| ui.button("Check now").clicked()) {
|
||
f.send(Command::CheckUpdates);
|
||
}
|
||
if f.shared.update.borrow().is_some() && row(ui, "A new version is ready", "", |ui| ui.button("Get it").clicked()) {
|
||
f.send(Command::OpenUpdate);
|
||
}
|
||
let repo = f.shared.settings.borrow().update.repo.clone();
|
||
if !repo.is_empty() && row(ui, "Source code and releases", &repo, |ui| ui.button("Open").clicked()) {
|
||
f.send(Command::Open { url: repo, how: crate::actions::Disposition::NewForegroundTab, from: None });
|
||
}
|
||
row(ui, "Licence", "Mozilla Public License 2.0 (Servo and Nacre)", |_| ());
|
||
row(ui, "Engine limits", "No DRM video (Widevine), no Chrome extensions (use scripts and styles), no printing (save as PDF instead)", |_| ());
|
||
});
|
||
});
|
||
}
|
||
|
||
/// First run: a few choices, then the new tab page.
|
||
pub fn welcome(ui: &mut Ui, f: &mut Frame) {
|
||
let mut s = f.shared.settings.borrow().clone();
|
||
let before = s.clone();
|
||
page_column(ui, "welcome", 640.0, |ui| {
|
||
let step = f.ui.pages.welcome_step;
|
||
ui.add_space(20.0);
|
||
match step {
|
||
0 => {
|
||
ui.label(RichText::new("Welcome to Nacre").size(32.0).strong());
|
||
ui.label("A few choices and you're ready. You can change all of them later in Settings.");
|
||
let sources = f.shared.import_sources.borrow().clone();
|
||
if !sources.is_empty() {
|
||
ui.add_space(12.0);
|
||
ui.label(RichText::new("Bring your bookmarks and history").strong());
|
||
card(ui, |ui| {
|
||
for (i, src) in sources.iter().enumerate() {
|
||
if row(ui, &src.name(), "Bookmarks, history, home page and search engine", |ui| ui.button("Import").clicked()) {
|
||
f.send(Command::Import { source: i, bookmarks: true, history: true, settings: true });
|
||
}
|
||
}
|
||
});
|
||
let status = f.shared.import_status.borrow().clone();
|
||
if !status.is_empty() {
|
||
ui.label(RichText::new(status).weak());
|
||
}
|
||
}
|
||
},
|
||
1 => {
|
||
ui.label(RichText::new("Search").size(26.0).strong());
|
||
card(ui, |ui| {
|
||
for (key, name, _, _) in s.search_engines() {
|
||
ui.radio_value(&mut s.startup.search_engine, key, name);
|
||
}
|
||
});
|
||
},
|
||
2 => {
|
||
ui.label(RichText::new("Look").size(26.0).strong());
|
||
card(ui, |ui| {
|
||
row(ui, "Mode", "", |ui| segmented(ui, &mut s.theme.mode, ThemeMode::ALL));
|
||
row(ui, "Colours", "", |ui| segmented(ui, &mut s.theme.source, ColourSource::ALL));
|
||
});
|
||
},
|
||
3 => {
|
||
ui.label(RichText::new("Privacy").size(26.0).strong());
|
||
card(ui, |ui| {
|
||
switch_row(ui, "Block ads and trackers", "", &mut s.adblock.enabled);
|
||
switch_row(ui, "HTTPS-only mode", "", &mut s.privacy.https_only);
|
||
switch_row(ui, "Privacy mode", "Hides your browser's fingerprint", &mut s.privacy.mode);
|
||
row(ui, "Secure DNS", "", |ui| {
|
||
egui::ComboBox::from_id_salt("welcome-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);
|
||
}
|
||
});
|
||
});
|
||
});
|
||
},
|
||
_ => {
|
||
ui.label(RichText::new("You're ready").size(32.0).strong());
|
||
ui.label("Nacre is set up. Have a look at the new tab page and the menu ☰ for everything else.");
|
||
},
|
||
}
|
||
ui.add_space(16.0);
|
||
ui.horizontal(|ui| {
|
||
if step > 0 && ui.button("Back").clicked() {
|
||
f.ui.pages.welcome_step -= 1;
|
||
}
|
||
if step < 4 {
|
||
if ui.button(RichText::new("Next").strong()).clicked() {
|
||
f.ui.pages.welcome_step += 1;
|
||
}
|
||
if ui.button("Skip setup").clicked() {
|
||
s.startup.welcome_done = true;
|
||
s.startup.import_offered = true;
|
||
f.send(Command::Navigate("nacre://newtab".into()));
|
||
}
|
||
} else if ui.button(RichText::new("Start browsing").strong()).clicked() {
|
||
s.startup.welcome_done = true;
|
||
s.startup.import_offered = true;
|
||
f.ui.pages.welcome_step = 0;
|
||
f.send(Command::Navigate("nacre://newtab".into()));
|
||
}
|
||
});
|
||
});
|
||
if s != before {
|
||
*f.shared.settings.borrow_mut() = s;
|
||
}
|
||
}
|
||
|
||
pub fn task_manager(ui: &mut Ui, f: &mut Frame) {
|
||
page_column(ui, "task-manager", 860.0, |ui| {
|
||
ui.heading("Task manager");
|
||
let (total, available) = crate::perf::system_memory();
|
||
ui.label(format!("Nacre uses {} with {} threads · {} of {} memory free", util::format_bytes(crate::perf::own_memory()), crate::perf::own_threads(), util::format_bytes(available), util::format_bytes(total)));
|
||
ui.label(RichText::new("Servo runs every page in Nacre's own process, so memory isn't split per tab.").weak().small());
|
||
ui.add_space(8.0);
|
||
let rows: Vec<(u64, String, &'static str, bool)> = f
|
||
.tabs
|
||
.iter()
|
||
.map(|t| {
|
||
let state = if t.page.is_some() { "Nacre page" } else if t.web.is_none() { "Unloaded" } else if t.frozen { "Frozen" } else if t.audible() { "Playing" } else if t.loading() { "Loading" } else { "Running" };
|
||
(t.id, t.display_title(), state, t.web.is_some())
|
||
})
|
||
.collect();
|
||
egui::Grid::new("tasks").num_columns(3).striped(true).show(ui, |ui| {
|
||
for (id, title, state, has_web) in rows {
|
||
ui.label(util::ellipsize(&title, 60));
|
||
ui.label(state);
|
||
ui.horizontal(|ui| {
|
||
if has_web && ui.small_button("Reload").clicked() {
|
||
f.send(Command::ReloadTab(id));
|
||
}
|
||
if ui.small_button("Close").clicked() {
|
||
f.send(Command::CloseTab(id));
|
||
}
|
||
});
|
||
ui.end_row();
|
||
}
|
||
});
|
||
ui.add_space(8.0);
|
||
if ui.button("Unload background tabs").clicked() {
|
||
f.send(Command::FreeMemory);
|
||
}
|
||
ui.ctx().request_repaint_after(std::time::Duration::from_secs(2));
|
||
});
|
||
}
|
||
|
||
pub fn source(ui: &mut Ui, f: &mut Frame, url: &str) {
|
||
let source = f.shared.sources.borrow().get(url).cloned();
|
||
match source {
|
||
None => {
|
||
f.send(Command::FetchSource(url.to_owned()));
|
||
ui.spinner();
|
||
},
|
||
Some(None) => {
|
||
ui.spinner();
|
||
},
|
||
Some(Some(Err(error))) => {
|
||
ui.label(format!("The source couldn't be loaded: {error}"));
|
||
if ui.button("Try again").clicked() {
|
||
f.shared.sources.borrow_mut().remove(url);
|
||
}
|
||
},
|
||
Some(Some(Ok(text))) => {
|
||
ui.horizontal(|ui| {
|
||
ui.label(RichText::new(format!("Source of {}", util::ellipsize(url, 100))).strong());
|
||
if ui.small_button("Copy").clicked() {
|
||
ui.ctx().copy_text(text.clone());
|
||
}
|
||
if ui.small_button("Reload").clicked() {
|
||
f.shared.sources.borrow_mut().remove(url);
|
||
}
|
||
});
|
||
egui::ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
|
||
// Very long sources are shown in part to keep the window responsive.
|
||
let mut shown: &str = if text.len() > 2_000_000 { &text[..text.char_indices().nth(2_000_000).map(|(i, _)| i).unwrap_or(text.len())] } else { &text };
|
||
// A &str buffer is read-only: selectable and copyable, not editable.
|
||
ui.add(egui::TextEdit::multiline(&mut shown).code_editor().desired_width(f32::INFINITY));
|
||
});
|
||
},
|
||
}
|
||
}
|
||
|
||
pub fn error(ui: &mut Ui, f: &mut Frame, url: &str, why: &str) {
|
||
ui.vertical_centered(|ui| {
|
||
ui.add_space(80.0);
|
||
ui.heading(crate::resources::ERROR_TITLE);
|
||
ui.label(url);
|
||
ui.label(RichText::new(why).weak());
|
||
if ui.button("Try again").clicked() {
|
||
f.send(Command::Navigate(url.to_owned()));
|
||
}
|
||
});
|
||
let _ = switch;
|
||
}
|