Skip to content

Embedders

An embedder is an app that shows HADAL’s web app inside itself: an Electron or Tauri wrapper on a computer, for example, or a phone app with a web view, with notifications, a badge, or a menu of its own. HADAL stays a web app on its server; the embedder loads the server’s address, and the person signs in there as in a browser.

A browser tab cannot do some things that such an app can, and Web Push does not reach a page in Electron. The app bridge joins the two: the embedder puts window.pocketHost in the page, and HADAL uses what it offers. HADAL knows nothing else about the embedder: not its name, not what kind of app it is, not what it runs on. In a browser there is no app bridge, and nothing changes.

GET /api/pocket/info answers without a sign-in:

{ "name": "hadal", "bridge": 1 }

bridge is the version of the app bridge that this server’s web app speaks. The answer never has HADAL’s version. A server older than the app bridge answers 401 there; its web app manifest (/manifest.webmanifest) still has "name": "HADAL".

The app bridge is experimental (since 0.28.0): it can change in a minor release (API stability). Before 0.28.0-beta.7 these docs were docs/desktop.md.

The embedder (in Electron, its preload script) puts one object in the top page of the server’s origin, and nowhere else: never in a frame (artifacts run in frames), never on another origin.

window.pocketHost = {
kind: "my-app", // which embedder; for logs only
apiVersion: 1,
capabilities: ["menu", "badge", "notify", "visibility", "pinned", "open"],
menuTitle(), // the heading of the embedder's group in the menu, such as its name; optional
menuItems(), // [{ id, label, hint? }]: the items of that group, at the menu's end
invoke(id), // one of them was chosen; false when it could not be done
setBadge(count), // sessions that need you, as the home-screen icon counts them
notify(message), // a notification for the embedder to show (below)
visible(), // whether the embedder's window shows: false while hidden in a tray or minimized
setPinned(list), // [{ id, title, state, label, url }]: the pinned sessions, in order
subscribe(listener), // the embedder's events (below)
};

web/host.js reads it: host, hostCan(capability), and callHost(name, …), which catches what the embedder throws. web/embedder.js does the rest. HADAL uses only the capabilities the embedder names, and ignores ones it does not know. A newer app bridge keeps version 1’s calls.

Capability What HADAL does
menu Shows menuItems() in a group of their own at the end of the menu, below its App part, under menuTitle() (up to 40 characters); without a title, the group has no heading. Choosing one calls invoke(id). HADAL GUI offers GUI Settings… under its name.
badge Calls setBadge(count) instead of the Badging API whenever the count changes.
notify Opens its event stream with embedder=notify. The server then sends this connection every notification it would push to the person (embedder-notify), and the page passes each to notify(message).
visibility Reads visible() with the page’s own visibility: the page counts as hidden while either says so. It tells the server (POST /api/visibility), so the server knows the person is away and lets notifications through, and seen marks and peek tiles wait as they do in a hidden tab.
pinned Calls setPinned(list) when a pinned session’s title or state changes, for a tray menu. state is the square’s shape from sessionMark: waiting, limited, working, failed, fresh (finished, not read), or seen. The session list’s theme states done and idle do not change these app bridge names. label says it in words.
open Opens what the embedder asks for (an open event), also without notify.

A page from before 0.28.0-beta.7, still open after the server updates, asks with host=notify and listens for desktop-notify: the server still sends it those, until the page reloads.

A page in an Electron window keeps running at full speed while the window hides in the tray, so document.visibilityState stays visible there. That is why visible() exists: without it, the server would think the person is looking, and hold every notification back.

The server decides as for Web Push (alerts.ts): who can see the session, the kinds each person turned on in Menu → Notifications, and whether they are looking at it. Then it sends the message through Web Push to their subscribed devices, and to each of their embedders’ connections (PocketApp.notifyEmbedders). An embedder that is not running gets nothing: nothing waits for it.

{
title: "HADAL needs approval · Deploy",
body: "bash: npm run deploy", // cut at 400 characters, as for Web Push
url: "/s/12", // what a click opens: a session, Lantern ("/?pip=1"), or "/"
tag: "approval-…", // one notification per tag: a newer one replaces it
urgency: "high", // "normal", or "high" for approvals and questions
approval: { // approvals only
id: "…",
allow: true, // Web Push's rule: the person may allow it, and the whole call fits on one short line
may: true, // the person may allow it at all
call: "bash: npm run deploy", // the whole call, never cut
},
}

The embedder chooses how much of an approval to show and whether to offer Allow, from may, allow, and call. It always offers Deny. The server checks again, when the answer comes, that the person may give it.

subscribe(listener) takes one function. The embedder calls it with:

  • { type: "visibility" }: its window was shown or hidden. The page reads visible() again.
  • { type: "open", url }: open this, such as a notification or a tray item that was clicked. Only addresses of the server’s own origin open.
  • { type: "approve", id, allow }: the person answered an approval in a notification. The page answers it with its own sign-in.

An embedder that hides its title bar, and shows HADAL up to its window’s top edge with the window’s own buttons over it (close, minimize, zoom), tells the page where they are through the web’s standard for it, the Window Controls Overlay (navigator.windowControlsOverlay). An installed web app with "display_override": ["window-controls-overlay"] does the same. The app bridge is not needed for it.

web/window-controls.js makes room only under the buttons, and only as much as they take; the rest of the layout keeps its whole height:

  • A bar under them (the session tabs, the conversation’s top bar, a panel’s, a viewer’s) keeps what it holds beside them, and the window can be dragged by it.
  • A window without one (the sidebar on wide screens, an extension’s page) starts below them. Tiled, its margin moves it, so the tiles’ gap stays above it.
  • A strip beside the buttons, as wide as the windows that moved down, moves the window too. What floats over the app (sheets, the launcher, viewers, Lantern) takes clicks there.
  • Tiled, the window whose bar is under the buttons has its corner cut around them (corner-shape), so its border and focus ring go down, around them, and back up, instead of under them. A browser without corner-shape keeps the rounded corner.

The page reads the layout, not the screen: a window, a bar, or a panel that opens (the subagents board, Design, Files, Browser, People) has its room and its cut before the frame that first shows it, and a window that pops in is measured where it lands. Nothing shows under the buttons first and moves after.

On <html>, data-window-controls is left (macOS), right (Windows, Linux), or none, and --controls-h is how far down the buttons reach. What makes room has data-under-controls, bar or push, and --controls-room. The window cut around the buttons has data-controls-notch, and --notch-w and --notch-h. The page sets data-window-controls before its first paint, so an embedder can tell that it makes its own room. For a page without it (an older HADAL, a sign-in page), HADAL GUI instead sets a top safe-area inset as tall as the buttons, which HADAL’s bars have long kept clear of on phones.

The app bridge is only as safe as the embedder that offers it. An embedder must:

  • put it only in the top frame of the server’s origin, and take it away when that frame goes elsewhere;
  • check, in its main process, the frame and origin of every call that comes from the page: the sender frame’s own origin (senderFrame.origin), not its url, because the server’s origin also serves sandboxed artifact pages, whose origin is opaque;
  • give the page no Node.js, and keep its sandbox and context isolation on.

HADAL gives the app bridge nothing that the page could not do over the API itself: the notifications are the person’s own, and an approval’s answer goes through the same route and checks as a tap in the page.

These pages describe HADAL 0.29.0. Your copy has the pages of its own version in its docs/ folder.