Skip to content

App UIs ​

Apps can add their own pages to the n5i dashboard, for example a status page for a node or a settings screen. The page is served by the app itself and shown inside the dashboard, so it feels like a part of it.

The dashboard and the app UI talk to each other with the app bridge protocol: the dashboard passes its theme, colour mode, language and a login token to the app, and the app can update the dashboard's breadcrumb, URL and notifications.

There are two ways to build an app UI:

  • With @n5i/ui, a Nuxt layer with Nuxt UI, n5i's design tokens and components, and a useHost() composable that handles the protocol for you. This is the recommended way.
  • With @n5i/app-bridge directly, a small dependency-free library for any framework or plain JavaScript.

An app adds pages to the dashboard's sidebar with ui_module in its metadata.yml:

yaml
version: 2

metadata:
  ui_module:
    menu_entries:
      - name: Overview
        icon: i-heroicons-home
        path: /
      - name:
          en: Peers
          de: Peers
        icon: i-heroicons-users
        path: /peers
FieldDescription
nameLabel in the sidebar. Translatable.
iconIcon name in the form i-<collection>-<icon>, for example i-heroicons-users.
pathPath inside the app that the entry opens.

An app with one entry is shown in the sidebar with its name and app icon. An app with several entries gets a group with one item per entry.

How embedding works ​

A menu entry opens the dashboard page /plugin/<app id>/<path>. On this page, the dashboard loads https://<app domain><path> in an iframe, where <app domain> is the first domain the user added to the app. The app UI is therefore served by the app's own web server, like the rest of the app, and an app needs a domain for its UI to show up. Without one, the dashboard shows an error instead.

text
Dashboard  https://dashboard.example.com/plugin/my-app/peers?tab=2
  └─ iframe https://my-app.example.com/peers?tab=2

The iframe is sandboxed with:

text
allow-forms allow-scripts allow-same-origin allow-popups allow-downloads
allow-modals allow-popups-to-escape-sandbox

So the app can run scripts, submit forms, open pop-ups and dialogs and download files, but it can't navigate the dashboard's window. The app UI must allow being framed by the dashboard: don't send X-Frame-Options: DENY or a Content-Security-Policy with a frame-ancestors directive that excludes the dashboard.

Messages between the dashboard and the app are only accepted from the iframe's window and the app's origin, and only sent to that origin.

Presentation ​

The dashboard shows app UIs as pages: the iframe takes the full content width and is transparent, so the app draws its content directly on the dashboard's background, using the dashboard's theme tokens and colour scheme. Render a page header and cards like a dashboard page does, not a full-screen card of your own.

Apps that use the app bridge say hello when they start. Apps that don't (for example, an app's regular web interface) are treated as legacy apps: if no hello arrives within 1 second after the iframe's load event, the dashboard draws a card around the iframe, so the app's own background doesn't clash with the dashboard. If a hello arrives later, the card is removed again.

The dashboard keeps its URL in sync with the app:

  • When the app navigates by itself (for example with client-side routing), it reports the new path with syncPath. The dashboard updates its address bar without reloading the iframe, so reloads and shared links open the same page.
  • When the app asks the dashboard to open another of its paths with navigate, the dashboard changes its URL and reloads the iframe.
  • openHostPage opens one of the dashboard's own pages by name. The dashboard currently offers app (the app's page in the app store), logs (the app's logs) and storage.

Next steps ​

Free and open-source software under the GNU AGPL 3.0 or later.