fix: controls couldn't cycle some mpv properties

closes #777
This commit is contained in:
tomasklaen
2023-11-07 15:10:39 +01:00
parent ed42152bb8
commit 0531659397
2 changed files with 7 additions and 4 deletions

View File

@@ -52,7 +52,7 @@ function CycleButton:init(id, props)
self['on_prop_' .. self.prop] = function(self, value) handle_change(self.prop, value) end
handle_change(self.prop, state[self.prop])
else
self:observe_mp_property(self.prop, handle_change)
self:observe_mp_property(self.prop, 'string', handle_change)
end
end

View File

@@ -182,9 +182,12 @@ end
-- Automatically registers disposer for the observer.
---@param name string
---@param callback fun(name: string, value: any)
function Element:observe_mp_property(name, callback)
mp.observe_property(name, 'native', callback)
---@param type_or_callback string|fun(name: string, value: any)
---@param callback_maybe nil|fun(name: string, value: any)
function Element:observe_mp_property(name, type_or_callback, callback_maybe)
local callback = type(type_or_callback) == 'function' and type_or_callback or callback_maybe
local prop_type = type(type_or_callback) == 'string' and type_or_callback or 'native'
mp.observe_property(name, prop_type, callback)
self:register_disposer(function() mp.unobserve_property(callback) end)
end