Skip to content

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.

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 }
]
Terminal window
ap add panel settings --type modal
ap add panel worker --type invisible
ap add panel inspector --title "Inspector" --width 320 --height 480

This 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.current(); // { id: "main" } - also ctx.panel
AP.panels.open("settings"); // open another panel of this extension
AP.panels.close(); // close this panel
AP.panels.close("settings"); // ask another open panel to close itself
  • Ids are the ones in afterpresets.json. An invalid id throws.
  • open asks the app to open the extension <bundleId>.<id>. It returns true when the request was sent; it does not wait for the panel to load.
  • Data cannot be passed to open. Send it with AP.events once the other panel is ready (see “Handshake” below).

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 listening
AP.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.
  • data must 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”
src/panels/main/main.js
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);

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 license on needs its own renderLicense. A small modal can reuse the main panel’s license screen code from js/.
  • An invisible panel cannot show a license screen. Boot it with licensing on and a renderLicense that draws nothing; its start runs once the buyer has activated in a visible panel.

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.