scripts: fix regression in state-routes.lua when marking routes as 'active'

Like WirePlumber 0.4.17, we need to mark the current routes as 'active' if they
were previously not active as soon as we detect it. This avoids a possible
infinite loop that restores the routes and saves them constantly, which happens
when the device's Route param has changed more than once before the event
'select-routes' is triggered.
This commit is contained in:
Julian Bouzas
2024-03-07 18:50:02 -05:00
committed by George Kiagiadakis
parent bed3b62e0d
commit 5e19722491
3 changed files with 12 additions and 7 deletions

View File

@@ -92,9 +92,6 @@ AsyncEventHook {
device:set_param ("Route", param) device:set_param ("Route", param)
route_info.prev_active = true
route_info.active = true
::skip_route:: ::skip_route::
end end

View File

@@ -67,9 +67,6 @@ SimpleEventHook {
avail_routes_changed = true avail_routes_changed = true
end end
end end
route_info.prev_active = route_info.active
route_info.active = false
route_info.save = false
-- store -- store
new_route_infos [route.index] = route_info new_route_infos [route.index] = route_info

View File

@@ -170,6 +170,8 @@ store_or_restore_routes_hook = SimpleEventHook {
return return
end end
local new_route_infos = {}
-- look at all the routes and update/reset cached information -- look at all the routes and update/reset cached information
for p in device:iterate_params ("EnumRoute") do for p in device:iterate_params ("EnumRoute") do
-- parse pod -- parse pod
@@ -179,7 +181,7 @@ store_or_restore_routes_hook = SimpleEventHook {
end end
-- find cached route information -- find cached route information
local route_info = devinfo.find_route_info (dev_info, route, false) local route_info = devinfo.find_route_info (dev_info, route, true)
if not route_info then if not route_info then
goto skip_enum_route goto skip_enum_route
end end
@@ -189,9 +191,16 @@ store_or_restore_routes_hook = SimpleEventHook {
route_info.active = false route_info.active = false
route_info.save = false route_info.save = false
-- store
new_route_infos [route.index] = route_info
::skip_enum_route:: ::skip_enum_route::
end end
-- update route_infos with new prev_active, active and save changes
dev_info.route_infos = new_route_infos
new_route_infos = nil
-- check for changes in the active routes -- check for changes in the active routes
for p in device:iterate_params ("Route") do for p in device:iterate_params ("Route") do
local route = cutils.parseParam (p, "Route") local route = cutils.parseParam (p, "Route")
@@ -216,6 +225,8 @@ store_or_restore_routes_hook = SimpleEventHook {
log:info (device, log:info (device,
string.format ("new active route(%s) found of device(%s)", string.format ("new active route(%s) found of device(%s)",
route.name, dev_info.name)) route.name, dev_info.name))
route_info.prev_active = true
route_info.active = true
selected_routes [tostring (route.device)] = selected_routes [tostring (route.device)] =
Json.Object { index = route_info.index }:to_string () Json.Object { index = route_info.index }:to_string ()