Skip to Content
Documentation

Pages, panels and status

Interface Songstress draws for you, from a tree of its own components, in the places it gives your extension.

Your extension's interface fits Songstress because Songstress draws it. You say what you mean (a page, a list, a tree, a choice to make, a notice, a status in the player) as JSON, and each app draws it with its own controls: the web and desktop apps in their design, the phones natively. What happens on a tap is JSON too: an action, which the app carries out. An extension never sets a colour, never reaches the app's own screens, and never shows anything without its mark.

Places

PlaceDeclared inWeb and desktopPhonesDrawn from
A pagepagesThe main area, and an entry in the sidebar with sidebarA page of its own, and an entry in the Library tab's "Extensions" group with sidebarIts renderer's screen
A sheetA navigate action with present: "sheet"A page over the screen it came fromA sheetThe page's renderer
A panelpanelsA section of Songstress's own screen, at its locationThe sameIts renderer's blocks
A status itemstatusThe player barThe full playerIts renderer's status
A menu itemmenusThe menu at its locationOne "Extensions" submenu in that menuA declared command
The settings pagesettingsThe extension's own pageThe extension's own page in SettingsThe manifest
A noticeA notify action, songstress.ui.notifyOver the app, until it is closedThe sameThe notice
A viewviewsA browser tab (web), the system's browser (desktop)The in-app browserYour own HTML

A renderer is a function your entry registers under the declared id, in the entry the manifest names in render: songstress.ui.pages.register(id, render), songstress.ui.panels.register(id, render) or songstress.ui.status.register(id, render). It is told who is looking, in which app (client), and what the screen shows. What the server entry renders shows in every app. A page's renderer is told:

Prop

Type

Pages

A page is a screen of its own, opened by an action, or from the apps' navigation when it sets sidebar. Up to 20. when holds back its navigation entry, never the page.

Prop

Type

src/server.ts
import { songstress } from 'songstress/server'

songstress.ui.pages.register('recent', async (context) => {
  const sent = (await songstress.storage.get<string[]>('sent', { userId: context.userId })) ?? []
  return {
    type: 'list',
    sections: [{ title: 'Sent today', items: sent.map((songId) => ({ type: 'song' as const, songId })) }],
    empty: { title: 'Nothing sent yet', text: 'Play something, and it shows here.', icon: 'music' },
  }
})

A page answers one of five screens:

typeWhat it is
listSections of rows, with an optional search field, an empty state and more rows on demand (nextCursor)
gridSections of cards, with the same
treeNodes that hold nodes: folders, groups, anything that holds more of itself; with an optional search field and an empty state
detailBlocks, read from top to bottom
formSections of fields and one button that hands them to a command

Rows and cards. row and card are your own: a title, a subtitle, an icon or an image, an action on a tap, a menu. song, album, artist and playlist are Songstress's own, named by library id and drawn exactly as Songstress draws them elsewhere, with their own menus.

Trees. A tree holds nodes: each your own node or a library song. A node holds what's under it as children, given now, or expandable, which says it has some: when the person opens it, the page is rendered again with the node's id in context.node, and your answer's nodes are what's under it. The web and desktop apps open a node in place (open opens it at first); the phones open a node that holds others as a page of its own.

Blocks, what a detail screen, a section and a panel are built from: stack, section, text, icon, image, badge, progress, banner, divider, spacer, collapsible, button, menu, shelf, and the four library types.

Fields, what a form holds: text-field, switch, checkbox, slider, picker, date-picker. The app keeps what's typed until the form is submitted; the command then gets the values by field name in context.values.

Every component's exact shape is in the API reference.

Panels

A panel is a section inside one of Songstress's own screens. Up to 10.

Prop

Type

locationWhere it is drawnIts renderer is told
now-playingThe player's now-playing viewThe song playing
homeHome, after Songstress's own shelves
artistAn artist's pageThe artist
albumAn album's pageThe album
playlistA playlist's pageThe playlist's id

A song, an artist or an album is handed over whole to an extension granted library.read, and left out for any other. A panel's renderer is told:

Prop

Type

It answers its blocks, or null to show nothing:

src/server.ts
import { songstress } from 'songstress/server'

songstress.ui.panels.register('plays', async ({ album }) => {
  if (!album) return null
  return { children: [{ type: 'text', text: `${album.songCount ?? 0} songs on ${album.name}`, style: 'caption' }] }
})

Status items

A status item is your extension's state at a glance in the player: a few words and an icon ("Sent", a check), in a tone, with what a tap does. Up to 2.

Prop

Type

It is rendered for the song playing: when the player shows it, when the song changes, and when it is refreshed. Its renderer answers what it shows, or null to show nothing now:

Prop

Type

It is told who is looking and the song playing:

Prop

Type

src/server.ts
import { songstress } from 'songstress/server'

songstress.ui.status.register('sent', async ({ userId, song }) => {
  if (!song) return null
  const last = await songstress.storage.get<string>('last', { userId })
  return last === song.id ? { text: 'Sent', icon: 'check', tone: 'success' } : { busy: true }
})

The apps show as many status items as their player has room for, in the order of the extensions' names.

Views

