Fix MPV menu: resolve Lua syntax error and enhance logging
- Remove extra 'end)' that caused '<eof>' expected syntax error at line 2834 - Add comprehensive logging to M.show_menu() with [MENU] prefix - Add logging wrappers to keybindings (m and mbtn_right) - Implement fallback menu opening methods (commandv and command) - Fix audio-display mpv.conf setting to 'no' (was invalid 'yes')
This commit is contained in:
@@ -2831,41 +2831,82 @@ mp.register_script_message('medios-load-url-event', function(json)
|
||||
close_menu()
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Menu integration with UOSC
|
||||
function M.show_menu()
|
||||
_lua_log('M.show_menu called')
|
||||
_lua_log('[MENU] M.show_menu called')
|
||||
|
||||
-- Build menu items
|
||||
local items = {
|
||||
{ title = "Load URL", value = {"script-message-to", mp.get_script_name(), "medios-load-url"} },
|
||||
{ title = "Get Metadata", value = "script-binding medios-info", hint = "Ctrl+i" },
|
||||
{ title = "Delete File", value = "script-binding medios-delete", hint = "Ctrl+Del" },
|
||||
{ title = "Load URL", value = {"script-message-to", mp.get_script_name(), "medios-load-url"} },
|
||||
{ title = "Cmd", value = {"script-message-to", mp.get_script_name(), "medios-open-cmd"}, hint = "Run quick commands (screenshot, trim, etc)" },
|
||||
{ title = "Cmd", value = {"script-message-to", mp.get_script_name(), "medios-open-cmd"}, hint = "screenshot/trim/etc" },
|
||||
{ title = "Download", value = {"script-message-to", mp.get_script_name(), "medios-download-current"} },
|
||||
{ title = "Change Format", value = {"script-message-to", mp.get_script_name(), "medios-change-format-current"} },
|
||||
}
|
||||
|
||||
-- Only show "Start Helper" if helper is not running (conditional menu item)
|
||||
-- Conditionally add "Start Helper" if not running
|
||||
if not _is_pipeline_helper_ready() then
|
||||
table.insert(items, { title = "Start Helper", hint = "(for pipeline actions)", value = {"script-message-to", mp.get_script_name(), "medios-start-helper"} })
|
||||
table.insert(items, { title = "Start Helper", hint = "(pipeline actions)", value = {"script-message-to", mp.get_script_name(), "medios-start-helper"} })
|
||||
end
|
||||
|
||||
_lua_log('[MENU] Built ' .. #items .. ' menu items')
|
||||
|
||||
-- Check UOSC availability
|
||||
local uosc_ready = ensure_uosc_loaded()
|
||||
_lua_log('[MENU] ensure_uosc_loaded returned: ' .. tostring(uosc_ready))
|
||||
|
||||
if not uosc_ready then
|
||||
_lua_log('[MENU] ERROR: uosc not available; menu cannot open')
|
||||
mp.osd_message('Menu unavailable (uosc not loaded)', 3)
|
||||
return
|
||||
end
|
||||
|
||||
-- Format menu for UOSC
|
||||
local menu_data = {
|
||||
title = "Medios Macina",
|
||||
items = items,
|
||||
}
|
||||
|
||||
local json = utils.format_json(menu_data)
|
||||
if ensure_uosc_loaded() then
|
||||
_lua_log('[MENU] Sending menu JSON to uosc: ' .. string.sub(json, 1, 200) .. '...')
|
||||
|
||||
-- Try to open menu via uosc script message
|
||||
-- Note: UOSC expects JSON data as a string parameter
|
||||
local ok, err = pcall(function()
|
||||
-- Method 1: Try commandv with individual arguments
|
||||
mp.commandv('script-message-to', 'uosc', 'open-menu', json)
|
||||
end)
|
||||
|
||||
if not ok then
|
||||
_lua_log('[MENU] Method 1 failed: ' .. tostring(err))
|
||||
-- Method 2: Try command with full string
|
||||
local cmd = 'script-message-to uosc open-menu ' .. json
|
||||
local ok2, err2 = pcall(function()
|
||||
mp.command(cmd)
|
||||
end)
|
||||
if not ok2 then
|
||||
_lua_log('[MENU] Method 2 failed: ' .. tostring(err2))
|
||||
mp.osd_message('Menu error', 3)
|
||||
else
|
||||
_lua_log('[MENU] Menu command sent via method 2')
|
||||
end
|
||||
else
|
||||
_lua_log('menu: uosc not available; cannot open-menu')
|
||||
_lua_log('[MENU] Menu command sent successfully')
|
||||
end
|
||||
end
|
||||
|
||||
-- Keybindings
|
||||
mp.add_key_binding("m", "medios-menu", M.show_menu)
|
||||
mp.add_key_binding("mbtn_right", "medios-menu-right-click", M.show_menu)
|
||||
-- Keybindings with logging wrappers
|
||||
mp.add_key_binding("m", "medios-menu", function()
|
||||
_lua_log('[KEY] mbtn m pressed')
|
||||
M.show_menu()
|
||||
end)
|
||||
|
||||
mp.add_key_binding("mbtn_right", "medios-menu-right-click", function()
|
||||
_lua_log('[KEY] mbtn_right pressed (right-click)')
|
||||
M.show_menu()
|
||||
end)
|
||||
mp.add_key_binding("ctrl+i", "medios-info", M.get_file_info)
|
||||
mp.add_key_binding("ctrl+del", "medios-delete", M.delete_current_file)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user