scripts: use the WpSettings safe APIs
Avoids Lua errors if a setting cannot be parsed or does not exist.
This commit is contained in:
@@ -16,7 +16,7 @@ function configProperties (node)
|
|||||||
["item.node"] = node,
|
["item.node"] = node,
|
||||||
["item.plugged.usec"] = GLib.get_monotonic_time (),
|
["item.plugged.usec"] = GLib.get_monotonic_time (),
|
||||||
["item.features.no-dsp"] =
|
["item.features.no-dsp"] =
|
||||||
Settings.get ("default-policy-audio.no-dsp"):parse(),
|
Settings.parse_boolean_safe ("default-policy-audio.no-dsp", false),
|
||||||
["item.features.monitor"] = true,
|
["item.features.monitor"] = true,
|
||||||
["item.features.control-port"] = false,
|
["item.features.control-port"] = false,
|
||||||
["node.id"] = node ["bound-id"],
|
["node.id"] = node ["bound-id"],
|
||||||
|
@@ -5,9 +5,7 @@
|
|||||||
--
|
--
|
||||||
-- SPDX-License-Identifier: MIT
|
-- SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
local config_settings = {
|
local config_settings = {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
-- apply properties from rules defined in JSON .conf file
|
-- apply properties from rules defined in JSON .conf file
|
||||||
function rulesApplyProperties(properties)
|
function rulesApplyProperties(properties)
|
||||||
|
@@ -27,9 +27,9 @@
|
|||||||
-- settings file: policy.conf
|
-- settings file: policy.conf
|
||||||
|
|
||||||
local use_persistent_storage =
|
local use_persistent_storage =
|
||||||
Settings.get ("bt-policy-use-persistent-storage"):parse() or false
|
Settings.parse_boolean_safe ("bt-policy-use-persistent-storage", false)
|
||||||
local use_headset_profile =
|
local use_headset_profile =
|
||||||
Settings.get ("bt-policy-media-role.use-headset-profile"):parse() or false
|
Settings.parse_boolean_safe ("bt-policy-media-role.use-headset-profile", true)
|
||||||
|
|
||||||
local applications = {}
|
local applications = {}
|
||||||
local profile_restore_timeout_msec = 2000
|
local profile_restore_timeout_msec = 2000
|
||||||
@@ -45,8 +45,8 @@ local last_profiles = {}
|
|||||||
local active_streams = {}
|
local active_streams = {}
|
||||||
local previous_streams = {}
|
local previous_streams = {}
|
||||||
|
|
||||||
local apps_setting = Settings.get ("bt-policy-media-role.applications"):parse()
|
local apps_setting =
|
||||||
|
Settings.parse_array_safe ("bt-policy-media-role.applications")
|
||||||
for i = 1, #apps_setting do
|
for i = 1, #apps_setting do
|
||||||
applications [apps_setting [i]] = true
|
applications [apps_setting [i]] = true
|
||||||
end
|
end
|
||||||
|
@@ -19,27 +19,11 @@
|
|||||||
-- settings file: device.conf
|
-- settings file: device.conf
|
||||||
|
|
||||||
local use_persistent_storage =
|
local use_persistent_storage =
|
||||||
Settings.get ("device.use-persistent-storage"):parse() or false
|
Settings.parse_boolean_safe ("device.use-persistent-storage", true)
|
||||||
|
local default_volume =
|
||||||
-- the default volume to apply (optional property)
|
Settings.parse_float_safe ("device.default-volume", 0.4^3)
|
||||||
local default_volume = 0.4^3
|
local default_input_volume =
|
||||||
local default_volume_json = Settings.get ("device.default-volume")
|
Settings.parse_float_safe ("default-input-volume", 1.0)
|
||||||
if default_input_volume_json ~= nil then
|
|
||||||
local val = default_volume_json:parse()
|
|
||||||
if val ~= nil then
|
|
||||||
default_volume = val
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- the default input volume to apply (optional property)
|
|
||||||
local default_input_volume = 1.0
|
|
||||||
local default_input_volume_json = Settings.get ("default-input-volume")
|
|
||||||
if default_input_volume_json ~= nil then
|
|
||||||
local val = default_input_volume_json:parse()
|
|
||||||
if val ~= nil then
|
|
||||||
default_input_volume = val
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- table of device info
|
-- table of device info
|
||||||
dev_infos = {}
|
dev_infos = {}
|
||||||
|
@@ -5,16 +5,8 @@
|
|||||||
--
|
--
|
||||||
-- SPDX-License-Identifier: MIT
|
-- SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
local duck_level = Settings.get ("default-policy-duck.level"):parse() or 0.3
|
local duck_level = Settings.parse_float_safe ("default-policy-duck.level", 0.3)
|
||||||
|
local roles = Settings.parse_object_safe ("endpoints-roles")
|
||||||
local roles = {}
|
|
||||||
local roles_json = Settings.get ("endpoints-roles")
|
|
||||||
if roles_json ~= nil then
|
|
||||||
local val = roles_json:parse()
|
|
||||||
if val ~= nil then
|
|
||||||
roles = val
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function findRole(role)
|
function findRole(role)
|
||||||
if role and not roles[role] then
|
if role and not roles[role] then
|
||||||
|
@@ -6,14 +6,8 @@
|
|||||||
-- SPDX-License-Identifier: MIT
|
-- SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
-- Receive script arguments from config.lua
|
-- Receive script arguments from config.lua
|
||||||
local roles = {}
|
|
||||||
local roles_json = Settings.get ("endpoints-roles")
|
local roles = Settings.parse_object_safe ("endpoints-roles")
|
||||||
if roles_json ~= nil then
|
|
||||||
local val = roles_json:parse()
|
|
||||||
if val ~= nil then
|
|
||||||
roles = val
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local self = {}
|
local self = {}
|
||||||
self.scanning = false
|
self.scanning = false
|
||||||
|
@@ -5,8 +5,8 @@
|
|||||||
--
|
--
|
||||||
-- SPDX-License-Identifier: MIT
|
-- SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
local move = Settings.get ("default-policy-move"):parse() or false
|
local move = Settings.parse_boolean_safe ("default-policy-move", false)
|
||||||
local follow = Settings.get ("default-policy-follow"):parse() or false
|
local follow = Settings.parse_boolean_safe ("default-policy-follow", false)
|
||||||
|
|
||||||
local self = {}
|
local self = {}
|
||||||
self.scanning = false
|
self.scanning = false
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
local putils = require ("policy-utils")
|
local putils = require ("policy-utils")
|
||||||
local cutils = require ("common-utils")
|
local cutils = require ("common-utils")
|
||||||
|
|
||||||
local move = Settings.get ("default-policy-move"):parse () or false
|
local move = Settings.parse_boolean_safe ("default-policy-move", false)
|
||||||
|
|
||||||
function parseBool (var)
|
function parseBool (var)
|
||||||
return cutils.parseBool (var)
|
return cutils.parseBool (var)
|
||||||
|
@@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
-- settings file: policy.conf
|
-- settings file: policy.conf
|
||||||
|
|
||||||
local move = Settings.get ("default-policy-move"):parse () or false
|
local move = Settings.parse_boolean_safe ("default-policy-move", false)
|
||||||
local follow = Settings.get ("default-policy-follow"):parse () or false
|
local follow = Settings.parse_boolean_safe ("default-policy-follow", false)
|
||||||
local filter_forward_format = Settings.get ("filter.forward-format"):parse () or false
|
local filter_forward_format =
|
||||||
|
Settings.parse_boolean_safe ("filter.forward-format", false)
|
||||||
|
|
||||||
local putils = require ("policy-utils")
|
local putils = require ("policy-utils")
|
||||||
local cutils = require ("common-utils")
|
local cutils = require ("common-utils")
|
||||||
|
@@ -18,12 +18,12 @@
|
|||||||
|
|
||||||
-- settings file: stream.conf
|
-- settings file: stream.conf
|
||||||
|
|
||||||
config_restore_props = Settings.get ("stream_default.restore-props"):parse()
|
config_restore_props =
|
||||||
or false
|
Settings.parse_boolean_safe ("stream_default.restore-props", false)
|
||||||
config_restore_target = Settings.get ("stream_default.restore-target"):parse()
|
config_restore_target =
|
||||||
or false
|
Settings.parse_boolean_safe ("stream_default.restore-target", false)
|
||||||
config_default_channel_volume = Settings.get_float ("stream.default-channel-volume")
|
config_default_channel_volume =
|
||||||
or 1.0
|
Settings.parse_float_safe ("stream.default-channel-volume", 1.0)
|
||||||
|
|
||||||
function rulesApplyProperties (properties)
|
function rulesApplyProperties (properties)
|
||||||
local matched, mprops = Settings.apply_rule ("stream_default", properties)
|
local matched, mprops = Settings.apply_rule ("stream_default", properties)
|
||||||
|
@@ -6,14 +6,7 @@
|
|||||||
-- SPDX-License-Identifier: MIT
|
-- SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
-- Receive script arguments from config.lua
|
-- Receive script arguments from config.lua
|
||||||
local endpoints = {}
|
local endpoints = Settings.parse_object_safe ("endpoints")
|
||||||
local endpoints_json = Settings.get ("endpoints")
|
|
||||||
if endpoints_json ~= nil then
|
|
||||||
local val = endpoints_json:parse()
|
|
||||||
if val ~= nil then
|
|
||||||
endpoints = val
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function createEndpoint (factory_name, properties)
|
function createEndpoint (factory_name, properties)
|
||||||
-- create endpoint
|
-- create endpoint
|
||||||
|
Reference in New Issue
Block a user