# 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` (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 `/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 `). 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-