diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-06 16:00:35 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-06 16:00:35 -0800 |
| commit | 8d9e9e400232e26ed27e00adab96caec06074be2 (patch) | |
| tree | 178f2a592515dd140f3a668791f143a57ff44fc9 | |
| parent | 95e0d4b3c9c6a1a518a0827a2d52e86c457ba875 (diff) | |
| download | mpv-iptv-menu-8d9e9e400232e26ed27e00adab96caec06074be2.tar.gz mpv-iptv-menu-8d9e9e400232e26ed27e00adab96caec06074be2.tar.xz | |
refresh favourites menu when going up stack
| -rw-r--r-- | main.lua | 79 |
1 files changed, 62 insertions, 17 deletions
@@ -449,6 +449,57 @@ local function push_group_menu(group) update_osd() end +local update_search_matches + +local function set_menu_sort(menu, bool) + if not menu.sorted == not bool then + return + end + + local key = menu.type == 'search' and 'search_options' or 'options' + if bool then + menu['orig_' .. key] = menu[key] + menu[key] = util.copy_table(menu[key]) + sort_options(menu[key]) + else + menu[key] = menu['orig_' .. key] + menu['orig_' .. key] = nil + end + + if menu.type == 'search' then + update_search_matches() + end + menu.sorted = bool +end + +local function refresh_favourites_menu() + local menu = menus[depth] + local opt = menu.options[menu.cursor] + local sorted = menu.sorted + if sorted then + set_menu_sort(menu, false) + end + + local options = group_menu_options(catalogue:get(menu.group_id)) + local seen = {} + for _, v in ipairs(options) do + seen[v.id] = true + end + for _, v in ipairs(menu.options) do + if not seen[v.id] then + options[#options+1] = v + end + end + menu.options = options + + if sorted then + set_menu_sort(menu, true) + end + if opt then + cursor_to_object(opt.id) + end +end + local function prev_menu() depth = depth - 1 @@ -456,6 +507,9 @@ local function prev_menu() -- reset main menu push_group_menu(catalogue:get(menus[1].group_id)) else + if menus[depth].group_id == 'favourites' then + refresh_favourites_menu() + end update_osd() end end @@ -514,8 +568,13 @@ local function goto_option() return end - if menu.type == 'search' or menu.group_id == 'favourites' then + if menu.group_id == 'favourites' then + depth = 1 + elseif menu.type == 'search' then depth = depth - 1 + if menus[depth].group_id == 'favourites' then + refresh_favourites_menu() + end end if opt.path then @@ -810,7 +869,7 @@ local function search_menu_options(options) return ret end -local function update_search_matches() +function update_search_matches() local menu = menus[depth] if #menu.search_text == 0 then @@ -990,21 +1049,7 @@ local function toggle_menu_sort() return end - local key = menu.type == 'search' and 'search_options' or 'options' - - menu.sorted = not menu.sorted - if menu.sorted then - menu['orig_' .. key] = menu[key] - menu[key] = util.copy_table(menu[key]) - sort_options(menu[key]) - else - menu[key] = menu['orig_' .. key] - menu['orig_' .. key] = nil - end - - if menu.type == 'search' then - update_search_matches() - end + set_menu_sort(menu, not menu.sorted) update_osd() end |
