theseus/bundled-addons/docx-editor
Local Dev 4cc2d53582 Theseus: start extensions on first use, Startup switches in Settings
Every enabled add-on used to be activated synchronously in initAddons(),
during app.whenReady and before the window exists. That is the largest
launch cost left (boot tracer, 2026-10-03). An add-on can now say
"activation": "on-demand" in addon.json. It is then listed at launch but
not started. Its declared surfaces stay live: "panels" (new: sidebar
panels declared up front), toolbar-menu, context-menu-items and the
page-inject bridge, whose source is read on the first matching page.
activate() runs on first real use: a panel opened, a menu or context
item picked, a message from its panel, tab or page bridge, a Settings
addon-invoke, a wiz:// link (for Aegis). All of those go through
AddonHost.dispatch(), which starts the add-on and waits for it, so no
call is dropped. Concurrent callers share one activation, and
activations run one at a time.

Startup stays the default: the host cannot tell what an older add-on
does in activate(). request-filter add-ons and add-ons that declare no
surface are forced to startup. If activate() returns a promise, calls
wait for it (at most 5 s). api.startAtLaunch(bool) lets an on-demand
add-on ask to be started at launch again (for live relay sessions).

Converted: notepad, screenshot, translate, docx-editor, pdf-editor, vpn
(none has launch-time work: no file association, no auto-connect, and
add-on file tabs are not part of the saved session). Shield and Cookie
Pop-ups stay startup: Shield owns the request filter and must see the
first request; Cookie Pop-ups costs ~6 ms and acts unasked on every
page. Aegis stays startup and untouched: another session owns it. See
NOTE-aegis-on-demand.md (next commit).

Settings › Performance › Startup:
- "Start extensions when first used" (default on). Off = all at launch;
  switching it off starts the waiting add-ons immediately.
- "Start the wallet at launch". Shown disabled with a hint until the
  installed Aegis manifest allows on-demand. It applies with no Settings
  change once Aegis opts in.
- "Preload common menus" gates prewarmOverlays().
- "Use lightest" preset.
New keys are plain SETTINGS_DEFAULTS through the existing settings-set.
No new IPC channels.

