Skip to content

Commit

Permalink
fix: controls couldn't cycle some mpv properties
Browse files Browse the repository at this point in the history
closes #777
  • Loading branch information
tomasklaen committed Nov 7, 2023
1 parent ed42152 commit 0531659
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/uosc/elements/CycleButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions src/uosc/elements/Element.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0531659

Please sign in to comment.