Skip to content

Licensing

Turn licensing on, handle every license status in renderLicense, choose offline grace, test with AP.__simulate, and follow the license screen standards.

The runtime owns license logic: browser sign-in, the saved license, online checks, device limits, and when your app may start. Your code only draws the license screen.

  • Paid extension: required. ap check and ap push fail when a paid product has no panel that boots with license on.
  • Free extension: optional. With licensing on, buyers must claim the free product on AfterPresets and sign in. Leave it off unless the user wants that.
license: false // default: no license screen, start runs at once
license: true // on, no offline grace
license: { offlineGraceDays: 7 } // on, works offline for up to 7 days
license: { checkInBackground: false } // on, always wait for the online check (see below)

Buyers sign in with their AfterPresets account: the extension opens the browser, the buyer clicks Sign in on afterpresets.com, and the extension unlocks. The extension receives a license token that only works for this extension on this computer; it never sees the buyer’s account credentials. Each panel of an extension shares one license: the buyer signs in once.

After a successful online check the API returns a signed record of it, valid for 12 hours, and the runtime saves it with the token. Until it runs out, launching the app, reloading a panel (including ap dev reloads) or opening another panel unlocks straight away, with no network call and no checking screen. After 12 hours the license is checked online again, without blocking the buyer:

  • A panel that is already open re-checks in the background. It stays unlocked while offline and locks only if the server rejects the license (for example a refund).
  • The next launch, with checkInBackground on (the default), opens the app straight away and checks online behind it. If the server rejects the license, the license screen appears over the app with the matching status (signed_out, refunded, not_owned). If the buyer is offline, the normal offline grace rules apply: offline_grace within grace, otherwise offline_expired. Blocking the network therefore never keeps an extension unlocked.
  • With checkInBackground: false the launch shows checking until the API answers. Use it only if the app must not run at all before the check.

Only a record signed for this extension, computer and saved sign-in counts. With no saved license, or one that is not signed (for example copied from another computer), the launch always shows checking. Try again (api.retry()) also always shows checking. The record is signed by AfterPresets, so editing the saved file does not extend it.

offlineGraceDays is a whole number from 0 to 30. The default is 0. Values outside the range are clamped, with a console warning.

Setting Buyer launches the extension while offline
0 (default) Status offline_expired. The app does not start until the license is checked online.
1-30 If the last signed online check was less than that many days ago, status offline_grace: the app starts and the screen should show a small warning. Otherwise offline_expired.

Tradeoff: grace lets buyers work on planes and in studios with no internet, but a refunded license keeps working offline for up to that many days. Ask the user; 7 days is a common choice. Never set it without telling them.

AP.boot({
start: function (ctx) { /* your app */ },
license: true,
renderLicense: function (api, root) {
// Clear root, then draw api.state.status into it.
}
});
  • renderLicense(api, root) is called at boot and again after every state change. Treat it as a pure render: empty root, then draw api.state.

  • root is <div id="ap-license-root">, appended to <body> by the runtime. The runtime only sets root.style.display ("none" while active, "" otherwise) and the attribute data-ap-status="<status>". It has no classes and no styles. Your CSS positions it: usually a full-panel overlay, and a thin bar for offline_grace:

    #ap-license-root { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1000; background: #1d1d1d; }
    #ap-license-root[data-ap-status="offline_grace"] { bottom: auto; }
  • Do not move, remove, or set display on root. Draw only inside it.

  • If renderLicense throws, the runtime logs the error and keeps going.

api is the same object as AP.license and ctx.license.

Member Use
api.state { status, message, graceDaysLeft, productUrl, manageDevicesUrl, signIn, account }
api.signIn(cb?) Start a browser sign-in. The runtime opens the sign-in page and waits for approval. cb(state) once it started.
api.openSignInPage() Open the sign-in page again (while signing_in).
api.cancelSignIn() Stop waiting. Status becomes signed_out.
api.retry(cb?) Check the saved license online again.
api.signOut(cb?) Sign this computer out (all panels) and free its device slot. Status becomes signed_out.
api.openUrl(url) Open an http(s) URL in the default browser.
api.onChange(fn) fn(state) after each change. Returns an unsubscribe function.

state.message is a ready-to-show sentence (sometimes from the server). state.productUrl is the product page where buyers get the extension. state.manageDevicesUrl is where buyers remove old computers. state.signIn is { url } (the sign-in page) while signing_in, otherwise null. There is no code to show: the buyer only approves in the browser. state.account is { username } once signed in, otherwise null.

start runs only for active and offline_grace. Every other status blocks the app, so the screen must explain what to do.

