auto_profiles: check for non-existent properties

Previously, it just silently didn't do anything which is not very
intuitive. Since the lua api returns an error string, check to see if
it matches the "property not found" case and print an error message.
Additionally, don't add the fake property to the internal
cached_properties list or try to observe it. This avoids redundant
evaluate calls which will never actually succeed. We do still mark it
under watched_properties however. This avoids having to call
mp.get_property_native multiple times.
This commit is contained in:
Dudemanguy 2023-03-28 20:47:31 -05:00
parent bdf7b5c3b8
commit 6e4a76db08
1 changed files with 6 additions and 1 deletions

View File

@ -87,8 +87,13 @@ function get(name, default)
-- Normally, we use the cached value only
if not watched_properties[name] then
watched_properties[name] = true
local res, err = mp.get_property_native(name)
if err == "property not found" then
msg.error("Property '" .. name .. "' was not found.")
return default
end
cached_properties[name] = res
mp.observe_property(name, "native", on_property_change)
cached_properties[name] = mp.get_property_native(name)
end
-- The first time the property is read we need add it to the
-- properties_to_profiles table, which will be used to mark the profile