# System Design – Flows ## 1. Start-up 1. Thunderbird loads the background script (`lib/settings.js`, `lib/marker.js`, `background.js`). 2. `ensureComposeScript()` registers the compose script with the ID `inline-comment-compose` unless it is already registered. Files and order are listed in `COMPOSE_SCRIPT_FILES` (`lib/settings.js`). It runs when the background script loads, on `runtime.onStartup` and on `runtime.onInstalled`. 3. On install or update (`runtime.onInstalled`), `injectIntoOpenComposeTabs()` also loads the script into compose windows that are already open (registered scripts only apply to new windows). On first install the options page opens. ## 2. A compose window opens 1. The compose script sends `ic:getConfig`. 2. The background script reads `compose.getComposeDetails(tabId)` (identity, plain text), the identity (`identities.get`), the settings (`resolveSettings`) and the stored on/off state. Without a stored state, `enabledByDefault` of the identity's settings applies. 3. Reply: `{ active, isPlainText, settings, identity: {name, email} }`. The button badge shows the state (see [section 4](#4-onoff-and-changes)). ## 3. Key press inside a quote ```text keydown while active (printable character, no Ctrl/Alt/Cmd shortcut, AltGr allowed) └─ caret inside a mail quote (blockquote type=cite / _moz_quote)? or (HTML only) in the gap between two quote parts? no → do nothing, the editor types as usual yes → preventDefault + stopPropagation, startComment(character) ├─ selection not empty → execCommand("delete") ├─ inside a quote: │ splitMode "native": execCommand("insertParagraph") │ caret now outside every quote? → insertComment │ otherwise → execCommand("undo") + manual split │ splitMode "manual": manual split (splitCiteAtRange) ├─ in the gap: insertComment └─ neither (e.g. the deletion removed the quote) → execCommand("insertText") insertComment ├─ HTML: node = createCommentNode(document, marker, "a", settings, ID) (DOM APIs only) │