Status What the screen shows Controls and the api call
disabled Nothing. Licensing is off; renderLicense is never called. None
signed_out Ask the buyer to sign in (state.message says why after a sign-out) Sign in with AfterPresets → api.signIn(); Get it → api.openUrl(state.productUrl)
signing_in “Finish signing in in your browser” (state.message) Open browser again → api.openSignInPage(); Cancel → api.cancelSignIn()
checking Progress text (state.message) Disable buttons
active Nothing (root is hidden). Clear root. None
not_owned state.message: this account does not own the extension Get it → api.openUrl(state.productUrl); Try again → api.retry(); Use a different account → api.signOut()
refunded state.message: the purchase was refunded Get it; Use a different account → api.signOut()
offline_grace One short non-blocking line with state.graceDaysLeft (the app is running) Retry → api.retry()
offline_expired Ask the buyer to connect to the internet Try again → api.retry(); Use a different account → api.signOut()
error state.message Try again → api.retry(); Sign in → api.signIn()

Too many computers is handled on the website during sign-in: the buyer removes an old computer under Manage devices there, then confirms again. Show Manage devices → api.openUrl(state.manageDevicesUrl) on the signed-in screens of your app (for example in settings) so buyers can find it.

The labels Sign in with AfterPresets and Get it are required wording. ap check warns when your license screen code does not mention a status.

Keep the markup in HTML, one block per status, and let the JS pick the block and fill in text. This is how the starter’s src/system/license-screen/ works (it uses the small helpers in src/shared/lib/view.js).

<!-- src/system/license-screen/license-screen.html (shortened) -->
<div data-state="signed_out">
<h1 id="license-title-signed_out">Sign in to unlock</h1>
<p data-field="message"></p>
<button type="button" data-action="signIn">Sign in with AfterPresets</button>
<button type="button" data-action="getIt">Get it</button>
</div>
<div data-state="signing_in">
<h1 id="license-title-signing_in">Continue in your browser</h1>
<p data-field="message"></p>
<button type="button" data-action="openSignInPage">Open browser again</button>
<button type="button" data-action="cancelSignIn">Cancel</button>
</div>
<!-- ...one block for checking, not_owned, refunded, offline_expired, error,
and a small banner for offline_grace -->
// src/system/license-screen/license-screen.js (shortened)
import markup from "./license-screen.html";
import { mount, isMounted, showState, fill, onAction } from "../../shared/lib/view.js";
export function renderLicense(api, root) {
if (!isMounted(root)) {
mount(root, markup); // the project's own HTML file, never outside data
onAction(root, {
signIn: function () { api.signIn(); },
openSignInPage: function () { api.openSignInPage(); },
cancelSignIn: function () { api.cancelSignIn(); },
retry: function () { api.retry(); },
signOut: function () { api.signOut(); },
getIt: function () { api.openUrl(api.state.productUrl); }
});
}
var s = api.state;
showState(root, s.status); // "active" matches no block: nothing shows
fill(root, { message: s.message }); // textContent
}
  1. Never call start yourself and never show app UI from renderLicense.
  2. Never read, log, or send the saved license file or token. The runtime keeps the only copy and sends it only to AfterPresets.
  3. Never ask the buyer for a password or key. Sign-in always happens in the browser through api.signIn().
  4. Never call the AfterPresets API directly for licensing. Use api.*.
  5. Open links only with api.openUrl(url), using the URLs in api.state. Do not hard-code them.
  6. Handle every status in the table.
  7. Do not style or hide #ap-license-root so the app is usable while blocked.
  8. Insert text with textContent (fill), never innerHTML: state.message can come from the server. innerHTML is only for your own .html files.

Accessibility

  • Use real <button> elements.
  • Put state.message in an element with role="status" (role="alert" for error statuses) so screen readers announce changes.
  • Give the blocking screen a heading. Move focus to the main button.
  • While signing_in, say plainly that the next step happens in the browser, and keep Open browser again visible in case the tab was closed.
  • Keep a visible focus outline and text contrast of at least 4.5:1.
  • Fit a 300 px wide panel with no horizontal scroll.

CEP browser limits (Chromium 74 in CEP 10)

  • No CSS gap on flex layouts (it is ignored). Use margins: .row > * + * { margin-left: 8px; }. Grid gap is fine.
  • No :has(), :is(), :where(), aspect-ratio, inset, container queries, or ?. / ?? in JavaScript.
  • Links: <a href> does not open the browser in CEP. Use buttons that call api.openUrl(url).

Style

  • Match the rest of the extension. Prefix classes with your own namespace (for example license__); the runtime uses none.

AP.__simulate works only in dev builds (ap dev) and only when licensing is on. It drives renderLicense through a status without touching the saved license and never calls start. While it is on, real license results do not change the screen. Run it in the live panel’s console or through the debugging connection.

AP.__simulate(); // lists every status
AP.__simulate("signing_in"); // shows code ABCD-EFGH
AP.__simulate("offline_grace", { graceDaysLeft: 1 });
AP.__simulate("error", { message: "Custom message" });
AP.__simulate(false); // end; validate for real

Before you finish, simulate every status, screenshot each one, and check that:

  • the required controls are present and the links open the right pages;
  • offline_grace leaves the app usable;
  • every other status except active covers the app;
  • ap check reports no missing statuses.