//! BetterDiscord-style extensions for the site page: `*.plugin.js` files and custom CSS. //! //! Plugins are trusted by the owner who installs them: by copying files into the folder, or through //! the app's install screen (dropped file, `waybetter://install` link, store), which shows the name, //! author, version, source, sha256, permissions and the code before anything is written (see //! [`validate_plugin`] and [`PluginStore::install`]). They run in the site page with full page //! access. Native code only reads files from its own plugins directory, never from a caller-supplied //! path, and the scripts it builds embed plugin data as JSON string literals. //! //! A header may declare `@permissions` (see [`PERMISSIONS`]). The page runtime then hands the //! plugin an API view that throws on undeclared members (`withPlugin`, runtime `permissions.ts`). //! That is a declaration plus a guard rail, not a sandbox: page JavaScript can always reach around //! it. A plugin without the line is "legacy" (full API, labelled so in the app). pub mod commands; pub mod migrate; use serde::Serialize; use sha2::{Digest, Sha256}; use std::collections::{BTreeMap, BTreeSet}; use std::fs; use std::path::{Path, PathBuf}; pub const PLUGIN_SUFFIX: &str = ".plugin.js"; pub const MAX_PLUGIN_BYTES: u64 = 2 * 1024 * 1024; pub const MAX_CSS_BYTES: usize = 512 * 1024; const STATE_FILE: &str = "enabled.json"; const CSS_FILE: &str = "custom.css"; /// Which first-party plugin content was last written, so upgrades never overwrite user edits. const BUNDLED_FILE: &str = "bundled.json"; /// What the plugin host needs from the app: where plugins run and what ships with it. #[derive(Clone, Copy, Debug)] pub struct PluginHost { /// The page runtime's window global; plugins register under `window..plugins`. pub runtime_global: &'static str, /// Scripts run only in the top frame of this exact origin, e.g. `https://x.com`. pub origin: &'static str, /// Console prefix, e.g. `wayBetter for X`. pub product: &'static str, /// Element id of the custom CSS `