S001: commit self-test WIP and UI brief

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-11 17:22:27 -06:00
commit 49825b626e
13 changed files with 405 additions and 11 deletions

11
Cargo.lock generated
View file

@ -4892,6 +4892,7 @@ dependencies = [
"qrcode",
"raw-window-handle",
"rfd",
"rusqlite",
"rustls",
"serde",
"serde_json",
@ -7124,7 +7125,6 @@ dependencies = [
"servo-config",
"servo-constellation",
"servo-constellation-traits",
"servo-default-resources",
"servo-devtools",
"servo-devtools-traits",
"servo-embedder-traits",
@ -7414,15 +7414,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "servo-default-resources"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0a9b9f4014b5632cbe1e0289de744ee63c33dce9dd142c23cd964904aa8214f"
dependencies = [
"servo-embedder-traits",
]
[[package]]
name = "servo-deny-public-fields"
version = "0.7.0"

74
docs/UI-BRIEF.md Normal file
View file

@ -0,0 +1,74 @@
# UI brief for the redesign session
Written 2026-11-11 from the user's instructions and their screen recording
(`~/Videos/Recordings/recording_20261111_06-11-33.mp4`, 72 s, the original Python Nacre's new tab page). Frames from
it are in `docs/ui-reference/`. The current egui UI is a plain stand-in; it exists so every feature can be used and
tested. **The redesign starts only after the framework works** (the user's rule), in a new session.
Use the `app-taste` skill for all of it.
## What the user asked for
- Redo the whole UI/UX "just like Google Material You, give it all you want":
- Tonal-spot colour schemes generated from a seed colour, with the seed taken from the current website
(theme-color / favicon), from the system accent, from a palette, or from a custom colour. User themes.
- Nice animations everywhere (spring motion; the Motion setting scales or disables it).
- Material 3 Expressive details: wiggly (wavy) lines and progress bars, scalloped "cookie" shapes, pill buttons,
segmented buttons with a check mark on the selected segment, large rounded cards.
- The new tab page must look and behave like the one in the video: "animative, reactive and everything".
- Then the settings pages and everything else, in the same system.
- Build the new UI around the features that exist; don't drop features to fit a design.
## The new tab page in the video (the target)
Layout, top to bottom, centred in the page card:
1. Greeting: "Good morning, Jacob Ward" (medium weight, on-surface colour).
2. Clock: very large thin digits in the accent tint, seconds shown, small "AM" baseline-aligned to the right;
the date ("Wednesday, November 11") under it.
3. Shortcuts row: round icons with labels and a dashed "Add shortcut" circle.
4. A row of two cards:
- Now playing: artwork inside a scalloped cookie shape with a dotted ring around it (the ring is the visualizer;
the cookie spins while playing), title "Nothing playing / Play something in a tab", a seek line with times,
shuffle / previous / play / next / repeat, and a "No media" chip that names the source tab.
- Weather: moon/sun glyph, big temperature, "Clear · feels like 35°", high/low, rain chance, humidity, wind,
and the place name.
5. Search field: pill shaped, search glyph, "Search DuckDuckGo or type a URL", a round accent button at the right.
6. A row of three cards: Notes ("Jot something down…"), Reading list, Top sites.
Background, behind everything, animated and reacting to the cursor:
- None, Shapes (outlined and filled rounded shapes drifting), Blobs (large soft circles), Constellation (dots joined
by thin lines), Waves (several sine lines that bend near the cursor), Dot grid (a grid of dots that swells in a
circle around the cursor).
- Amount: Few / Some / Lots. Speed: Slow / Normal / Fast. "React to the cursor" switch.
- Image or GIF: Upload / Change / Remove, with Dim and Blur sliders; the animated layer draws over the image.
Customize panel: slides in from the right as a rounded panel over the page (the page stays visible and live while
settings change), with sections BACKGROUND, IMAGE OR GIF, ELEMENTS (each element has up/down arrows and a switch:
Greeting, Clock, Shortcuts, Now playing, Weather, Search, Notes, Reading list, Top sites) and DETAILS (24-hour clock,
Show seconds, Your name, Weather place with a city suggestion list, Units Auto / °C / °F).
Chrome seen in the video (for the toolbar redesign): one rounded window card, a pill tab with a close button, round
"+" button, toolbar icons (back, forward, reload, home, incognito mask), a pill address field with a star, then
password key, history, downloads, QR/apps grid, developer tools, shield, and a three-dot menu. The bookmarks bar shows
a hint when empty. The page sits in a floating rounded card with a margin.
## What already exists to build on
- `src/theme.rs`: `Palette` (accent, surfaces, text, outline...), seed selection (website / system / palette /
custom), dark/light, roundness, animation time. Replace its simple HSL maths with real Material tonal palettes
(HCT) when redesigning; keep the `Palette` roles so the rest of the UI keeps working.
- `src/ui/pages/newtab.rs`: every element and every background from the video already works in plain form
(clock, greeting, search, shortcuts, now playing, weather via Open-Meteo, notes, reading list, recent/top sites;
shapes, blobs, particles, waves, dots; image with dim and blur). Settings live in `Settings::ntp`.
Missing against the video: the Constellation background (the setting calls it "particles": add the lines), the
Customize panel over the page (today it's a settings sub-page), top sites as its own card, shuffle/repeat buttons.
- `src/ui/widgets.rs`: switch, segmented control, rows, cards. These are the pieces to restyle first.
- `src/media.rs`: visualizer levels (cava or simulated) ready for the dotted ring.
- Website colours: `META_JS` in `src/inject.rs` reports `theme-color` and the page background; `Tab::theme_color`
feeds `theme::seed`.
## Open questions for the user at the start of the UI session
- Keep egui for the redesigned UI, or draw the chrome with something else? (egui can do all of the above with custom
painting; text shaping and blur are its weak spots.)
- Fonts: the video uses a geometric sans (looks like Google Sans / Outfit) with thin clock digits.

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 455 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

View file

@ -188,6 +188,7 @@ pub struct App {
pub instance: Option<crate::instance::Server>,
/// Windows that commands asked for; opened when the event loop is at hand.
pub window_requests: Vec<WindowRequest>,
pub selftest: Option<crate::selftest::SelfTest>,
/// Commands waiting for a window to exist.
pub pending_commands: Vec<Command>,
/// Picture-in-picture windows to close after their tab went away.
@ -310,6 +311,7 @@ impl App {
crashed_last_time,
instance: None,
window_requests: Vec::new(),
selftest: crate::selftest::SelfTest::from_env(),
pending_commands: Vec::new(),
window_closes: Vec::new(),
}
@ -1079,6 +1081,9 @@ impl App {
self.update_vpn_route();
self.poll_gamepads();
self.update_media_now();
if self.selftest.is_some() {
self.selftest_step();
}
if now.duration_since(self.last_tick) >= Duration::from_millis(900) {
self.last_tick = now;
let before = self.shared.toasts.borrow().len();

View file

@ -15,6 +15,7 @@ mod paths;
mod pdf;
mod perf;
mod resources;
mod selftest;
mod spell;
mod store;
mod tabs;

308
src/selftest.rs Normal file
View file

@ -0,0 +1,308 @@
//! Scripted runs for testing: `NACRE_SCRIPT=<file>` makes Nacre run the commands in the file, one
//! per line, and save screenshots and status files next to it. Lines starting with `#` are notes.
//!
//! wait <seconds> let the browser run
//! waitload [seconds] wait until the current tab finished loading (default limit 30 s)
//! open <url> load in the current tab newtab <url> open in a new tab
//! page <nacre://...> show an internal page
//! shot <name> save the window as <name>.png
//! status <name> save tabs, downloads, VPN, ad blocker and so on as <name>.json
//! set <json pointer> <json> change a setting, e.g. `set /privacy/https_only true`
//! flyout <name> main, downloads, shield, vpn, media, siteinfo, profiles, apps, qr, none
//! do <action> a shortcut action by its settings key, e.g. `do new_tab`
//! cmd <name> [arg] back, forward, reload, bookmark, install_app, pip, exitpip, free_memory,
//! update_lists, check_updates, close_tab, select <n>, zoom <step>,
//! find <text>, download <url>, navigate <typed text>, mute, pin
//! js <script> run JavaScript in the current tab; the result goes to the log
//! click <x> <y> click in the page at CSS-ish pixel x,y (from the page's top left)
//! log <text> write a line to the log
//! quit
use std::path::PathBuf;
use std::time::{Duration, Instant};
use winit::window::WindowId;
use crate::actions::{Command, Disposition, DownloadOp};
use crate::app::App;
use crate::tabs::Page;
use crate::ui::Flyout;
pub struct SelfTest {
lines: Vec<String>,
next: usize,
wait_until: Option<Instant>,
wait_load_until: Option<Instant>,
dir: PathBuf,
/// A screenshot was asked for and hasn't been written yet.
pending_shot: bool,
}
impl SelfTest {
pub fn from_env() -> Option<SelfTest> {
let path = PathBuf::from(std::env::var_os("NACRE_SCRIPT")?);
let text = std::fs::read_to_string(&path).ok()?;
let dir = path.parent().map(|p| p.to_owned()).unwrap_or_else(|| PathBuf::from("."));
let lines = text.lines().map(|l| l.trim().to_owned()).filter(|l| !l.is_empty() && !l.starts_with('#')).collect();
Some(SelfTest { lines, next: 0, wait_until: None, wait_load_until: None, dir, pending_shot: false })
}
fn log(&self, text: &str) {
use std::io::Write as _;
if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(self.dir.join("selftest.log")) {
let _ = writeln!(f, "{text}");
}
}
}
impl App {
/// Run script lines until one has to wait.
pub fn selftest_step(&mut self) {
let Some(window) = self.current_window().or_else(|| self.windows.keys().next().copied()) else { return };
loop {
let Some(test) = self.selftest.as_mut() else { return };
if let Some(until) = test.wait_until {
if Instant::now() < until {
return;
}
test.wait_until = None;
}
if test.pending_shot {
// Written by the window after its next frame.
if self.windows.get(&window).is_some_and(|w| w.shot_request.is_some()) {
self.redraw(window);
return;
}
if let Some(test) = self.selftest.as_mut() {
test.pending_shot = false;
}
continue;
}
if let Some(until) = test.wait_load_until {
let loading = self.windows.get(&window).and_then(|w| w.tab()).is_some_and(|t| t.loading() || t.pending_url.is_some());
if loading && Instant::now() < until {
return;
}
if let Some(test) = self.selftest.as_mut() {
if loading {
test.log("waitload: gave up waiting");
}
test.wait_load_until = None;
}
continue;
}
if test.next >= test.lines.len() {
return;
}
let line = test.lines[test.next].clone();
test.next += 1;
test.log(&format!("> {line}"));
self.selftest_run(window, &line);
if self.exiting {
return;
}
}
}
fn selftest_run(&mut self, window: WindowId, line: &str) {
let (verb, rest) = line.split_once(char::is_whitespace).map(|(v, r)| (v, r.trim())).unwrap_or((line, ""));
let dir = self.selftest.as_ref().map(|t| t.dir.clone()).unwrap_or_default();
match verb {
"wait" => {
let secs: f64 = rest.parse().unwrap_or(1.0);
if let Some(t) = self.selftest.as_mut() {
t.wait_until = Some(Instant::now() + Duration::from_secs_f64(secs));
}
},
"waitload" => {
let secs: f64 = rest.parse().unwrap_or(30.0);
if let Some(t) = self.selftest.as_mut() {
// Give the load a moment to start before checking.
t.wait_until = Some(Instant::now() + Duration::from_millis(700));
t.wait_load_until = Some(Instant::now() + Duration::from_secs_f64(secs));
}
},
"open" => self.navigate(window, rest.to_owned()),
"newtab" => self.open(window, rest.to_owned(), Disposition::NewForegroundTab, None),
"page" => {
if let Some(page) = Page::from_url(rest) {
self.show_page(window, page);
}
},
"shot" => {
if let Some(win) = self.windows.get_mut(&window) {
win.shot_request = Some(dir.join(format!("{rest}.png")));
}
if let Some(t) = self.selftest.as_mut() {
t.pending_shot = true;
}
self.redraw(window);
},
"status" => {
let text = serde_json::to_string_pretty(&self.selftest_status(window)).unwrap_or_default();
let _ = std::fs::write(dir.join(format!("{rest}.json")), text);
},
"set" => {
let (pointer, value) = rest.split_once(char::is_whitespace).unwrap_or((rest, "null"));
let result = (|| -> Result<(), String> {
let mut json = serde_json::to_value(&*self.shared.settings.borrow()).map_err(|e| e.to_string())?;
let slot = json.pointer_mut(pointer).ok_or("no such setting")?;
*slot = serde_json::from_str(value.trim()).map_err(|e| e.to_string())?;
let settings = serde_json::from_value(json).map_err(|e| e.to_string())?;
*self.shared.settings.borrow_mut() = settings;
Ok(())
})();
if let (Err(error), Some(t)) = (result, self.selftest.as_ref()) {
t.log(&format!("set failed: {error}"));
}
self.apply_settings_if_changed();
},
"flyout" => {
let url = self.windows.get(&window).and_then(|w| w.tab()).map(|t| t.url.clone()).unwrap_or_default();
let flyout = match rest {
"main" => Some(Flyout::Main),
"downloads" => Some(Flyout::Downloads),
"shield" => Some(Flyout::Shield),
"vpn" => Some(Flyout::Vpn),
"media" => Some(Flyout::Media),
"siteinfo" => Some(Flyout::SiteInfo),
"profiles" => Some(Flyout::Profiles),
"apps" => Some(Flyout::Apps),
"qr" => Some(Flyout::Qr(url)),
_ => None,
};
if let Some(win) = self.windows.get_mut(&window) {
win.ui.flyout = flyout;
win.ui.flyout_anchor = None;
}
self.redraw(window);
},
"do" => {
let action = crate::keys::Action::ALL.iter().find(|(_, key, ..)| *key == rest).map(|(a, ..)| *a);
match action {
Some(action) => self.run_in(window, Command::Action(action)),
None => self.selftest_log(&format!("unknown action {rest}")),
}
},
"cmd" => {
let (name, arg) = rest.split_once(char::is_whitespace).map(|(n, a)| (n, a.trim())).unwrap_or((rest, ""));
let tab = self.windows.get(&window).and_then(|w| w.tab()).map(|t| t.id).unwrap_or(0);
let page = self.windows.get(&window).and_then(|w| w.tab()).map(|t| t.url.clone()).unwrap_or_default();
let command = match name {
"back" => Command::Back,
"forward" => Command::Forward,
"reload" => Command::Reload { hard: false },
"bookmark" => Command::ToggleBookmark,
"install_app" => Command::InstallApp,
"pip" => Command::EnterPip,
"exitpip" => Command::ClosePip(tab),
"free_memory" => Command::FreeMemory,
"update_lists" => Command::UpdateFilterLists,
"check_updates" => Command::CheckUpdates,
"close_tab" => Command::CloseTab(tab),
"select" => Command::SelectTab(arg.parse().unwrap_or(0)),
"zoom" => Command::Zoom(arg.parse().unwrap_or(1)),
"find" => Command::Find { text: arg.to_owned(), forward: true, case: false },
"download" => Command::DownloadUrl { url: arg.to_owned(), page, name: String::new() },
"pause_download" => Command::Download(DownloadOp::Pause(arg.parse().unwrap_or(1))),
"resume_download" => Command::Download(DownloadOp::Resume(arg.parse().unwrap_or(1))),
"navigate" => Command::Navigate(arg.to_owned()),
"mute" => Command::MuteTab(tab),
"pin" => Command::PinTab(tab),
"reopen" => Command::ReopenClosed(None),
"media" => Command::Media { tab, action: arg.to_owned(), value: 0.0 },
_ => {
self.selftest_log(&format!("unknown cmd {name}"));
return;
},
};
self.run_in(window, command);
},
"js" => {
let Some(web) = self.windows.get(&window).and_then(|w| w.active_webview()).cloned() else {
self.selftest_log("js: no page");
return;
};
let log_path = dir.join("selftest.log");
web.evaluate_javascript(rest.to_owned(), move |result| {
use std::io::Write as _;
if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(&log_path) {
let _ = writeln!(f, "js -> {result:?}");
}
});
},
"click" => {
let mut parts = rest.split_whitespace().filter_map(|p| p.parse::<f64>().ok());
let (x, y) = (parts.next().unwrap_or(0.0), parts.next().unwrap_or(0.0));
if let Some(win) = self.windows.get_mut(&window)
&& let Some(rect) = win.page_rect
{
let scale = win.egui.egui_ctx.pixels_per_point() as f64;
let pos = winit::dpi::PhysicalPosition::new((rect.min.x as f64 + x) * scale, (rect.min.y as f64 + y) * scale);
win.pointer = Some(pos);
win.send_mouse_move(pos);
win.send_mouse_button(winit::event::ElementState::Pressed, winit::event::MouseButton::Left);
win.send_mouse_button(winit::event::ElementState::Released, winit::event::MouseButton::Left);
}
},
"log" => self.selftest_log(rest),
"quit" => self.quit(),
_ => self.selftest_log(&format!("unknown line: {line}")),
}
}
fn selftest_log(&self, text: &str) {
if let Some(t) = self.selftest.as_ref() {
t.log(text);
}
}
fn selftest_status(&self, window: WindowId) -> serde_json::Value {
let tabs: Vec<serde_json::Value> = self
.windows
.get(&window)
.map(|w| {
w.tabs
.iter()
.enumerate()
.map(|(i, t)| {
serde_json::json!({
"active": i == w.active, "url": t.shown_url(), "title": t.display_title(), "loading": t.loading(),
"load_status": format!("{:?}", t.load_status), "has_web": t.web.is_some(), "blocked": t.blocked,
"hidden_elements": t.hidden_elements, "pinned": t.pinned, "muted": t.muted, "zoom": t.zoom,
"favicon": t.favicon.is_some(), "crashed": t.crashed, "can_back": t.can_go_back(), "can_forward": t.can_go_forward(),
"history_len": t.back_forward.len(), "find": [t.find.index, t.find.count], "prompts": t.prompts.len(),
"dialog": t.dialog.is_some(), "media": t.media.as_ref().map(|(m, _)| serde_json::json!({"title": m.title, "paused": m.paused, "duration": m.duration, "position": m.position})),
"theme_color": t.theme_color.map(crate::theme::to_hex), "console_lines": t.console.len(), "pip": t.pip_size.is_some(),
})
})
.collect()
})
.unwrap_or_default();
let downloads: Vec<serde_json::Value> = self.shared.downloads.borrow().items.iter().map(|d| serde_json::json!({"id": d.id, "name": d.file_name(), "state": format!("{:?}", d.state), "received": d.received, "total": d.total, "error": d.error, "manager": d.manager})).collect();
let settings = self.shared.settings.borrow();
serde_json::json!({
"windows": self.windows.len(),
"window_kinds": self.windows.values().map(|w| format!("{:?}", w.kind)).collect::<Vec<_>>(),
"tabs": tabs,
"downloads": downloads,
"vpn": format!("{:?}", self.shared.vpn_status.borrow()),
"route": self.shared.bridge.as_ref().map(|b| format!("{:?}", b.route())),
"bridge_bytes": self.shared.bridge.as_ref().map(|b| b.bytes.load(std::sync::atomic::Ordering::Relaxed)),
"adblock": {"ready": self.shared.adblock.ready(), "rules": self.shared.adblock.rule_count(), "status": self.shared.adblock_status.borrow().clone(), "total": settings.adblock.total},
"history": self.shared.history.borrow().len(),
"bookmarks": self.shared.bookmarks.borrow().all().len(),
"logins": self.shared.vault.borrow().contents.logins.len(),
"vault_locked": self.shared.vault.borrow().locked(),
"apps": self.shared.apps.borrow().items.len(),
"dlm": format!("{:?}", self.shared.dlm_status.borrow()),
"discord": self.shared.presence_status.borrow().clone(),
"spell": self.shared.spell_status.borrow().clone(),
"update": self.shared.update_status.borrow().clone(),
"media_now": self.shared.media_now.borrow().as_ref().map(|m| m.title.clone()),
"import_sources": self.shared.import_sources.borrow().iter().map(|s| s.name()).collect::<Vec<_>>(),
"memory": crate::perf::own_memory(),
"user_agent": self.shared.user_agent.borrow().clone(),
})
}
}

View file

@ -360,7 +360,8 @@ impl Default for Rpc {
Self {
enabled: false,
target: RpcTarget::Arrpc,
client_id: String::new(),
// Nacre's own Discord application; users can put their own in settings.
client_id: "1560319659872485462".to_owned(),
custom: Vec::new(),
disabled_sites: Vec::new(),
site_ids: BTreeMap::new(),

View file

@ -56,6 +56,8 @@ pub struct BrowserWindow {
pub pip_frame: Option<egui::TextureHandle>,
pub pip_size: [u32; 2],
pub focused: bool,
/// Save the next frame to this file (self-test screenshots).
pub shot_request: Option<std::path::PathBuf>,
}
/// Choose the winit window attributes for a kind of window.
@ -114,6 +116,7 @@ impl BrowserWindow {
pip_frame: None,
pip_size: [0, 0],
focused: true,
shot_request: None,
})
}
@ -219,6 +222,17 @@ impl BrowserWindow {
let rgba = egui::Rgba::from(clear);
egui_glow::painter::clear(self.egui.painter.gl(), [size.width, size.height], [rgba.r(), rgba.g(), rgba.b(), 1.0]);
self.egui.paint(&self.window);
if let Some(path) = self.shot_request.take() {
let rect = servo::DeviceIntRect::from_origin_and_size(Point2D::new(0, 0), euclid::Size2D::new(size.width as i32, size.height as i32));
match self.rendering.read_to_image(rect) {
Some(image) => {
if let Err(error) = image.save(&path) {
log::error!("screenshot {}: {error}", path.display());
}
},
None => log::error!("screenshot {}: the window couldn't be read", path.display()),
}
}
self.rendering.present();
}