Measured: boot-trace, fresh profile, --seconds 20 so the 30 s add-on OTA
poll can't swap Aegis mid-series; warm runs 2-3 of two paired series.
- Add-on activation at launch: 121-154 ms -> 104-174 ms. The six
  converted add-ons went from 16-20 ms to 0. The rest is Shield (83-148
  ms, noisy) and Aegis (15 ms in this tree's 0.9.0).
- Toolbar painted: 1278-1584 ms -> 1282-1481 ms (within noise).
- With "Preload common menus" off: 0 overlays prewarmed, 8 processes
  instead of 11, about 50-70 MB less at 15 s.

The bundled add-on versions are not bumped. Existing profiles keep their
old addon.json, and so stay on startup activation, until those add-ons
ship with a higher version (seedBundledAddons only reseeds a strictly
newer bundle).
2026-10-03 16:05:32 +02:00
..
fonts feat(docx-editor): the page fills the window, and two fonts ship with it 2026-09-22 19:12:56 +02:00
lib feat(docx-editor): ship it in the build, updated over the first-party channel 2026-09-21 22:47:13 +02:00
vendor feat(docx-editor): ship it in the build, updated over the first-party channel 2026-09-21 22:47:13 +02:00
addon.json Theseus: start extensions on first use, Startup switches in Settings 2026-10-03 16:05:32 +02:00
editor.css feat(docx-editor): the page fills the window, and two fonts ship with it 2026-09-22 19:12:56 +02:00
editor.html feat(docx-editor): the page fills the window, and two fonts ship with it 2026-09-22 19:12:56 +02:00
editor.js feat(docx-editor): the page fills the window, and two fonts ship with it 2026-09-22 19:12:56 +02:00
fonts.css feat(docx-editor): the page fills the window, and two fonts ship with it 2026-09-22 19:12:56 +02:00
icon-16.png feat(docx-editor): the blue DOC badge, kept as the generated source 2026-09-22 00:10:56 +02:00
icon-32.png feat(docx-editor): the blue DOC badge, kept as the generated source 2026-09-22 00:10:56 +02:00
icon-48.png feat(docx-editor): the blue DOC badge, kept as the generated source 2026-09-22 00:10:56 +02:00
icon-128.png feat(docx-editor): the blue DOC badge, kept as the generated source 2026-09-22 00:10:56 +02:00
icon-256.png feat(docx-editor): the blue DOC badge, kept as the generated source 2026-09-22 00:10:56 +02:00
icon.svg feat(docx-editor): the blue DOC badge, kept as the generated source 2026-09-22 00:10:56 +02:00
index.js feat(docx-editor): the page fills the window, and two fonts ship with it 2026-09-22 19:12:56 +02:00
panel.html feat(docx-editor): ship it in the build, updated over the first-party channel 2026-09-21 22:47:13 +02:00
README.md feat(docx-editor): the page fills the window, and two fonts ship with it 2026-09-22 19:12:56 +02:00
ROUND-TRIP.md feat(docx-editor): ship it in the build, updated over the first-party channel 2026-09-21 22:47:13 +02:00

Word editor — a Theseus extension

Opens, edits and saves Word documents (.docx) in a full Theseus tab, and exports them as PDF.

Saving comes in three shapes. Save drops a copy in your downloads until the document has a home; Save as… opens a real file dialog where the extension you type — .docx or .pdf — decides the format, and from then on Save writes straight to that file; PDF is the one-click export. PDFs are rendered by Chromium's own print pipeline from lib/doc-css.js, the same stylesheet the editor displays, on the paper size the document itself specifies — so the export matches the preview rather than being a second opinion about it.

It is a first-party extension: written here, signed with the Silent Mode operator key, and updated over the channel at theseus.x/extensions/docx-editor/ like every other add-on Theseus ships. It does not go through the community catalogue, which is for extensions published by whoever owns a BNS name.

It ships inside Theseus, so a fresh install already has it and Settings lists it under Built into Theseus; the channel above then updates it between releases without waiting for one. That is the same arrangement as screenshot, aegis and pdf-editor, and it is what gives a user their first copy at all — Settings can only install from the community catalogue, so an extension that is neither bundled nor catalogued has a working update channel and no way in.

The cost is about 400 KB compressed in the installer, most of it the vendored editor libraries.

The page, and the fonts

The sheet is drawn at the size the document says it is — A4 stays A4, margins come from its own sectPr — and CSS zoom scales the whole thing to fit the window. Scaling rather than widening is the point: a page stretched to the window would break every line somewhere different from where the printed page breaks it. The footer carries the control, and Fit width is the default because a page marooned in the middle of a wide window wastes the screen. The choice is remembered per editor, not per document.

Ubuntu and Fraunces ship with the add-on, in fonts/, because Windows has neither and a font offered in the ribbon that the machine lacks is a font the user picks and then cannot see. Regenerate with npm run fonts; licences are in fonts/LICENSES.txt. They cost about 700 KB, most of it Ubuntu's Cyrillic and Greek coverage — dropping those subsets would roughly halve it.

Two wrinkles worth knowing. The editor is on file://, where Chromium registers @font-face rules but refuses to fetch the font files, so the add-on reads them and hands the page a stylesheet with the woff2 inlined as data URLs; the same inlined copy goes into the PDF export, whose print window runs from a temp folder where a relative url() would resolve to nothing. If either path fails the ribbon labels those two families "(not available)" rather than pretending.

The icon

icon.svg is the one drawing. npm run icons rasterises it to icon-16/32/48/128/256.png and writes a minified copy into addon.json's icon field, which is what the dock button and the catalogue card read — so there is never a second version to keep in step.

It is a blue document badge, paired with pdf-editor's red one so the two editors read as a set in the dock — a solid fill stays legible at the 16–18px the dock actually renders, which an outlined page does not.

Deliberately not Microsoft's Word icon: their mark is a blue sheet carrying a white W, and dressing our extension up as theirs would be both a legal problem and a dishonest one. A folded-corner page is the universal document glyph, and "DOC" is the file format rather than anyone's trademark.

Building

The vendored libraries (mammoth, ProseMirror, docx, JSZip) are bundled by a build step that lives outside this folder, because mammoth needs local patches before it can carry everything the editor edits:

cd ../../addon-build/docx-editor
npm install
npm run build        # writes vendor/docx-vendor.js here
npm run icons        # re-rasterises icon.svg after editing it

vendor/docx-vendor.js is committed, so the extension is installable straight from a checkout; re-run npm run build after touching anything under addon-build/.

Publishing

The full recipe is in docs/ADDON-UPDATES.md; the short version, signed with the operator key and always from a clean copy of the commit rather than the working tree:

git archive HEAD TheseusNavigator/extensions/docx-editor | tar -x -C <clean>
node scripts/sign-addon-update.mjs         <clean>/TheseusNavigator/extensions/docx-editor         https://navigate.st/bns/theseus.x/extensions/docx-editor         "$USERPROFILE/.silentmode/ops/addon-update-key.pem" --out out/

node ../Argus/src/lib/sia-upload.js out/docx-editor-<version>.tar.gz bns/theseus/extensions/docx-editor
node ../Argus/src/lib/sia-upload.js out/updates.json                 bns/theseus/extensions/docx-editor

The channel lives on Sia only — nothing goes to the VPS filesystem — and is served through the gateway at https://navigate.st/bns/theseus.x/extensions/. A first release has no updates.json to prepend to, so it ships one holding just its own entry. Versions must increase.

Testing

Three levels, all re-runnable, all from ../../addon-build/docx-editor:

node test/roundtrip.mjs                  # the built-in fixture
node test/corpus.mjs <folder of .docx>   # real documents
node ../../../scratchpad/verify-docx-editor/drive.mjs   # a real Theseus, over CDP

The last one installs this folder into a throwaway profile the way the community channel would, and is the only one that catches browser-only breakage.

What survives a round trip, and what doesn't, is written up in ROUND-TRIP.md. Read that before promising anyone a Word feature.