scripts/lib: update policy-config to use the settings manager

This commit is contained in:
George Kiagiadakis 2022-11-09 21:29:09 +02:00 committed by Julian Bouzas
parent 57d4a8cb07
commit 67ab0eced2

View file

@ -4,42 +4,16 @@
--
-- SPDX-License-Identifier: MIT
-- Policy configuration manager
-- Policy settings manager
local defaults <const> = {
move = true,
follow = true,
filter_forward_format = false,
local settings_manager = require ("settings-manager")
local defaults = {
["move"] = true,
["follow"] = true,
["filter-forward-format"] = false,
["audio-no-dsp"] = false,
["duck-level"] = 0.3,
}
local keys <const> = {
move = "policy.default.move",
follow = "policy.default.follow",
filter_forward_format = "policy.default.filter-forward-format",
}
local config = {
move = Settings.parse_boolean_safe (keys.move, defaults.move),
follow = Settings.parse_boolean_safe (keys.follow, defaults.follow),
filter_forward_format = Settings.parse_boolean_safe (
keys.filter_forward_format, defaults.filter_forward_format),
}
Settings.subscribe ("policy.default*", function (_, setting, value)
local parsed_val = value:parse ()
if setting == keys.move then
if type (parsed_val) == "boolean" and config.move ~= parsed_val then
config.move = parsed_val
end
elseif setting == keys.follow then
if type (parsed_val) == "boolean" and config.follow ~= parsed_val then
config.follow = parsed_val
end
elseif setting == keys.filter_forward_format then
if type (parsed_val) == "boolean" and config.filter_forward_format ~= parsed_val then
config.filter_forward_format = parsed_val
end
end
end)
return config
return settings_manager.new ("policy.default.", defaults)