Skip to content

Launch Options ​

When the app launches content, it provides the read-only DesktopEngine.launchOptions before index.js runs:

js
const options = DesktopEngine.launchOptions || {};
options.windowType;   // the only window type it can make, for new DesktopEngine.Window({ type }): 'widget' (on the desktop) or 'overlay' (above windows); 'desktop' for a wallpaper
options.size;         // the id of the widget size picked: 'small', 'medium', 'large' or one of its own
options.width;        // the widget's width in points: the size picked, or the one it was left in when it can be resized
options.height;
options.position;     // { x, y }: where the user last dragged it; a widget without one gets a default, a companion picks its own
options.display;      // { id, name, frame, visibleFrame, scale }
options.displays;     // the displays instead, when a wallpaper spans them, see Wallpapers
options.parameters;   // the values of the options
options.locale;       // the user's preferred language, e.g. 'en-US'
options.permissions;  // the permissions it runs with, e.g. ['audio', 'network']; denied ones aren't there

Coordinates are the ones of DesktopEngine.Window styles: the origin at the top left of the main display, y pointing down. See LaunchOptions for all the fields.

When options change ​

When the user changes an option, the app restarts the content with the new values. Listen to parameterschange of DesktopEngine.system and it keeps running instead: apply the new values yourself, keeping everything else as it is, such as the time left on a timer or where a companion is walking.

js
const system = DesktopEngine.system;
let accent = DesktopEngine.launchOptions.parameters?.accent ?? '#0A84FF';
system.onparameterschange = (event) => {
  accent = event.parameters.accent ?? '#0A84FF';
  draw();
};
  • Set the listener when the content starts: the app looks for one each time the user changes an option.
  • event.parameters has every value, event.changed the keys that changed; DesktopEngine.launchOptions.parameters has the new values too.
  • Dragging a slider fires it several times a second: redraw right away, but leave heavy work, such as rebuilding a scene, until the values stop changing.

Talking to the app ​

js
win.onmove = (payload) => postMessage('host', { type: 'move', x: payload.x, y: payload.y });
postMessage('host', { type: 'close' }); // removes itself from the desktop

The app remembers the position move reports and passes it back in options.position next time, also when the user removes the content and adds it again on the same display.

Appearance ​

DesktopEngine.system.appearance is the system's current appearance, 'light' or 'dark'. appearancechange fires when the user switches it in System Settings (or Auto switches it by the time of day):

js
const system = DesktopEngine.system;
let dark = system.appearance === 'dark';
system.onappearancechange = (event) => {
  dark = event.appearance === 'dark';
  draw();
};

An Appearance option should offer auto (following the system) as its default, see the widget and wallpaper templates. Wallpapers draw every frame anyway: read appearance each frame and fade to its colors, no event needed.

The SDK is released under the Apache License 2.0