Documentation / LemmeKnow

Delivery Screen pages

A Delivery Screen is an HTML page that LemmeKnow shows full screen, over the lock screen, when a rule's Delivery step runs. This page is the reference for writing one: when it shows, what the page can load, the Lk object it talks to, and the theme and settings it receives.

You declare the screen in a plugin package's manifest (see Building plugin packages). The Backdrop package is a complete example: its screen.html reads the payload, params, and theme, and its texture.js draws any theme style's texture on a canvas the way the app does. You're welcome to copy texture.js into your own screens. The LemmeGetIt package has palette.js, which colors elements with the theme's palette the way the app animates its bars (see Palette colors).

Plugins can also add notification cards, pages drawn over a notification. They're built the same way and use the same sandbox, Lk object and theme as described here.

When a screen shows

A Delivery step shows its screen only when the phone is locked and its display is off. If the user is already looking at the phone, the step is skipped. The screen needs the Full-screen notifications permission; the Delivery step editor offers to grant it.

The screen fills the display with the system bars hidden. If the step has Show palette bars on, the app draws its palette bars at the top and bottom edges, around your page. With a Bar slide-in time set, your page fills the whole display and the bars slide in over its top and bottom edges, so keep important content clear of them. The page itself is transparent until you give it a background, so set one.

The screen closes when:

  • the user touches it anywhere (the page never receives the touch);
  • the phone is unlocked or its display turns off;
  • the page calls Lk.deliveryComplete() or Lk.deliveryDismissed().

Keeping the display on

With keepAwakeSeconds set in the manifest (0 to 30), the display stays on for that many seconds or until the screen closes, whichever comes first. When the hold ends on a locked phone, the display goes dark shortly afterwards with the screen still in place, as the lock screen would. Users can turn the hold off for a step with Keep the screen on. Without keepAwakeSeconds the normal display timeout applies.

The page's address

The page is loaded at:

https://delivery/<screen id>/

Relative URLs resolve against it, and the folder holding your entry HTML file is the root. So with the entry at delivery/backdrop/screen.html, the tag <script src="texture.js"> loads delivery/backdrop/texture.js. Subfolders work; files above the entry's folder can't be reached.

PathWhat it serves
<path>Your own files, from the entry's folder and below
_plugin/<file>A file your package declares under textures, fonts or sounds, at the path written in the manifest
_param/<key>The file the user picked for an image, sound or font param
_theme/<element>The image or GIF texture of that element's style in the step's theme, such as _theme/screen or _theme/card
_theme/window_top, _theme/window_bottomThe bar textures when the theme styles the two bars separately
_theme/fontThe theme's font file, when it uses one

You rarely need to build _param and _theme addresses yourself: Lk.params() and Lk.theme() hand them to you.

Audio files (from any of these paths) are only served when the screen declares "includesSound": true. The same flag lets audio and video start without a tap, which matters because a Delivery Screen never gets one.

The sandbox

An alert can carry another app's notification text, so the screen is sealed off from the network. It can't send anything anywhere.

AllowedSource
ScriptsYour files, inline <script>, and eval
StylesYour files and inline styles
Images, audio, videoYour files, data: and blob: URLs
FontsYour files and data: URLs
fetch and XMLHttpRequestYour files and the _plugin, _param and _theme paths

Everything else is refused:

  • Requests to any other address are answered locally with a 404. Nothing reaches the network, and DNS prefetching is off.
  • Navigating away from the page, opening windows and submitting forms do nothing.
  • WebRTC (RTCPeerConnection and friends) and navigator.mediaDevices are removed before your scripts run.
  • Workers, <object>, and <embed> are blocked.
  • Frames aren't available. A screen whose HTML contains iframe, frame, frameset, object, embed, portal, or fencedframe is not shown at all (its notification stays). Creating or inserting one from script throws a NotSupportedError, and any that still appear are removed.

console.log output goes to Android's system log (logcat), which is handy while developing.

The Lk object

The page gets a global Lk object. Its data methods return JSON as a string, so parse what you read:

