Panels and events
Build extensions with several panels, modals, or invisible panels; open and close them with AP.panels; send data between them with AP.events.
One extension can have several windows. Each is a panel with its own id,
HTML, and JavaScript. They share js/, css/, jsx/, and the license.
Panel types
Section titled “Panel types”type |
What it is | Use it for |
|---|---|---|
panel |
A dockable panel, listed in Window → Extensions when menu is true |
The main UI |
modal |
A dialog that blocks the app until closed | Settings, confirmations, one-off forms |
invisible |
No window; starts with the app and runs in the background | Listening for events, background work |
Panels are declared in afterpresets.json:
"panels": [ { "id": "main", "title": "Tool", "type": "panel", "width": 400, "height": 580, "menu": true }, { "id": "settings", "title": "Tool Settings", "type": "modal", "width": 360, "height": 300 }]Adding a panel
Section titled “Adding a panel”ap add panel settings --type modalap add panel worker --type invisibleap add panel inspector --title "Inspector" --width 320 --height 480This creates src/panels/<id>/index.html and src/panels/<id>/main.js, and
adds the entry to afterpresets.json. Each panel calls AP.boot in its own
main.js and imports the screens and helpers it uses from src/app/
and src/shared/. After adding a panel, restart
ap dev and then the app: CEP reads the manifest only at launch.
AP.panels
Section titled “AP.panels”AP.panels.current(); // { id: "main" } - also ctx.panelAP.panels.open("settings"); // open another panel of this extensionAP.panels.close(); // close this panelAP.panels.close("settings"); // ask another open panel to close itself- Ids are the ones in
afterpresets.json. An invalid id throws. openasks the app to open the extension<bundleId>.<id>. It returnstruewhen the request was sent; it does not wait for the panel to load.- Data cannot be passed to
open. Send it withAP.eventsonce the other panel is ready (see “Handshake” below).
AP.events
Section titled “AP.events”AP.events sends JSON messages between the open panels of this extension.
var off = AP.events.on("preset:selected", function (data, meta) { // data: the JSON value that was sent. meta.from: the sender's panel id. showPreset(data.name);});
AP.events.emit("preset:selected", { name: "Bounce" }); // returns true if sent
off(); // stop listeningAP.events.off("preset:selected", handler); // same, by function- Delivered to every other open panel that listens to that name. The sending panel does not receive its own event.
datamust be JSON-serialisable (objects, arrays, strings, numbers, booleans,null). Delivery is asynchronous.- Names use letters, digits, and
_ . : -(up to 100 characters). Names starting with__ap.are reserved and throw. - A panel that is not open receives nothing; events are not queued.
Handshake: send data to a panel you just opened
Section titled “Handshake: send data to a panel you just opened”AP.events.on("settings:ready", function () { AP.events.emit("settings:load", { fps: 24 });});AP.panels.open("settings");
// src/panels/settings/main.js (inside start)AP.events.on("settings:load", function (data) { renderForm(data); });AP.events.emit("settings:ready", null);Shared license
Section titled “Shared license”All panels of an extension share one saved license. The buyer activates once.
- When a panel opens, it validates the saved key; it does not ask again.
- When the buyer activates or signs out in one panel, every other open panel updates itself automatically.
- Every panel that boots with
licenseon needs its ownrenderLicense. A small modal can reuse the main panel’s license screen code fromjs/. - An
invisiblepanel cannot show a license screen. Boot it with licensing on and arenderLicensethat draws nothing; itsstartruns once the buyer has activated in a visible panel.
Updates with several panels
Section titled “Updates with several panels”Every panel with updates.check: "auto" checks for updates. Only one install
runs at a time, and onInstalled fires in every open panel. AP.updates.reload()
reloads every open panel of the extension, so one Reload now click starts
the new version everywhere. To keep it simple, show the update screen in the
main panel and use updates: { check: "manual" } in the others.