A view is your own HTML file, for what Songstress's components can't draw: a visualiser, a game, a chart of your own. Up to 10. A view and a page are opened the same way, so they share their ids.

Prop

Type

An app opens a view in the browser, apart from the app: a tab on the web, the system's browser on the desktop, the in-app browser on a phone. It gets no songstress API and nothing of the app's: no storage, no session, no player. It is served by the member's own server at an address of its own that expires, and is handed the params it was opened with as the address's query. Any data it needs, it fetches itself. What must react to the app, or work offline, belongs in a declared page.

Actions

What a tap does:

typeWhat it does
invokeRuns one of your commands
navigateOpens one of your pages or views, or Songstress's page for something in the library; as a page or as a sheet
playPlays library songs now, as a tap on a song does
queueAdds library songs to the queue, at its end or next
openUrlOpens an http or https address in the browser
copyCopies text
shareOpens the device's share sheet
toastShows a short message that goes away by itself
notifyShows a notice that stays until it is closed, with up to two buttons
confirmAsks first, then carries out another action
pickAsks the person to choose, then hands their choice to a command
inputAsks for a line of text, then hands it to a command
refreshRenders the page, panel or status item it came from again

A command answers with an action for the app to carry out, so your extension can lead a person through steps that each run on their own: a pick hands its answer to a command, which answers with an input, whose answer goes to another command, which answers with a notice.

Asking

  • pick is Songstress's picker: a title, the items to choose from (each an id and a title, and optionally a subtitle, an icon or an image), a search field with an optional placeholder, and many for a choice of several (picked marks those chosen at first). Then its command runs with the action's input, and context.answer holds the id chosen, or the ids. Up to 100 items.
  • input is one field: a title, a prompt, a placeholder, the value it holds at first, multiline, a maxLength (up to 2000), required, and submit, the word on its button. Then its command runs, and context.answer is the text. Never a password: a secret is a setting.
  • confirm asks yes or no, then carries out its action.

Prop

Type

Prop

Type

context.source says which asked. A question may lead to one more question and no further: a third in a row is no action at all. Nothing runs when the person closes what was asked.

src/server.ts
import { songstress } from 'songstress/server'

songstress.commands.register('choose-chart', async () => ({
  action: {
    type: 'pick',
    title: 'Which chart?',
    items: [
      { id: 'week', title: 'This week' },
      { id: 'year', title: 'This year' },
    ],
    command: 'show-chart',
  },
}))

songstress.commands.register('show-chart', async (_input, context) => ({
  action: { type: 'navigate', to: { page: 'chart', params: { period: String(context.answer) } } },
}))

Notices

A toast goes away by itself. A notice stays until the person closes it: a title, a message, a tone (info, success, warning or danger), and up to two buttons, each a title and an action. The app shows it with your extension's name.

Prop

Type

Code may also tell a notice unasked, while the member has an app open, with songstress.ui.notify(notice). The server entry names the member (songstress.ui.notify(notice, { userId })) and every app they have open shows it. Nothing is kept for an app that is closed. At most ten an hour for one member: more reject with limit-exceeded.

Live

What you draw is rendered when it is shown, and again when the person pulls to refresh, when a refresh action asks, and when your code asks with songstress.ui.refresh(target), where target is { page }, { panel } or { status } with the id. The server entry names the member: songstress.ui.refresh({ status: 'sent' }, { userId }). Asked more often than once every five seconds for one target, an app renders it once.

Conditions

A menu item, a page's navigation entry, a panel and a status item may name a when: a condition the app holds it to, as VS Code's when clauses do. Up to 200 characters:

  • a key alone (true when its value is true, a text that isn't empty, or a number that isn't 0), or compared to a value with == or !=;
  • a value is 'text' in single quotes, a number, true or false;
  • ! turns a condition round, && and || join two, and parentheses group them, nested at most eight deep.
KeyIts valueKnown in
platformweb, desktop, ios or androidEvery place
clientCode, viewsThe app's capabilitiesEvery place
adminThe member is the server's adminEvery place
signedInThe extension's sign-in has an account: the server's, or with scope user the member's ownEvery place
playingThis device's player is playingEvery place
setting.<key>One of your settings, as this member and device have it (never a secret)Every place
favoriteThe song, album or artist the menu was opened on is a favouriteThe menus of a song, an album, an artist, the queue and the player
songstress.json
{ "command": "send-again", "when": "signedIn && setting.mode == 'manual' && platform != 'web'" }

The validator refuses a condition no app can read (WHEN_INVALID), and a key no app knows there, a setting you didn't declare or a secret one, signedIn with no sign-in, or a platform that is none of the four (WHEN_KEY_UNKNOWN). An app that can't read a condition leaves the item out.

What a tree can't do

By design, a tree can't run script or timers in the app, choose a colour, a font, a size or a position (colour is said by meaning, tone, and the theme decides the rest), load an image from the device, ask for a password, draw outside its places, or grow without bound: the apps cap a tree's size, depth and rows, and how often it is redrawn.

An app says which version of the components it draws (client.ui; this is version 2, which added trees, status items, notices, pick and input). A component it doesn't know shows as "needs a newer app", and an action it doesn't know does nothing: read client.ui and answer what that app draws.

On this page