fix: title initializing prematurely and not accounting for dynamic variables
ref #312
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user