function read(name) {
  try { return (window.Lk && Lk[name]) ? JSON.parse(Lk[name]() || '{}') : {}; }
  catch (e) { return {}; }
}
const payload = read('payload');
const params = read('params');
const theme = read('theme');
MethodReturns
Lk.payload()The alert, as a JSON string (below)
Lk.params()The step's values for your declared params, as a JSON string
Lk.theme()The step's theme, as a JSON string
Lk.notificationStyle()The relaying rule's notification style as a JSON string, or null (below)
Lk.capabilities()A JSON string listing optional features: {"notificationStyle":true}
Lk.deliveryComplete()Nothing. Closes the screen; call it when your presentation has finished.
Lk.deliveryDismissed()Nothing. Closes the screen; call it when the user has chosen to dismiss it in your page's own terms.

Both closing methods currently have the same effect. Use the one that describes what happened.

payload

{
  "title": "Front door",
  "message": "Motion detected at 21:04",
  "volume": 0.8,
  "stream": "notification",
  "icon": "https://delivery/my_screen/_payload/icon",
  "image": "https://delivery/my_screen/_payload/image"
}
FieldMeaning
titleThe rule's name. Can be an empty string.
messageThe alert's message, with tokens filled in.
volumeThe step's volume setting from 0 to 1 (1 when unset), for screens that set their own audio volume to match.
streamThe step's audio stream: notification, media, ringer, or alarm.
iconThe address of an icon for where the alert came from: the notifying app's icon, the server's icon, or the LemmeKnow icon. Use it as an image source.
imageThe address of the picture on the app's notification, such as a camera snapshot or a contact photo. Only there when the notification still shows one.

The install review's Play button runs your screen with the title LemmeKnow, the message This is a sample alert, volume 1, stream notification and the LemmeKnow icon, using your params' defaults and the user's current theme.

params

Lk.params() has one entry for every param you declared, whether or not its input is currently shown. Each value is the user's setting for the step, or your default when the user hasn't set one or the stored value isn't valid any more. Keys you didn't declare never appear.

