Originally created by: kristofferR
Part of the assessment epic [#59] (Ref [#47]).
lib.rs was a 3,811-line monolith with 70+ #[cfg] attributes interleaved with cross-platform logic. This moves the code verbatim into modules along the section seams that already existed — pure relocation plus pub(crate)/use plumbing, no behavior changes:
| Module | Lines | Contents |
|---|---|---|
notifications.rs |
452 | NotifyMsg, avatar temp-PNG cache + sweeps, DND schedule (parse_hhmm/dnd_active), notify-rust path incl. the sound flag |
menu.rs |
451 | build_menu, handle_menu_event, mutate_settings, and the recent-conversations feature (RecentThread, sanitize/id helpers, rebuild_recent_menus) |
settings.rs |
448 | Settings struct/defaults + sanitized()/zoom clamping, AppState (incl. recent_threads), load/save, apply_settings, autostart, webview-data clearing |
download.rs |
426 | download allowlist/blocklist, filename helpers, unique_path |
window.rs |
378 | build_app_window, theme helpers, themed-window recreation, settings window, init script (incl. the zoom merge) |
url_rules.rs |
256 | tracking-redirect unwrap, internal/auth host rules, percent_decode |
tray.rs |
247 | tray build/toggle, build_tray_menu (with recent conversations), show_main, macOS reopen |
preflight.rs |
171 | Messenger DNS preflight, MessengerLoadStatus |
commands.rs |
159 | the #[tauri::command] fns (incl. open_log_folder), store_settings, run_update_check |
diag.rs |
84 | page-diagnostics parsing/sanitising and the DIAG_*/log-size caps |
hotkey.rs |
55 | the global summon hotkey (sync/apply/reconcile) |
macos/ |
447 | the objc2 interop: UNUserNotificationCenter delegate, theme observer, webview transparency, and the new dock.rs (applicationDockMenu: provider) |
lib.rs |
418 | crate constants, user-agent/Linux-webkit tuning, the run() builder + event listeners |
Each test moved next to the module it covers — 60 tests, same count as main, all passing. cargo fmt --check, clippy -D warnings, cargo check --features mcp, and node --check are clean.
The injected-script toolchain (#48) was originally scoped into this branch but is deferred to its own follow-up PR.
Redone on top of current main. The PRs that previously had to land first (global hotkey, page zoom, notification sound + DND, telemetry blocking, recent-conversations menus, Caprine shortcuts, diagnostics/log routing) have all merged; this split was redone from scratch against current main, so nothing needs to merge before it now.
Originally posted by: kristofferR
@coderabbitai review
Originally posted by: coderabbitai[bot]
✅ Action performed
Review finished. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.Originally posted by: coderabbitai[bot]
📝 Walkthrough
## Walkthrough This PR splits the Tauri backend into dedicated modules: commands, download, macos (notifications/theme), menu, notifications, preflight, settings, tray, url_rules, and window. It adds settings fields (badges, theme, privacy, notifications), download/URL safety validation, DNS preflight for Messenger connectivity, macOS native notifications, system theme observation, and window/tray/menu construction logic. ### Changes **Backend Module Split and Feature Additions** |Layer / File(s)|Summary| |---|---| |**Settings schema and persistence**`src-tauri/src/settings.rs`|Adds new persisted fields (unread_badge, badge_mode, theme, menu_bar_only, mute_notifications, hide_notification_preview, hide_names_avatars, system_emoji), load/save helpers, cache-clear scheduling, autostart sync, and apply_settings runtime propagation.| |**Settings commands and update/connect flow**
`src-tauri/src/commands.rs`|Implements get/set/reset settings commands, an updater-plugin check/install command, and a connect_messenger command that runs a DNS preflight before navigating the webview.| |**Messenger DNS preflight**
`src-tauri/src/preflight.rs`|Defines MessengerLoadStatus/MessengerPreflightError, sinkhole IP detection, and messenger_dns_preflight resolution/classification logic.| |**URL classification rules**
`src-tauri/src/url_rules.rs`|Adds tracking-redirect unwrapping, auth URL allowlisting, internal-URL classification, and a percent-decoder.| |**Download safety rules**
`src-tauri/src/download.rs`|Adds media-host allowlisting, filename sanitization/derivation, download allow/deny logic, executable extension blocking, and collision-safe path generation.| |**Window construction and theming**
`src-tauri/src/window.rs`|Adds theme helpers, build_app_window with navigation/download enforcement, close-to-tray handling, macOS window recreation on theme change, settings window, and init_script JS injection.| |**Menu construction and event handling**
`src-tauri/src/menu.rs`|Builds the native menu and handles menu events for settings mutation, window actions, cache clearing, and devtools.| |**Tray icon and window reveal logic**
`src-tauri/src/tray.rs`|Adds tray enablement, unread badge title, macOS reopen-after-quit logic, and tray icon/menu construction.| |**macOS native notifications**
`src-tauri/src/macos/mod.rs`, `src-tauri/src/macos/notifications.rs`|Implements a UNUserNotificationCenter delegate, authorization setup, and notification delivery with avatar attachments and click routing.| |**macOS theme interop**
`src-tauri/src/macos/theme.rs`|Adds WKWebView transparency, NSWindow background setting, dark-mode detection, and a KVO observer that triggers window recreation on system theme flips.| |**Cross-platform notification dispatch**
`src-tauri/src/notifications.rs`|Defines NotifyMsg parsing, avatar decoding/caching, per-OS notification dispatch, and click routing back into the webview.| **Estimated code review effort:** 4 (Complex) | ~75 minutes ### Sequence Diagram(s) :::mermaid sequenceDiagram participant Frontend participant connect_messenger participant messenger_dns_preflight participant WebviewWindow Frontend->>connect_messenger: invoke command connect_messenger->>messenger_dns_preflight: run DNS check with timeout messenger_dns_preflight-->>connect_messenger: Ok or Blocked/DnsFailed alt DNS resolves connect_messenger->>WebviewWindow: navigate_to_messenger WebviewWindow-->>connect_messenger: loading status else Blocked connect_messenger-->>Frontend: MessengerLoadStatus (blocked) else Other failure/timeout connect_messenger->>WebviewWindow: navigate anyway end connect_messenger-->>Frontend: MessengerLoadStatus :::mermaid sequenceDiagram participant Page participant show_message_notification participant OSNotification participant on_notification_click participant MainWebview Page->>show_message_notification: carrier:notify payload show_message_notification->>OSNotification: deliver_notification_macos / show_native_notification OSNotification-->>show_message_notification: user activation/click show_message_notification->>on_notification_click: id on_notification_click->>MainWebview: __carrierNotifyClick(id) **Possibly related issues** - [kristofferR/Carrier#47](https://github.com/kristofferR/Carrier/issues/47): Describes splitting `src-tauri/src/lib.rs` into the same settings, tray, menu, notifications, download, url_rules, preflight, and macos modules implemented in this PR. **Possibly related PRs** - [[kristofferR/Carrier#13](https://github.com/kristofferR/Carrier/issues/13)](https://github.com/kristofferR/Carrier/pull/13): Overlaps with the new native notification implementation and macOS avatar decoding/click routing back to the webview. - [[kristofferR/Carrier#34](https://github.com/kristofferR/Carrier/issues/34)](https://github.com/kristofferR/Carrier/pull/34): Shares the same macOS UNUserNotificationCenter delegate and deliver_notification_macos flow including avatar attachment and click routing. - [[kristofferR/Carrier#41](https://github.com/kristofferR/Carrier/issues/41)](https://github.com/kristofferR/Carrier/pull/41): Implements the same DNS-preflight-based Messenger reachability diagnostics and connect_messenger command flow.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation | | :------------------------: | :------- | :--------------------------------------------------------------------------------------------------------- | | Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. | | Title check | ✅ Passed | The title clearly summarizes the main refactor: splitting lib.rs into modules. |✨ Finishing Touches
📝 Generate docstrings
- [ ] Create stacked PR - [ ] Commit on current branch🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests - [ ] Commit unit tests in branch `refactor/monolith-split`Comment
@coderabbitai helpto get the list of available commands.Originally posted by: kristofferR
@coderabbitai review
Originally posted by: coderabbitai[bot]
✅ Action performed
Review finished. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.Ticket changed by: kristofferR