Skip to Content
Documentation

Commands, menus and settings

Name the actions your code carries out, place them in Songstress's menus, and declare the settings Songstress draws for you.

Commands

A command is a named action your code carries out. Declare it, then register its handler under the same id in the entry run names. Up to 50.

Prop

Type

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

songstress.commands.register('test-connection', async (_input, context) => {
  const token = await songstress.settings.get<string>('token', { userId: context.userId })
  return { action: { type: 'toast', message: token ? 'Connected.' : 'Add your token first.', tone: token ? 'success' : 'warning' } }
})

A handler is handed the command's input (the song, album or artist a menu was opened on, a form's values, the answer to a question) and its context: who ran it (userId), from where (source: menu, action, form, settings, pick, input or code), and in which app (client). It may answer with an action for the app to carry out, and a value for code that called it.

Prop

Type

Prop

Type

Commands cross sides. Client code may run one of the extension's server commands with songstress.commands.execute(id, input) and gets back the value its handler left: that is how the two halves of an extension talk. Server code has no execute; it calls its own functions.

menus places commands, keyed by location. Each location is a list of up to ten { "command": "<id>" } items, each naming a declared command (MENU_COMMAND_UNKNOWN), none twice in one menu (DUPLICATE_ID). An item may have a when: a condition it shows under.

songstress.json
"menus": {
  "song/context": [{ "command": "add-to-chart", "when": "signedIn && !favorite" }],
  "player/actions": [{ "command": "open-visualiser", "when": "views && platform != 'ios'" }]
}

Prop

Type

Each item:

Prop

Type

On phones, an extension's items in a menu sit together in one "Extensions" submenu, and there is no sidebar.

Settings

Songstress draws and keeps your settings for you: a list, in the order they're shown, of up to 50. Every setting has a key (the name code reads it by), a type, a title, an optional description, and a scope.

scopeWhose it isWho reads it
serverThe whole server's; the admin sets itThe server entry, and client code unless it is a secret
userEach member's ownThe server entry, naming the member, and that member's client code
deviceEach device's ownClient code on that device

Each type takes its own fields. Text:

Prop

Type

A secret, drawn as a password field. Songstress seals it, never shows it again and never sends it to an app; only the server entry reads it:

Prop

Type

A number:

Prop

Type

A switch:

Prop

Type

One choice from a list:

Prop

Type

Each option:

Prop

Type

required means Songstress asks for the setting and doesn't start the extension for whoever lacks it: for anyone while a server setting is empty, for a member while their user setting is, on a device while its device setting is. A default must be a value the setting itself accepts (SETTING_DEFAULT_INVALID), a minimum may not be above its maximum (SETTING_RANGE_INVALID), and no two options share a value (SETTING_OPTION_DUPLICATE).

Reading a setting

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

declare const userId: string // the member a call concerns, from a hook or a command

const token = await songstress.settings.get<string>('token', { userId }) // a member's own
const mode = await songstress.settings.get<string>('mode') // the server's
songstress.settings.onChange((change) => console.log('a setting changed', change))

The settings page

Every app draws the settings on the extension's own page, each scope where its owner sets it: the server's for the admin, a member's own, and this device's under "This device" ("This phone" on a phone). A setting may name a section, up to 40 characters: settings that name the same section are drawn together under it as a heading, in the order the sections first come, and those that name none come first. The buttons of menus["settings/actions"] stand under them.

On this page