Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add message interface #31

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ The menu syntax is similar to [mpv.net](https://github.com/mpvnet-player/mpv.net
- use `_` if no keybinding
- use `ignore` if no command

> You may define custom keywords to be used in another script, and update it's menu with [message](#messages).

```
Ctrl+a show-text foobar #menu: Foo > Bar
_ ignore #menu: -
Expand Down Expand Up @@ -78,9 +80,11 @@ If both `menu.dll` and `menu.lua` exists in scripts folder, one of it may be nam

- `max_title_length=80`: Limits the title length in dynamic submenu, set to 0 to disable.

## Updating menu from script
## Scripting

### Properties

The menu data is stored in `user-data/menu/items` property with the following structure:
#### `user-data/menu/items`

```
MPV_FORMAT_NODE_ARRAY
Expand All @@ -92,10 +96,44 @@ MPV_FORMAT_NODE_ARRAY
"submenu" MPV_FORMAT_NODE_ARRAY[menu item] (required if type is submenu)
```

Updating this property will trigger an update of the menu UI.
The menu data of the C plugin is stored in this property, updating it will trigger an update of the menu UI.

To reduce update frequency, it's recommended to update this property in [mp.register_idle(fn)](https://mpv.io/manual/master/#lua-scripting-mp-register-idle(fn)).

Be aware that `dyn_menu.lua` is conflict with other scripts that also update the `user-data/menu/items` property,
you may use the messages below if you only want to update part of the menu.

### Messages

#### `menu-ready`

Broadcasted when `dyn_menu.lua` has initilized itself.

#### `get <keyword> <src>`

Get the menu item structure of `keyword`, and send a json reply to `src`.

```json
{
"keyword": "chapters"
"item": {
"title": "Chapters",
"type": "submenu",
"submenu": []
}
}
```

The reply is sent via `srcript-message-to <src> menu-get-reply <json>`.

If `keyword` is not found, the result json will contain an additional `error` field, and no `item` field.

#### `update <keyword> <json>`

Update the menu item structure of `keyword` with `json`.

As a convenience, if you don't want to override menu title and type, omit the corresponding field in `json`.

## Credits

This project contains code copied from [mpv](https://github.com/mpv-player/mpv).
Expand Down
Loading