ledgeline_shell/lib.rs
1//! The shell Ledgeline's apps share: everything between "a router of API
2//! routes plus a built SPA" and "a hardened local server in a desktop window".
3//!
4//! - [`security`] — the per-process bearer token, the `Host` guard, the
5//! exact-origin CORS allowlist and the security headers (CSP included), plus
6//! [`security::harden`] / [`security::protect`], which put them on a router.
7//! - [`spa`] — serving an app's `RustEmbed`-ed SPA same-origin, with the
8//! embedded-mode marker injected and a per-response CSP.
9//! - [`app_dirs`] — where an app keeps its own state ([`AppDirs`]).
10//! - [`recents`] — the recently-opened store, shared by every app.
11//! - [`gui`] (the `gui` feature) — the desktop boot pieces: the in-process
12//! server on an ephemeral port, the window, the standard menus, the wry
13//! webview with its navigation policy, and the platform glue.
14//!
15//! The UI-preferences data model lives one layer down, in
16//! [`ledgeline_core::ui_prefs`], because it is data, not runtime.
17//!
18//! Nothing here knows which app it is serving: an app describes itself once
19//! with an [`AppIdentity`] and hands it to the pieces that need a name.
20
21pub mod app_dirs;
22#[cfg(feature = "gui")]
23pub mod gui;
24pub mod recents;
25pub mod security;
26pub mod spa;
27
28pub use app_dirs::AppDirs;
29
30/// Who the shell is serving: the names an app shows, logs under and hands to
31/// its SPA.
32///
33/// The SPA reads the two globals at startup, so they are part of the app's
34/// contract with its own web build and must never change for an app that has
35/// shipped (Ledgeline's are `__LEDGELINE_TOKEN__` and
36/// `__LEDGELINE_EMBEDDED__`). The shell embeds them in scripts after checking
37/// nothing, so they must be plain JavaScript identifiers.
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub struct AppIdentity {
40 /// The product name: the window title, the macOS app menu, About.
41 pub name: &'static str,
42 /// The macOS bundle identifier (`CFBundleIdentifier`).
43 pub bundle_id: &'static str,
44 /// The prefix of every line the shell writes to stderr (`ledgeline: …`).
45 pub log_prefix: &'static str,
46 /// The environment variable a caller-chosen access token is read from.
47 pub token_env: &'static str,
48 /// The `window` global the access token is handed to the SPA in.
49 pub token_global: &'static str,
50 /// The `window` global that tells the SPA it is served embedded.
51 pub embedded_global: &'static str,
52 /// The path the app's SPA is served under, with a leading and a trailing
53 /// slash: `/` when the SPA is the whole origin (Ledgeline), `/app/` when
54 /// other content shares it (the invoicer, beside MBR's pages).
55 ///
56 /// The desktop window shows only documents under it
57 /// ([`gui::build_webview`]), and only they are handed the token
58 /// ([`security::token_init_script`]). [`security::in_spa`] is the test.
59 pub spa_base: &'static str,
60 /// The sources of a `frame-src` directive added to the SPA shell's CSP
61 /// ([`security::shell_csp`]), or `None` for none: then `default-src
62 /// 'self'` governs the shell's frames, as it does for Ledgeline, which
63 /// frames nothing.
64 ///
65 /// The invoicer's note and invoice frames need `https:` here: WebKit
66 /// checks a frame's navigation against the parent's `frame-src` before
67 /// the desktop window's navigation handler sees it, so without it an
68 /// https link clicked in a frame dies silently instead of reaching
69 /// [`gui::build_webview`]'s handler, which keeps the frame on our origin
70 /// and opens the link in the browser. (`mailto:` does not belong here:
71 /// WebKit refuses it from a sandboxed frame whatever the CSP says, so it
72 /// goes through [`security::HANDOFF_PATH`].) A static source list, with
73 /// no `;`.
74 pub spa_frame_src: Option<&'static str>,
75}