366 lines
31 KiB
Markdown
366 lines
31 KiB
Markdown
# Nacre (Rust) — design notes
|
||
|
||
Working notes for whoever continues this code. Keep it current.
|
||
|
||
## Ground rules (from the user, 2026-11-10)
|
||
|
||
- Everything in Rust; the engine is WebKitGTK 6.0 (D-032, Linux only) in a GTK 4 host; the chrome is egui. (The first engine was Servo 0.7; it was removed in S053, history in `docs/engine/servo-removal.md`.)
|
||
- Function first. The UI is plain egui for now; the designed UI comes after everything works.
|
||
- Written from scratch. The older `astar76/Nacre-rust` repo is not a source.
|
||
- No builds until the code has been reviewed and declared "first build worthy". Then one build:
|
||
`nice cargo build --release -j 2`. Never run tests alongside a release build.
|
||
- Feature spec: the settings screenshot plus the original Python Nacre (`~/Documents/Apps/Nacre/nacre`,
|
||
`config.py` DEFAULTS is the list of settings). Nothing in there is to be dropped silently; things WebKit cannot do
|
||
are listed under "Engine limits" and shown as unavailable in the UI.
|
||
- Never connect to Tor or proxies in tests.
|
||
|
||
## Layout
|
||
|
||
```
|
||
src/main.rs args, single instance, starts the GTK application
|
||
src/app.rs App: owns the engine, windows, timers, background jobs; handles engine events from a GLib idle
|
||
src/window.rs BrowserWindow: gtk::ApplicationWindow, Overlay of the tabs' web views and the egui area
|
||
src/egui_area.rs egui painted in a transparent Gtk.GLArea over the window; pointer only where egui has something
|
||
src/engine/ WebKitGTK: `host.rs` Engine (network session, web context, settings, signals -> Event queue),
|
||
`view.rs` View (one web view's actions), `mod.rs` Event, ViewId and payload types
|
||
src/tabs.rs Tab (one View or an internal page), per-window tab list
|
||
src/keys.rs GTK key -> shortcut table (rebindable)
|
||
src/inject.rs JavaScript injected into pages (bridge, autofill, find, media, PiP, cosmetic filters)
|
||
src/adblock.rs adblock-rust: lists, updates, cosmetic engine, conversion to WebKit content filters
|
||
webext/ web process extension (cdylib): headers, stand-ins, blocked counts (D-036)
|
||
src/discord.rs Discord Rich Presence over the local IPC socket
|
||
src/media.rs media state gathered from pages; feeds the media button, Discord, MPRIS later
|
||
src/importer.rs import from Chromium- and Firefox-family browsers
|
||
src/spell.rs spell check (spellbook + hunspell dictionaries)
|
||
src/perf.rs memory use, low-memory mode, energy saver, tab freezing and unloading
|
||
src/updates.rs update check against the Forgejo releases API
|
||
src/paths.rs config / data / cache dirs, profiles
|
||
src/tabs.rs Tab, internal pages (Page), prompts and dialogs per tab
|
||
src/theme.rs palette and egui visuals from the Appearance settings
|
||
src/resources.rs titles and builders of Nacre's error and certificate pages
|
||
src/instance.rs single instance per profile (links go to the running browser)
|
||
src/pdf.rs one-page PDF for "save as PDF"
|
||
src/actions.rs Command enum and everything the browser does when asked
|
||
src/util.rs small helpers (time, url fixing, json files, random)
|
||
src/store/ settings, history, bookmarks, downloads, vault, permissions, session, apps, scripts
|
||
src/net/ bridge (local proxy: direct / SOCKS5 / HTTP upstream, DoH), policy, privacy, fetch (ureq), tor, dlm
|
||
src/ui/ egui: chrome (tab strip, toolbar, omnibox, bookmarks bar), menus, dialogs, pages/*
|
||
```
|
||
|
||
## How the pieces fit
|
||
|
||
- One process, many windows. `App` holds `Rc<Shared>` (engine, stores, ad blocker, bridge handle) and a map of
|
||
`BrowserWindow`s. Window kinds: Normal, App (site installed as app: no toolbar), Pip (floating window with one video).
|
||
- Incognito is a second process (`nacre --incognito`) with a temporary profile deleted on exit and an ephemeral
|
||
engine session (`Setup.dirs = None`).
|
||
- Rendering (D-033, D-035): each window is a `Gtk.Overlay`: below, a `Gtk.Stack` with one WebKit web view per tab,
|
||
placed at egui's page rectangle by margins; above, an `EguiArea` (transparent `Gtk.GLArea`, `egui_glow`) that draws
|
||
all the chrome. WebKit draws the page itself. GTK's pick sends the pointer to egui only where egui has something
|
||
(the chrome, flyouts, menus, dialogs, toasts); elsewhere the page gets pointer, wheel, right click, drag and IME
|
||
natively. Keyboard focus goes to the page after navigation (`focus_page`) and to egui for the address field.
|
||
- WebKit signals arrive on the main thread. The handlers in `engine/host.rs` only turn them into `Event`s on the
|
||
`Hub` queue (never touching `App`, which may be borrowed while WebKit emits a signal synchronously);
|
||
`App::handle_event` handles them from a GLib idle (`app::pump`). Questions WebKit needs answered (navigation,
|
||
permissions, dialogs, certificate errors, downloads) travel as payload types that hold the WebKit request object,
|
||
and the answer goes back through them. Views are known by Nacre's own `ViewId` (D-041); the map to `WebView` lives
|
||
in `host.rs` only.
|
||
- Page -> browser messages: the `nacre` script message handler (registered before a view is built) carries
|
||
`inject.rs` messages as JSON. Browser -> page: `View::evaluate_javascript` (JSON result).
|
||
- Network: the engine is pointed at `net::bridge` (SOCKS5 with a per-run user name and token; the same port also
|
||
speaks HTTP proxy). The bridge decides per connection: direct (optionally resolving through DoH), or through the
|
||
VPN upstream (SOCKS5 with remote DNS for Tor, or an HTTP proxy). Switching VPN or DNS needs no restart. Nacre's own
|
||
requests (downloads, filter lists, updates) go through the bridge too. `NACRE_NO_BRIDGE=1` turns it off for
|
||
debugging. Request policy (HTTPS-only, tracking parameters, external schemes, downloads) is `net::policy::decide`
|
||
in WebKit's `decide-policy`; sub-resource work is the web process extension (see "Ad blocker on WebKit").
|
||
- Settings pages, history, bookmarks, downloads, passwords, apps and so on are egui views shown in a tab
|
||
("internal tab", `nacre://settings` etc.), not web pages.
|
||
|
||
## WebKitGTK embedding cheat sheet
|
||
|
||
```
|
||
webkit = { package = "webkit6", version = "=0.6.1", features = ["v2_52"] } // WebKitGTK 6.0; gtk4, glib, egui_glow
|
||
webkit::functions::{major,minor,micro}_version() // shown in Settings -> About (`engine_version()` in main.rs)
|
||
NetworkSession (persistent dirs or ephemeral) .website_data_manager() .cookie_manager() .set_proxy_settings(..)
|
||
WebContext / WebView::builder().network_session(..).related_view(parent) // pop-ups keep window.opener
|
||
Settings: user agent, developer extras, hardware acceleration policy, media stream, WebRTC (tuning: docs/engine/tune/)
|
||
UserContentManager: add_script / add_style_sheet (all frames, author level), register_script_message_handler("nacre"),
|
||
UserContentFilterStore (compiled ad blocker filters, `engine/host.rs set_content_filter`)
|
||
Signals -> Event: load-changed, notify::uri / title / estimated-load-progress / is-playing-audio, decide-policy
|
||
(navigation, new window, response -> downloads), create, close, permission-request, script-dialog,
|
||
web-process-terminated, load-failed-with-tls-errors, authenticate, show-notification, enter/leave-fullscreen,
|
||
context-menu (Nacre draws its own), run-file-chooser (portal), show/hide select / colour pickers
|
||
FindController (find, count, highlight), WebInspector (F12, attached; remote inspection on 127.0.0.1:6080 by request),
|
||
evaluate_javascript, set_zoom_level, set_is_muted, back_forward_list, print
|
||
Web process extension (`webext/`): send-request headers and redirects, console-message-sent for blocked counts
|
||
```
|
||
|
||
egui 0.37 deprecates `Ui::id` (now `Ui::scope_id`) and `Id::new` (now `Id::unique` / `IdSalt::new`); the code still
|
||
uses the old names, which build with warnings.
|
||
|
||
Not in WebKit, so Nacre does it itself: spell check (hunspell dictionaries), password capture and autofill,
|
||
extensions replaced by user scripts and styles, the context menu, the download manager, picture in picture window.
|
||
|
||
## Engine limits (shown as unavailable, not hidden)
|
||
|
||
- Widevine / DRM video: EME is off in this build (WebKitGTK ships none); the setting stays, marked "not available with
|
||
this engine". Widevine on WebKit is a later plan.
|
||
- Chrome extensions: not possible. Replaced by user scripts and user styles (Apps -> Scripts).
|
||
- Hardware acceleration switch: "Off" selects software rendering on next start.
|
||
- Permissions WebKit never asks the embedder about: storage persist, per-site JavaScript (not wired yet), MIDI,
|
||
Bluetooth, wake lock, background sync, game controllers.
|
||
- Ad blocker: network rules WebKit's content blocker can't express are dropped (table in "Ad blocker on WebKit"); the
|
||
`images` permission is not enforced.
|
||
- Web process memory isn't split per tab in the task manager; the "Nacre uses" figure is the host process.
|
||
- Pop-ups always open as tabs, never as separate windows.
|
||
- Fingerprinting: bits per metric and what privacy mode covers are in `docs/engine/privacy-mode.md` (the Servo-era
|
||
numbers there are historical).
|
||
|
||
## Media
|
||
|
||
Playback is WebKit's own (GStreamer) including Media Source Extensions; `tests/smoke/mse*.txt` are plain MSE tests.
|
||
Page media state (title, position, playing) is read by a page probe and `is-playing-audio`; `media.rs` feeds the media
|
||
button, Discord and MPRIS. Picture in picture moves the live web view into its own floating window and back (no reload).
|
||
The patched gst_mse of the Servo era is gone; `docs/engine/gst-mse-patches.md` is its record.
|
||
|
||
## Cookies at rest
|
||
|
||
`store::cookies` seals the cookie jar into `<data>/cookies.bin` with XChaCha20-Poly1305 (`vault::seal`, AAD
|
||
`nacre-cookies-v1`, magic `NACRECK1`); the 256-bit key lives in the OS keyring (crate `keyring` 3, service `Nacre`,
|
||
account `cookies <data folder>`). Without a keyring cookies live for the run only and nothing is written (Settings →
|
||
Privacy → Site data says so). A file that doesn't decrypt is moved to `cookies-unreadable-<time>.bin`. Incognito
|
||
writes nothing. Reconnecting this to WebKit's cookie manager (cookie DB on tmpfs, sealed on exit) is plan S051 (D-037).
|
||
|
||
## Privacy mode
|
||
|
||
Page script `PRIVACY_JS` (`inject.rs`) plus the web process extension and WebKit's third-party cookie policy; every
|
||
surface, the choice made for it and the Cover Your Tracks result are in `docs/engine/privacy-mode.md`. Paused per site
|
||
(`privacy.mode_off`); on in incognito windows by default (`privacy.mode_incognito`).
|
||
|
||
## UI system (S015)
|
||
|
||
Everything the interface draws takes its colours, radii, sizes and springs from `src/theme.rs`; widgets live in
|
||
`src/ui/widgets.rs`, Expressive shapes in `src/ui/paint.rs`, icons in `src/ui/icons.rs`. `nacre://gallery`
|
||
(`src/ui/pages/gallery.rs`, not linked from the UI) shows all of it; `SMOKE_SIZE=1400x2800 tools/smoke.sh
|
||
tests/smoke/gallery.txt` shoots it dark and light. Rules: the `app-taste` skill. No one-off colour, radius or duration.
|
||
|
||
**Tokens reach widgets through the egui context.** `theme::apply(ctx, &palette, &settings)` (called by
|
||
`App::style_window` whenever the theme, seed or settings change) stores `theme::Tokens { palette, roundness, motion }`
|
||
and sets egui visuals, text styles and spacing. From any `Ui`: `theme::palette(ui.ctx())`,
|
||
`theme::radius(ui.ctx(), theme::L)`, `theme::spring(...)`. Fonts are set once per window: `ui::fonts()` in
|
||
`window.rs`.
|
||
|
||
**Colour** (`theme::Palette`, from the `material-colors` crate, D-009). `Palette::new(seed, dark, variant, contrast)`
|
||
builds the M3 scheme; `variant` is a `theme::VARIANTS` key (tonal_spot default), `contrast` -1..1. Seeds:
|
||
`theme::seed` (website colour if chroma ≥ 12 and tone 8..95, else fallback; system accent; preset; custom).
|
||
- M3 roles: `primary`, `on_primary`, `primary_container`, `on_primary_container`, `inverse_primary`, `secondary*`,
|
||
`tertiary*` (same four each), `error`, `on_error`, `error_container`, `on_error_container`, `surface`,
|
||
`surface_dim`, `surface_bright`, `surface_container_lowest`, `surface_container_low`, `surface_container`, `surface_container_high`,
|
||
`surface_container_highest`, `on_surface`,
|
||
`on_surface_variant`, `outline`, `outline_variant`, `inverse_surface`, `inverse_on_surface`, `scrim`, `shadow`.
|
||
- Extra: `warning`, `success` (fixed hues at primary's tones).
|
||
- Old names kept as aliases for existing code: `accent` = primary, `on_accent` = on_primary, `accent_soft` =
|
||
secondary_container, `surface_high` = surface_container_high, `surface_low` = surface_container_lowest (the page
|
||
background), `text` = on_surface, `text_weak` = on_surface_variant. New code uses the M3 names.
|
||
- Usage: page background `surface_container_lowest`; cards `surface_container`; floating surfaces
|
||
`surface_container_high`; fields `surface_container_highest`; hairlines `outline_variant`; selection
|
||
`secondary_container` + `on_secondary_container`; main action `primary`.
|
||
- State layers: `theme::layer(base, over, amount)` mixes opaque; constants `HOVER` 0.08, `FOCUS` 0.10, `PRESS` 0.10,
|
||
`DRAG` 0.16, `DISABLED_CONTENT` 0.38, `DISABLED_CONTAINER` 0.12 (content colour over the container).
|
||
|
||
**Shape and space.** Radii `XS` 4, `S` 8, `M` 12, `L` 16, `XL` 28, `FULL` (pill); always read through
|
||
`theme::radius(ctx, token)` (Roundness setting: Subtle ×0.5, Default ×1, Round ×1.4) and convert with
|
||
`theme::corner_radius(f32)`. Spacing `GAP_XS` 4, `GAP_S` 8, `GAP_M` 12, `GAP_L` 16, `GAP_XL` 24. Heights
|
||
`CONTROL_SMALL` 32 (icon buttons), `CONTROL` 40 (buttons, segmented), `ROW` 56 (list rows). Cards use `L`, chrome
|
||
pills `FULL`, small egui widgets `S` (`theme::corner`).
|
||
|
||
**Type.** Outfit (OFL, `assets/fonts/Outfit[wght].ttf`, one variable font) at `theme::Weight` Thin 200, Light 300,
|
||
Regular 400 (egui's Proportional), Medium 500, SemiBold 600; `theme::font(size, weight)`. Sizes `SMALL` 12, `BODY` 14,
|
||
`TITLE` 18, `HEADLINE` 24, `DISPLAY` 64, `DISPLAY_LARGE` 96 (new tab clock: SemiBold, primary), `DISPLAY_SMALL` 40 (figures in cards). egui text styles: Small/Body/Button/Heading(24
|
||
Medium)/Monospace 13. Outfit is Latin only: every family falls back to Material Symbols, then egui's Ubuntu-Light
|
||
(Cyrillic, Greek). No CJK font is bundled.
|
||
|
||
**Icons.** Material Symbols Outlined (Apache 2.0), cut to `tools/icons.txt` by `tools/icons.py` into
|
||
`assets/fonts/MaterialSymbolsOutlined-Nacre.ttf` (FILL and wght axes kept). Use the constants `icons::HOME` etc.
|
||
(`icons::ALL` lists them). To add one: add its name (fonts.google.com/icons) to `tools/icons.txt`, run
|
||
`python tools/icons.py`. Draw with `widgets::icon(ui, center, glyph, size, filled, colour)` or
|
||
`theme::icon_font(size, filled)`; filled (FILL 1) is for selected states. Icons also work inside text (`format!("{}
|
||
Open folder", icons::FOLDER_OPEN)`) through the fallback. Sizes `ICON` 20, `ICON_LARGE` 32. Never emoji.
|
||
|
||
**Motion.** `theme::spring(ctx, id, target, spring) -> f32`: per-id state in egui memory, retargets keeping
|
||
velocity, starts at the target on first use, repaints only while moving, returns the target at once with Motion off.
|
||
`theme::effect(ctx, id, on) -> 0..1` is the colour/opacity spring. Presets (stiffness/damping ratio): `FAST`
|
||
1400/0.62 (press, small controls), `DEFAULT` 700/0.68 (panels, movement), `SLOW` 300/0.74 (big transitions),
|
||
`EFFECT` 900/1.0 (colour, opacity; never overshoots). Motion setting = time factor (Off 0, Fast 0.6, Normal 1,
|
||
Slow 1.8; stiffness ÷ factor²); `theme::animation_time` drives egui's own animations (0.1 s × factor).
|
||
|
||
**Widgets** (`ui::widgets`; all have hover state layer, press squeeze, focus ring in `secondary`, disabled 38 %):
|
||
- `button(ui, ButtonKind::{Filled, Tonal, Outlined, Text}, Option<icon>, label) -> Response`: 40 px pill, press
|
||
morphs to radius `S`.
|
||
- `icon_button(ui, icon, tooltip)`, `icon_toggle(ui, icon, tooltip, on)`: 32 px circle, press squashes to a squircle;
|
||
selected = `secondary_container` fill and filled icon.
|
||
- `switch(ui, &mut bool) -> changed`: M3 switch, handle travels (FAST) and grows with a check when on, hover halo.
|
||
- `segmented(ui, &mut T, &[(T, label)]) -> changed`: equal-width segments, selected = tonal fill + check that slides in.
|
||
Animation state is keyed on the widget's id, never its position (a position key breaks while the page scrolls).
|
||
- `card(ui, |ui| ...)`: `surface_container`, radius `L`; rows inside get hairlines between them (not above the first).
|
||
- `row(ui, title, description, |ui| control)`, `switch_row`, `link_row(ui, title, description) -> clicked` (whole
|
||
row is the button, chevron at the end), `section(ui, title)` (group title in `primary`, above a card).
|
||
- `text_field`, `number` (stepper: − value +, fixed width so rows line up), `page_column`, `glyph(toolbar key) -> icon`.
|
||
- Rows (S019): `icon_row` / `icon_link_row` (leading icon), `wide_row` (control under the text, for chips and
|
||
lists), `limited_row` (partial engine support: a tertiary info line under the description), `unavailable_row`
|
||
(engine can't: reason + "Not available" label). A row remembers its control's width and moves the control under
|
||
the text when it doesn't fit beside 220 pt of text (`request_discard`, no flicker). `highlight_rows(ctx, query)`
|
||
tints and counts matching rows (settings search). `chip`, `choice_chips` (one of many), `toggle_chips` (any of),
|
||
`input_chip` (label + ×), `slider` (M3 Expressive, moved from Customize).
|
||
- Still under the pointer (R1-21): a control never changes the layout around itself while it is used.
|
||
`filter_chip(ui, label, on)` (used by `choice_chips` / `toggle_chips` and on/off chips) keeps one width, the check
|
||
slides in over reserved space. `slider` sets its value live, for settings that only repaint (contrast, dim,
|
||
blur); `settled_slider(…, &|v| label)` is for settings that re-lay out the page (interface size): while dragged
|
||
only the handle and an M3 value label move, the value is set on release (a click or arrow key sets it at once).
|
||
|
||
**Settings** (S019, `src/ui/pages/settings.rs`). Rail 264 pt (title, search pill, 48 pt entries, sliding
|
||
`secondary_container` pill); under 760 pt page width an 88 pt icon rail (56×32 pill, short label under) with the
|
||
search pill above the content. Content column 760 pt; header = Headline title, sub-pages get a back button and the
|
||
section name above. Search draws every section unseen (`UiBuilder::invisible`, own id salt) to count matching rows,
|
||
then shows only sections with matches, rows highlighted; `nacre://settings/?search=<words>` opens it. Appearance:
|
||
scheme preview (mini browser in the live roles + key colours), palette swatches built per preset with the current
|
||
mode/style/contrast (cached), custom colour = hex field + picker.
|
||
|
||
**Pages and dialogs** (S020). Page widgets in `widgets.rs`: `page_header(title, subtitle, actions)` (Headline title,
|
||
actions right or under it below 640 pt, subtitle truncated), `search_pill(id, &mut text, hint)`, `empty_state(glyph,
|
||
title, body, action)` and `status_state(glyph, title, body, error)` (round icon, plain words, button), `list_item(id,
|
||
glyph, title, detail, trailing)` (one 56 pt row inside a `card`: round icon, title and detail cut with an ellipsis,
|
||
whole row clickable, icon buttons at the end), `more_menu` (more button + `menus::menu_item` rows), `password_field`,
|
||
`strength_meter`. Pages follow one shape: header, search pill, then `section` + `card` groups; every list has an empty
|
||
state (what will appear and how) and a "nothing matches" state. `row` now lays the control beside the text on its first
|
||
frame and moves it under the text only when it measured too wide (it used to start stacked, which stuck in narrow cards).
|
||
Welcome (`pages/welcome.rs`): six steps in a 560 pt card over the new tab backdrop; indicator dots (current one a
|
||
stretched pill, clickable), card height on a spring, step content fades and slides in (a new spring id per step),
|
||
Enter continues, Escape skips, every choice is written to settings at once. Dialogs (`dialogs.rs::dialog_card`): scrim
|
||
over the page rect, `surface_container_high` card radius `XL`, padding 24, one shadow, eases in; title Headline, body
|
||
`on_surface_variant`, actions right with the main one last (Enter = main, Escape = cancel). Permission and find bars are
|
||
56 pt `surface_container_high` bars with real buttons. Selftest: `key <name>`, `welcome <step>`. The web error pages
|
||
(`assets/pages/*.html`) use the same roles in CSS with a dark scheme.
|
||
|
||
**Shapes** (`ui::paint`): `cookie(painter, center, radius, lobes, rotation, fill, stroke)`,
|
||
`cookie_image(painter, texture, center, radius, lobes, rotation)` (artwork in a cookie), `cookie_points`,
|
||
`wavy_line(painter, x0, x1, y, amplitude, wavelength, phase, stroke)`, `wavy_progress(painter, rect, fraction,
|
||
amplitude, phase, &palette)` (amplitude 0 = flat, animate it with a spring when playing/paused; advance `phase` only
|
||
while something plays), `shadow(painter, rect, radius, dark)` (one soft shadow for floating surfaces; egui's
|
||
`window_shadow`/`popup_shadow` are set to match).
|
||
|
||
**What egui can't do here:** no text blur or text shadows; no per-glyph variable axes inside one label (a weight is
|
||
a font family); shadows are tessellator-blurred rectangles only (not arbitrary shapes); `Ui::id`/`Id::new` are
|
||
deprecated in 0.37 but still used across the code.
|
||
|
||
**Chrome** (S016, `src/ui/chrome.rs`). Everything behind the chrome and around the page is `chrome::chrome_fill`
|
||
(`surface_container`); the page is a card with margin `GAP_S` (sides and bottom) and radius `L`. Web pages are
|
||
blitted as rectangles, so `ui::card_corners` paints a ring in the chrome colour over the corners (works over the GL
|
||
blit). Heights: tab strip 44 (tab pills 34, gap 4, width 76..240, pinned 44, +24 with an audio button), toolbar 52
|
||
(address pill 40), bookmarks bar 36 (chips 28), title bar 36, app bar 44; buttons inside tabs and the address field
|
||
are 24. Tabs slide to their slots with `DEFAULT` springs, the selection pill (secondary_container) slides between
|
||
them, a dragged tab stays under the pointer (`theme::spring_jump`) and the others make room (`drag_layout`); a
|
||
window resize jumps instead of sliding. Toolbar order: back, forward, reload, home, incognito | address | passwords,
|
||
history, bookmarks, downloads, qr, apps, devtools, pip, screenshot, adblock, media, vpn, profile, menu (each shown
|
||
per the toolbar setting). Status on buttons: badges (blocked count, running downloads), a progress ring round
|
||
downloads, a coloured dot on the VPN, a slash through the shield when off. All icons are Material Symbols (D-009).
|
||
|
||
**New tab page** (S017, `src/ui/pages/newtab.rs`). A column of at most 920 pt (24 pt side margins) centred in the
|
||
page card, and centred vertically when it fits (measured the frame before; a `DEFAULT` spring moves it when elements
|
||
change). Elements come in `Settings::ntp.elements` order; `blocks()` groups card elements that follow each other into
|
||
rows on a 3-column grid (2 below 720 pt, 1 below 480 pt), Now playing spanning two columns; a short row is centred.
|
||
Rows: Now playing/Weather 224 pt (Now playing below 440 pt wide puts its artwork above, +136 pt), other cards 176 pt;
|
||
cards are `surface_container`, radius `L`, title = 18 pt icon + Body Medium in `primary`. Clock: `DISPLAY_LARGE` 96
|
||
(`DISPLAY` 64 under 560 pt) SemiBold `primary` (the user asked for heavier digits in S018), colons `primary` at 45 %,
|
||
every digit in a cell as wide as the widest digit (no shifting), AM/PM Title Medium `on_surface_variant` with its top
|
||
on the digits' top; date `util::format_long_date`. Shortcuts: 56 pt circles in 88 pt cells,
|
||
favicon of an open tab on that site else the first letter; dashed `outline` circle for Add; right-click opens/removes.
|
||
Search pill 640×56, `surface_container_high`, `primary` ring while focused, 40 pt `primary` go button. Media art,
|
||
visualizer ring (56 radial bars starting just outside the cookie's scallops, bands mirrored left/right, turning with the cookie at one turn a minute; short `outline_variant` ticks when still), seek bar, play button and titles
|
||
are shared with the media flyout: `menus::media_art`, `seek_bar`, `play_button`, `media_title`. Weather:
|
||
`newtab::Weather` (Open-Meteo current + daily, `Shared::weather` = `Option<Result<Weather, String>>`), fetched when
|
||
shown and missing, older than 30 min, or for another place/unit (after the place stays unchanged for 1 s).
|
||
|
||
**New tab backdrop and Customize** (S018, `src/ui/pages/backdrop.rs`, `customize.rs`). Under the elements: the image or
|
||
GIF (`ntp.bg_image`, decoded on a thread, GIF frames with their delays, cover-fit, Blur = shrink + small gaussian +
|
||
linear stretch in 2 px steps, Dim = `surface_container_lowest` at `bg_dim`), then one animated layer: Shapes (flowers,
|
||
clover outline, rounded triangles/squares, pills, soft blobs in primary/tertiary/secondary/inverse_primary tints),
|
||
Blobs (wobbling `*_container` circles), Constellation (`particles`: dots, lines under 150 pt, the cursor links dots
|
||
within 200 pt), Waves (sines that swell and bend near the cursor), Dot grid (faint ripple; dots swell and turn
|
||
`primary` within 210 pt of the cursor). Amount scales the count per megapixel (×0.55/1/1.8), Speed the clock
|
||
(×0.45/1/2), the Motion setting divides it, Motion off or `perf::still` freezes it (the cursor still reacts). The
|
||
cursor is smoothed by `DEFAULT` springs and fades in/out; the panel hides it. 60 fps via `request_repaint_after`.
|
||
Customize: a `surface_container_high` panel 400 pt wide (margin `GAP_S`) on an `Order::Middle` Area, sliding from the
|
||
right (`DEFAULT` spring); opened by the tonal "Customize" pill at the bottom right (and "Set place"), closed by its
|
||
×, or Escape. Rows 48 pt (icon, label, control right); filter chips for the background; an M3 Expressive slider
|
||
(16 pt track, bar handle with a gap); Weather place suggestions from Open-Meteo geocoding (`Command::SuggestPlaces`,
|
||
`Shared::places`, after 350 ms of no typing), picking one stores its coordinates. Selftest: `customize [close]`,
|
||
`pointer <x> <y> | off`.
|
||
|
||
**Redraw scheduling** (S018). egui's "repaint after N" is honoured: a repaint observer on each window's context
|
||
records the earliest wanted time, `App::draw` redraws at once only for immediate requests and otherwise sets
|
||
`BrowserWindow::redraw_at`, which `about_to_wait` wakes for. Hidden windows (`WindowEvent::Occluded`) skip scheduled
|
||
frames. Before S018 any delayed request redrew immediately, so the new tab page ran at the display rate.
|
||
|
||
**Floating surfaces** (`src/ui/menus.rs`). `menus::floating(ctx, id, pos, pivot, open, |ui| ..)` draws a
|
||
`menus::surface` (surface_container_high, radius `L`, popup shadow) that grows from its pivot corner (scale 0.9 to
|
||
1, `DEFAULT`) and fades in (`EFFECT`); with `open` false it shrinks and fades without input, then returns None.
|
||
Flyouts keep the last one drawn so it animates out; switching flyouts closes one while the other opens. Rows:
|
||
`menu_item(ui, icon, label, trailing, selected)` (34 high, icon column, label cut with an ellipsis, shortcut or
|
||
detail on the right), `divider`, `empty`, `one_line` (text cut to a width). egui popups (`Popup::menu`, submenus)
|
||
use the same `surface` frame. Areas need `default_size` set or egui caps them at 600×400.
|
||
Panel flyouts (R1-18, after the original's): `header(ui, title, |ui| ..)` (Title, actions as icon buttons on the
|
||
right, no leading icon), `group(ui, title, |ui| ..)` (accent label over a group, its actions on the right),
|
||
`entry(ui, icon, title, subtitle, time)` (48 high, icon in the menu rows' column, two lines, time on the right),
|
||
`empty_state(ui, icon, title, body)`, `line` (label + control), `text`, `actions` (one right-aligned row of
|
||
buttons). Text starts at `INSET` (12, the menu icons' edge). Never use a wrapping layout in a flyout: inside the
|
||
full-window `default_size` it centres itself in the whole height and stretches the surface (R1-17).
|
||
|
||
## Feature checklist
|
||
|
||
See `docs/FEATURES.md`; every row names the file that implements it and its review state.
|
||
|
||
## Ad blocker on WebKit (D-036, S049)
|
||
|
||
- **Network rules** → WebKit content filters. `adblock::convert` parses every enabled list (network rules only) with
|
||
adblock-rust's `content-blocking` conversion; blocks first, then exceptions (`ignore-previous-rules`), then the
|
||
"first-party documents pass" rule; identical rules are dropped. WebKit refuses a filter of more than 150 000 rules,
|
||
so blocks are shared out over several filters and **each filter repeats every exception** (an exception only
|
||
reaches rules of its own filter). JSON at `<cache>/adblock-engine.webkit<N>.json`, compiled by
|
||
`UserContentFilterStore` (`<cache>/content-filters`, id `nacre-adblock-<list fingerprint>-<N>`); a restart with the
|
||
same lists loads the compiled filter (ms). First compile of the seed lists: ~7–15 s inside WebKit, off the main
|
||
thread; pages loaded meanwhile aren't network-blocked (cosmetic hiding still runs). `Engine::set_content_filter`
|
||
installs a build only when all its filters are ready and drops stale builds.
|
||
- **Cosmetic rules** stay in the adblock-rust engine (now built cosmetic-only) and page scripts, as before.
|
||
- **Per-site pause / ad blocker off**: the view's filters are detached in `decide-policy` before a main-frame load
|
||
of a paused host (`attach_filters`), and re-checked on every settings change.
|
||
- **Coverage, seed lists (10 lists, 2026-11-13)**: 152 610 network rules, 151 179 converted (99.1 %) into 149 902
|
||
WebKit rules (1 filter) and 268 redirects. Left out:
|
||
|
||
| Reason | Rules | What it means |
|
||
|---|---|---|
|
||
| `NetworkGenerichideUnsupported` | 590 | `$generichide` (the cosmetic engine still honours it) |
|
||
| `FullRegexUnsupported` | 248 | `/regex/` rules beyond WebKit's regex dialect |
|
||
| `NetworkRemoveparamUnsupported` | 215 | `$removeparam` (Nacre's own tracking-param strip covers the common ones) |
|
||
| `RedirectRuleOnly` | 151 | `$redirect-rule=`: a stand-in only for what another rule blocks; the filter's block wins |
|
||
| `FromNotSupported` | 121 | `$from=` / `$to=` domain options |
|
||
| `NoSupportedNetworkOptions` | 77 | only types WebKit has no name for (`$ping`, `$websocket`, …) |
|
||
| `NetworkCspUnsupported` | 28 | `$csp=` header injection |
|
||
| `UnlessAndIfDomainTogetherUnsupported` | 1 | `$domain=a.com\|~b.a.com` |
|
||
|
||
- **Redirect rules** (`$redirect=<name>`): when Nacre has the stand-in (`adblock::resource`: noopjs, noop.txt,
|
||
noop.css, noopjson, noopframe, transparent images) the rule goes to the extension, which rewrites the request to
|
||
`nacre-resource:<name>` (URI scheme served by the browser, registered secure + CORS); stand-ins Nacre lacks
|
||
(google-ima.js, media files, …) become plain blocks. Limits: an exception (`@@`) doesn't stop
|
||
an extension redirect; the extension can't see the resource type; third-party is "last two host labels differ".
|
||
- **Web process extension** (`webext/`, `libnacre_webext.so`, ~0.8 MB, minimal FFI — no maintained Rust bindings
|
||
for WebKit's web process extension API exist): config JSON (`net::rules::Config`: headers, strip, ad blocker
|
||
on, paused hosts, redirects) as initialization user data and `nacre-config` user messages. `send-request` sets
|
||
DNT/Sec-GPC/Save-Data, applies redirects, strips tracking parameters from sub-resources (`net::rules`, the one
|
||
copy, shared with the browser by `#[path]`). Loaded from `NACRE_WEBEXT_DIR`, else `<exe>/../lib/nacre` (packages:
|
||
`$APPDIR/usr/lib/nacre`), else the exe's folder (cargo builds it next to `target/release/nacre`).
|
||
- **Blocked counts**: a content-filter block never reaches `send-request` or the UI process. WebKit logs each one to
|
||
the page console ("Content blocker prevented frame displaying <page> from loading a resource from <url>"); the
|
||
extension's `console-message-sent` handler sends a `nacre-blocked` message to the page's view, and the UI adds it
|
||
to `Hub::blocked` (reset in the `load-changed` Started handler). Limits: depends on WebKit's console wording;
|
||
WebKit may not log blocks for every load type (checked: script, image, fetch, module, async/defer, dynamic import);
|
||
a block logged just after a new page starts may count for the new page.
|