fix: title initializing prematurely and not accounting for dynamic variables

ref #312
This commit is contained in:
tomasklaen
2022-10-10 10:40:22 +02:00
parent 30a3ec195d
commit be1b978528

View File

@@ -4293,10 +4293,21 @@ mp.register_event('end-file', function(event)
handle_file_end()
end
end)
mp.observe_property('title', 'string', function(_, title)
-- Don't change title if there is currently none
if state.title then update_title(title) end
end)
function observe_title()
-- Idle is needed as some template variables might not be present until everything else initialized
mp.unregister_idle(observe_title)
local hot_keywords = {'time'}
local timer = mp.add_periodic_timer(0.9, function() print('updating') update_title(mp.get_property_native('title')) end)
timer:kill()
mp.observe_property('title', 'string', function(_, title)
-- Don't change title if there is currently none
if state.title then update_title(title) end
-- Enable periodic updates for templates with hot variables
local is_hot = itable_find(hot_keywords, function(var) return string.find(title or '', var) ~= nil end)
if is_hot then timer:resume() else timer:kill() end
end)
end
mp.register_idle(observe_title)
mp.observe_property('playback-time', 'number', create_state_setter('time', function()
-- Create a file-end event that triggers right before file ends
file_end_timer:kill()