Skip to content

Commit

Permalink
add profile list support
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Jan 8, 2024
1 parent 9571a64 commit 13fa914
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The menu syntax is similar to [mpv.net](https://github.com/mpvnet-player/mpv.net
- `#@chapters`: chapter list
- `#@editions`: edition list
- `#@audio-devices`: audio device list
- `#@profiles`: profile list
- use `_` if no keybinding
- use `ignore` if no command

Expand Down
24 changes: 23 additions & 1 deletion lua/dyn_menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
-- #@chapters: chapter list
-- #@editions: edition list
-- #@audio-devices: audio device list
-- #@profiles: profile list

local opts = require('mp.options')

Expand Down Expand Up @@ -235,6 +236,25 @@ local function update_audio_devices_menu(submenu)
end)
end

local function update_profiles_menu(submenu)
mp.observe_property('profile-list', 'native', function(_, profile_list)
if not profile_list then return end
for i = #submenu, 1, -1 do table.remove(submenu, i) end

for _, profile in ipairs(profile_list) do
if not (profile.name == 'default' or profile.name:find('gui') or
profile.name == 'encoding' or profile.name == 'libmpv') then
submenu[#submenu + 1] = {
title = profile.name,
cmd = string.format('show-text %s; apply-profile %s', profile.name, profile.name),
}
end
end

mp.set_property_native(menu_prop, menu_items)
end)
end

local file_scope_dyn_menus = {}

local function dyn_menu_update(item, keyword)
Expand All @@ -258,9 +278,11 @@ local function dyn_menu_update(item, keyword)
update_editions_menu(item.submenu)
elseif keyword == 'audio-devices' then
update_audio_devices_menu(item.submenu)
elseif keyword == 'profiles' then
update_profiles_menu(item.submenu)
end

if keyword ~= 'audio-devices' then
if keyword ~= 'audio-devices' and keyword ~= 'profiles' then
file_scope_dyn_menus[#file_scope_dyn_menus + 1] = item.submenu
end
end
Expand Down

0 comments on commit 13fa914

Please sign in to comment.