Skip to content

UI API ​

The ui namespace provides methods for displaying native popup menus, balloon notifications, context menus, and theme toast events.

ui ​

ui.hideNotification ​

Hide the balloon shown by showNotification; nothing to do when none was shown.

This method takes no parameters.

Returns

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
const result = await fb2k.invoke('ui.hideNotification');

ui.showContextMenu ​

Open the main window's own context menu. Coordinates that are omitted, not positive, or more than 50 px away from the real cursor are replaced by the cursor position.

ParameterTypeRequiredDescription
xintegerNoScreen x in pixels. Default: -1.
yintegerNoScreen y in pixels. Default: -1.

Returns

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
// Omit x and y to open at the current cursor position
await fb2k.invoke('ui.showContextMenu');

Automatic Coordinate Correction

When supplied coordinates deviate by more than 50 pixels from the physical cursor position, the host automatically snaps to the current system cursor position, ensuring accurate positioning across multi-monitor setups and high-DPI scaling.

ui.showCustomMenu ​

Show a native popup menu at the system cursor position and wait for the choice. The chosen row is reported as selectedId and also announced to the calling window as ui:menuItemClicked with { id, label }; dismissing the menu reports selectedId: null.

ParameterTypeRequiredDescription
itemsUiMenuItem[]YesThe rows.
items[].idstringNoIdentifier reported as selectedId and in ui:menuItemClicked.
items[].labelstringNoDisplay text.
items[].typestringNoseparator draws a separator; any other value is an ordinary row. Default: "item".
items[].enabledbooleanNoWhether the row can be picked. Default: true.
items[].checkedbooleanNoWhether the row shows a checkmark. Default: false.
items[].shortcutstringNoShortcut hint drawn right-aligned after the label.
items[].submenuUiMenuItem[]NoChild rows; a row with this key opens a submenu instead of being picked.
xintegerNoAccepted for compatibility; the menu opens at the system cursor. Default: 0.
yintegerNoAccepted for compatibility; the menu opens at the system cursor. Default: 0.
wintegerNoWith h, the size of a rectangle below the cursor the menu must not cover; the menu then opens below it. Default: 0.
hintegerNoSee w. Default: 0.
suppressDefaultbooleanNoAccepted for compatibility; has no effect. Default: false.

Returns

FieldTypeDescription
selectedIdstring | nullId of the chosen row; null when the menu was dismissed.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
const res = await fb2k.invoke('ui.showCustomMenu', {
    items: [
        { id: 'play', label: 'Play' },
        { type: 'separator' },
        { id: 'remove', label: 'Remove', enabled: false },
    ],
});
if (res.success === false) throw new Error(res.error);
const { selectedId } = res;

ui.showNotification ​

Show a Windows balloon notification from the plugin's notification icon, creating the icon on first use. At least one of title and body must be given.

ParameterTypeRequiredDescription
titlestringNoNotification title. Default: "".
bodystringNoNotification body. Default: "".
silentbooleanNotrue shows it without the notification sound. Default: false.
timeoutintegerNoDisplay time in milliseconds, as a hint to the shell. Default: 5000.

Returns

FieldTypeDescription
idintegerSequence number of the notification, from 1.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
await fb2k.invoke('ui.showNotification', {
    title: 'Now Playing',
    body: 'Daft Punk - Digital Love',
});

ui.showToast ​

Ask the calling window's page to show a toast: nothing is painted natively, the payload is delivered to that window as ui:toast with { message, duration, type, position }.

ParameterTypeRequiredDescription
messagestringYesToast text. Must not be empty.
durationintegerNoDisplay time in milliseconds. Default: 3000.
type"info" | "success" | "warning" | "error"NoToast kind, passed through to the page. Default: "info".
positionstringNoScreen corner, passed through to the page. Default: "bottom-right".

Returns

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
await fb2k.invoke('ui.showToast', { message: 'Playlist saved', type: 'success' });

Frontend Rendering Model

ui.showToast does not draw UI natively in C++. Instead, it dispatches a ui:toast event directed to the calling window; the frontend listens for this event and renders the toast using the active theme's UI component for consistent visuals.

Interaction delivery and limitations ​

ui.showCustomMenu uses the current cursor position for native placement and routes ui:menuItemClicked to the calling window. A dismissed menu returns a successful result with selectedId: null. ui.showToast paints no native UI: it dispatches ui:toast to the caller so that the active theme controls presentation.