From 77d2dcd97fd9ef0de34270adc99503b975ff1b72 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Thu, 10 Oct 2024 11:36:29 -0400 Subject: [PATCH] autoswitch-bluetooth-profile.lua: drop local function declarations There is no point in local functions in the global script scope. We use a sandbox anyway to isolate from other scripts. --- .../device/autoswitch-bluetooth-profile.lua | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/scripts/device/autoswitch-bluetooth-profile.lua b/src/scripts/device/autoswitch-bluetooth-profile.lua index bd9def55..2ec03554 100644 --- a/src/scripts/device/autoswitch-bluetooth-profile.lua +++ b/src/scripts/device/autoswitch-bluetooth-profile.lua @@ -60,30 +60,30 @@ Settings.subscribe ("bluetooth.use-persistent-storage", function () handlePersistentSetting (Settings.get_boolean ("bluetooth.use-persistent-storage")) end) -local function saveHeadsetProfile (device, profile_name) +function saveHeadsetProfile (device, profile_name) local key = "saved-headset-profile:" .. device.properties ["device.name"] headset_profiles [key] = profile_name state:save_after_timeout (headset_profiles) end -local function getSavedHeadsetProfile (device) +function getSavedHeadsetProfile (device) local key = "saved-headset-profile:" .. device.properties ["device.name"] return headset_profiles [key] end -local function saveLastProfile (device, profile_name) +function saveLastProfile (device, profile_name) last_profiles [device.properties ["device.name"]] = profile_name end -local function getSavedLastProfile (device) +function getSavedLastProfile (device) return last_profiles [device.properties ["device.name"]] end -local function isSwitchedToHeadsetProfile (device) +function isSwitchedToHeadsetProfile (device) return getSavedLastProfile (device) ~= nil end -local function findProfile (device, index, name) +function findProfile (device, index, name) for p in device:iterate_params ("EnumProfile") do local profile = cutils.parseParam (p, "EnumProfile") if not profile then @@ -103,7 +103,7 @@ local function findProfile (device, index, name) return INVALID, INVALID, nil end -local function getCurrentProfile (device) +function getCurrentProfile (device) for p in device:iterate_params ("Profile") do local profile = cutils.parseParam (p, "Profile") if profile then @@ -114,7 +114,7 @@ local function getCurrentProfile (device) return nil end -local function highestPrioProfileWithInputRoute (device) +function highestPrioProfileWithInputRoute (device) local profile_priority = INVALID local profile_index = INVALID local profile_name = nil @@ -152,7 +152,7 @@ local function highestPrioProfileWithInputRoute (device) return profile_priority, profile_index, profile_name end -local function hasProfileInputRoute (device, profile_index) +function hasProfileInputRoute (device, profile_index) for p in device:iterate_params ("EnumRoute") do local route = cutils.parseParam (p, "EnumRoute") if route and route.direction == "Input" and route.profiles then @@ -166,7 +166,7 @@ local function hasProfileInputRoute (device, profile_index) return false end -local function switchDeviceToHeadsetProfile (dev_id, device_om) +function switchDeviceToHeadsetProfile (dev_id, device_om) -- Find the actual device local device = device_om:lookup { Constraint { "bound-id", "=", dev_id, type = "gobject" } @@ -222,7 +222,7 @@ local function switchDeviceToHeadsetProfile (dev_id, device_om) end end -local function restoreProfile (dev_id, device_om) +function restoreProfile (dev_id, device_om) -- Find the actual device local device = device_om:lookup { Constraint { "bound-id", "=", dev_id, type = "gobject" } @@ -274,7 +274,7 @@ local function restoreProfile (dev_id, device_om) end end -local function triggerSwitchDeviceToHeadsetProfile (dev_id, device_om) +function triggerSwitchDeviceToHeadsetProfile (dev_id, device_om) -- Always clear any pending restore/switch callbacks when triggering a new switch if restore_timeout_source[dev_id] ~= nil then restore_timeout_source[dev_id]:destroy () @@ -292,7 +292,7 @@ local function triggerSwitchDeviceToHeadsetProfile (dev_id, device_om) end) end -local function triggerRestoreProfile (dev_id, device_om) +function triggerRestoreProfile (dev_id, device_om) -- we never restore the device profiles if there are active streams for _, v in pairs (active_streams) do if v == dev_id then @@ -319,7 +319,7 @@ end -- We consider a Stream of interest if it is linked to a bluetooth loopback -- source filter -local function checkStreamStatus (stream, node_om, visited_link_groups) +function checkStreamStatus (stream, node_om, visited_link_groups) -- check if the stream is linked to a bluetooth loopback source local stream_id = tonumber(stream["bound-id"]) local peer_id = lutils.getNodePeerId (stream_id) @@ -376,7 +376,7 @@ local function checkStreamStatus (stream, node_om, visited_link_groups) return nil end -local function handleStream (stream, node_om, device_om) +function handleStream (stream, node_om, device_om) if not Settings.get_boolean ("bluetooth.autoswitch-to-headset-profile") then return end @@ -395,7 +395,7 @@ local function handleStream (stream, node_om, device_om) end end -local function handleAllStreams (node_om, device_om) +function handleAllStreams (node_om, device_om) for stream in node_om:iterate { Constraint { "media.class", "matches", "Stream/Input/Audio", type = "pw-global" }, Constraint { "node.link-group", "-", type = "pw" },