Architecture
Nobook Architecture
Nobook is a highly opinionated desktop wrapper for Facebook, built using Tauri v2. It leverages native OS WebView engines (WebView2 on Windows) to render the Facebook mobile interface (m.facebook.com) while aggressively injecting custom JavaScript and CSS to modify the user experience.
Core Components
1. Tauri Backend (Rust)
The Rust backend is responsible for:
- Window creation and WebView initialization.
- Managing native OS bindings (e.g., launching default browsers for external links via
rundll32 url.dll,FileProtocolHandler). - Exposing IPC (Inter-Process Communication) commands for the frontend (e.g.,
save_settings,get_settings,open_url,write_log). - Handling native
on_navigationevents to intercept webview redirects at the OS level. - Running a background thread to watch for settings file modifications (Hot Reload).
2. Frontend Injector (JavaScript)
Because Nobook does not host its own HTML pages (it loads m.facebook.com directly), all UI and feature logic is dynamically injected at document.readyState === 'loading'.
The Rust backend reads raw JS files from app/src/main/res/raw/ and compiles them into a single string during the build process (include_str!). This string is evaluated as the initialization_script of the WebView.
3. Settings Engine
Settings are stored locally in a .nobook_settings.json file in the user’s AppData or HOME directory. When the app launches, Rust parses this JSON and dynamically constructs a window._NOBOOK_FILTERS configuration array. This array is injected directly into the WebView before the MasterObserver initializes.
Data Flow
- Launch:
desktop.exestarts. - Read Config: Rust reads
.nobook_settings.json. - Compile Payload: Rust evaluates flags (e.g.,
show_suggested: false) and injects the corresponding filter keywords into a singlewindow._NOBOOK_FILTERSconfiguration payload alongside the core JS modules. - WebView Init: Tauri creates the WebView pointing to Facebook and executes the payload immediately.
- DOM Modification: The single Master
MutationObserverbegins observing the DOM. It checks the text of new nodes against the_NOBOOK_FILTERSarray and mutates Facebook’s React tree (hiding elements, styling, intercepting clicks) in a highly-optimized $O(N)$ pass. - IPC Communication: When the user clicks the Custom Settings button, the injected JS communicates with Rust to save new preferences or batch-write to the native log file.