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 mp.input.select() menu support #32

Merged
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
25 changes: 23 additions & 2 deletions recentmenu.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local utils = require("mp.utils")
local options = require("mp.options")
local input_available, input = pcall(require, "mp.input")

local o = {
enabled = true,
Expand All @@ -12,6 +13,8 @@ options.read_options(o, _, function() end)

local path = mp.command_native({ "expand-path", o.path })

local uosc_available = false

local menu = {
type = 'recent_menu',
title = 'Recently played',
Expand Down Expand Up @@ -269,8 +272,25 @@ end

function open_menu()
read_json()
local json = utils.format_json(menu)
mp.commandv('script-message-to', 'uosc', 'open-menu', json)
if uosc_available then
local json = utils.format_json(menu)
mp.commandv('script-message-to', 'uosc', 'open-menu', json)
elseif input_available then
local item_titles, item_values = {}, {}
for i, v in ipairs(menu.items) do
item_titles[i] = v.title
item_values[i] = v.value
end
mp.commandv('script-message-to', 'console', 'disable')
input.select({
prompt = menu.title .. ':',
items = item_titles,
default_item = 1,
submit = function (id)
mp.commandv(unpack(item_values[id]))
end,
})
end
end

function get_dyn_menu_title(title, hint, path)
Expand Down Expand Up @@ -353,6 +373,7 @@ mp.add_key_binding(nil, "last", play_last)
mp.register_event("file-loaded", on_load)
mp.register_event("end-file", on_end)

mp.register_script_message('uosc-version', function() uosc_available = true end)
mp.commandv('script-message-to', 'uosc', 'get-locale', mp.get_script_name())
mp.register_script_message('uosc-locale', function(json)
locale = utils.parse_json(json)
Expand Down