-
-
Notifications
You must be signed in to change notification settings - Fork 6
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 handler support #30
Conversation
The following is an example patch applied to recentmenu.lua script ---
scripts/recentmenu.lua | 23 ++++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/scripts/recentmenu.lua b/scripts/recentmenu.lua
index 40d44dc..f17f26b 100644
--- a/scripts/recentmenu.lua
+++ b/scripts/recentmenu.lua
@@ -288,6 +288,21 @@ function open_menu()
mp.commandv('script-message-to', 'uosc', 'open-menu', json)
end
+function dyn_menu()
+ read_json()
+ local submenu = {}
+ local menu_items = menu.items
+ for _, item in ipairs(menu_items) do
+ submenu[#submenu + 1] = {
+ title = string.format('%s\t%s', item.title, item.hint),
+ cmd = string.format("%s '%s'", item.value[1], item.value[2]),
+ }
+ end
+ local json = utils.format_json(submenu)
+ mp.commandv('script-message-to', 'dyn_menu', 'menu-items', json, 'recent')
+end
+
function play_last()
read_json()
if menu.items[1] then
@@ -310,14 +325,23 @@ function on_load()
end
current_item = { path, filename, title }
append_item(path, filename, title)
+ dyn_menu()
end
function on_end(e)
if e and e.reason and e.reason == "quit" then
append_item(current_item[1], current_item[2], current_item[3])
end
+ dyn_menu()
end
+mp.register_script_message('dyn_menu-version', function(version)
+ local min_version = '2.0.0'
+ if version >= min_version then
+ dyn_menu()
+ end
+end)
+
mp.add_key_binding(nil, "open", open_menu)
mp.add_key_binding(nil, "last", play_last)
mp.register_event("file-loaded", on_load)
-- |
Other scripts can send a message to render a submenu serialized as JSON
Why? you can trigger the uosc menu created by I have plan to add script message support, by the syntax is different:
|
That's just an example. uosc rendering is a separate menu, while patches implement a right-click submenu.
I'm glad to hear that you have a similar idea, but I don't quite agree with the usage of this script message. You plan to have other scripts send the complete chain of submenu titles, but I believe it should be configurable in input.conf instead of being separated from each other.
This is similar to what I am currently doing, except that I have reused some existing functions. |
That's because your script may call |
So, We can communicate this init state to other scripts through set |
|
Other scripts can send a message to render a submenu serialized as JSON
There are two issues to be solved