TypeValue
text, tokensString, up to 4,000 characters. tokens arrive with the alert's tokens already filled in.
numberNumber, within hardMin and hardMax
toggletrue or false
choiceOne of your option values
colorCSS hex (#RRGGBB, or eight digits with alpha), or null. Theme colors arrive as hex.
image, sound, fontA URL your page can load (for a font, in an @font-face rule), or null

For image, sound, and font, a picked phone file, bundled texture, or plugin file arrives as its _param/<key> address. A default written as a path in your folder or as _plugin/<file> arrives exactly as written, which resolves against the page's address. A file the app can no longer read (a moved phone file, a removed plugin) falls back to your default.

When an image param is set to a theme style, its value is that style's _theme address (when the style has no image or GIF texture, your default applies instead, or null), and the extra key _styles maps the param's key to the style's element key:

{
  "image": "https://delivery/backdrop/_theme/screen",
  "fit": "style",
  "showTitle": true,
  "footer": "",
  "sound": null,
  "_styles": { "image": "screen" }
}

That lets a screen draw the style its own way, including text textures, which have no file. Backdrop does exactly this:

const styleKey = (params._styles || {}).image;
const themeStyle = styleKey ? LkTexture.style(theme, styleKey) : null;
if (themeStyle && LkTexture.hasTexture(themeStyle)) {
  LkTexture.draw(document.getElementById('bg'), themeStyle, theme);
}

theme

Lk.theme() returns the theme the step chose, or the user's current appearance when the step uses Current theme. Its shape is the theme format described in Building plugin packages, with these differences:

FieldIn Lk.theme()
colorsEvery color the app has, not just overrides, as CSS hex (#RRGGBB, or #RRGGBBAA when not opaque)
paletteColorsThe palette as it cycles on screen
paletteCycleMsHow long one pass through the palette takes at the user's animation speed
waveModeThe theme's wave mode, or absent for Pulse. Chaos arrives as pulse when the user has flash-safe mode on.
waveAngleThe Wave and Ping-pong direction in degrees: the theme's own, else the user's
waveSpreadThe user's wave spread in degrees, how much of the palette is visible across the screen at once
paletteBrightnessThe user's palette brightness, from 0 to 1, to multiply palette colors by
styles.<element>.textureContentFor image and GIF textures, a URL your page can load, or null when the file can't be read. Text textures keep their characters.
windowTopStyle, windowBotStyleSame treatment, when the bars are styled separately
fontFamilyA URL when the theme uses a font file; otherwise a family name, or absent

Element styles at their default may be left out, as are style fields at their default value. Fill in the defaults yourself (the table on the packages page lists them, and texture.js has them built in). Sizes are in dp; window.devicePixelRatio gives device pixels per dp.

Palette colors

palette.js defines LkPalette, which reads the palette fields above and colors elements to match the app: one steady color when the palette is static, or the palette animated in the theme's wave mode at the user's speed, angle, spread, and brightness. Your callback is called every frame with each element and its color. In the wave modes, an element's color depends on where it sits on screen. In chaos, each element drifts through the palette on its own.

const theme = JSON.parse(Lk.theme());
const painting = LkPalette.paint(document.querySelectorAll('.dot'), theme,
  (el, color) => { el.style.backgroundColor = color; });
// painting.stop() ends the animation.

LkPalette.colorer(theme) returns the underlying function of elapsed milliseconds, x and y (each 0 to 1 across the screen) and element, for screens that draw on a canvas.

CSS variables

The same theme is available to plain CSS. These variables are defined on :root before your page renders:

VariableValue
--lk-<color name>Every color, named in lowercase with dashes (--lk-accent, --lk-bg-app, --lk-bg-surface, --lk-text-primary, --lk-alert-accent), as #RRGGBB
--lk-texture-<element>Every image or GIF texture as url("..."), with underscores as dashes (--lk-texture-screen, --lk-texture-list-item, --lk-texture-window-top)
--lk-font-familyThe theme's font, when it sets one
html, body {
  margin: 0;
  height: 100%;
  background: var(--lk-bg-app, #000);
  color: var(--lk-text-primary, #fff);
  font-family: var(--lk-font-family, system-ui, sans-serif);
}
.window { border: 1px solid var(--lk-accent-border, #4fa3ff); }
#bg { background-image: var(--lk-texture-screen); }

Always give a fallback, since a texture variable only exists when the theme has that texture. The app draws nothing for you: texture settings such as tiling, size, opacity, and pan are in Lk.theme() for screens that want to follow them.

Notification style Coming soon

A notify rule in Relay mode can set its OS style to Nest, Overlap or Card and pick the current theme, a specific one, or a saved playlist for its notification (an Override rule's style counts the same way). When it does, Lk.notificationStyle() returns that theme's OS notification look; with a playlist, it's the theme picked for that notification, so a screen can draw part of itself, such as a message box, to match the notification. It returns null when the rule has no theme style, when the step belongs to an alert or nudge rule, and on older app versions that don't have the method (check Lk.notificationStyle exists before calling it).

FieldMeaning
id, nameThe theme
colorsEvery color key as #RRGGBB, like Lk.theme()
notification.background, .title, .text, .borderCard fill, title, body text and border colors
notification.borderWidth, .cornerRadius, .paddingFrame sizes in dp
notification.showTitle, .titleSize, .titleBold, .textSize, .textAlignText settings (textAlign is start, center or end)
notification.imageAnchor, .imageSize, .imageCorner, .imageAlign, .gapThe decoration column (imageAnchor is none, left, right or random)
notification.texture or .textureTextThe card texture's address or tile text, when it has one
notification.textureOpacity, .textureColor, .textureColorModeHow to draw that texture (mask, tint or none)

Your screen keeps the step's theme either way. Make using the style a choice in your params, so the user decides, and fall back to your normal look when it's null.

Sound

To play audio, set "includesSound": true and point an <audio> element at your own file, a _plugin/ sound, or a sound param:

if (params.sound) {
  const audio = document.getElementById('sound');
  audio.src = params.sound;
  audio.volume = Math.max(0, Math.min(1, payload.volume ?? 1));
  audio.play().catch(e => console.log('sound: ' + e));
}

With includesSound on, the Delivery step shows volume and stream controls, and their values arrive in the payload.

Checklist

  • Declare the screen in deliveryScreens with id, entry, every file in assets, and includesSound if it plays audio.
  • Keep every file inside the entry's folder, or declare it as package content and load it through _plugin/.
  • Set a background; the page starts transparent.
  • Don't wait for a touch: any touch closes the screen.
  • Call Lk.deliveryComplete() when you're done if the screen shouldn't stay up.
  • Install the package and press Play in the review dialog to try it.