From 5e197224916578382e67857f829037d8eb129a1c Mon Sep 17 00:00:00 2001 From: Julian Bouzas Date: Thu, 7 Mar 2024 18:50:02 -0500 Subject: [PATCH] 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. --- src/scripts/device/apply-routes.lua | 3 --- src/scripts/device/select-routes.lua | 3 --- src/scripts/device/state-routes.lua | 13 ++++++++++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/scripts/device/apply-routes.lua b/src/scripts/device/apply-routes.lua index bb933339..ce71a564 100644 --- a/src/scripts/device/apply-routes.lua +++ b/src/scripts/device/apply-routes.lua @@ -92,9 +92,6 @@ AsyncEventHook { device:set_param ("Route", param) - route_info.prev_active = true - route_info.active = true - ::skip_route:: end diff --git a/src/scripts/device/select-routes.lua b/src/scripts/device/select-routes.lua index cbfb16cf..ecd3df52 100644 --- a/src/scripts/device/select-routes.lua +++ b/src/scripts/device/select-routes.lua @@ -67,9 +67,6 @@ SimpleEventHook { avail_routes_changed = true end end - route_info.prev_active = route_info.active - route_info.active = false - route_info.save = false -- store new_route_infos [route.index] = route_info diff --git a/src/scripts/device/state-routes.lua b/src/scripts/device/state-routes.lua index e6ccba10..1f57c5b7 100644 --- a/src/scripts/device/state-routes.lua +++ b/src/scripts/device/state-routes.lua @@ -170,6 +170,8 @@ store_or_restore_routes_hook = SimpleEventHook { return end + local new_route_infos = {} + -- look at all the routes and update/reset cached information for p in device:iterate_params ("EnumRoute") do -- parse pod @@ -179,7 +181,7 @@ store_or_restore_routes_hook = SimpleEventHook { end -- 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 goto skip_enum_route end @@ -189,9 +191,16 @@ store_or_restore_routes_hook = SimpleEventHook { route_info.active = false route_info.save = false + -- store + new_route_infos [route.index] = route_info + ::skip_enum_route:: 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 for p in device:iterate_params ("Route") do local route = cutils.parseParam (p, "Route") @@ -216,6 +225,8 @@ store_or_restore_routes_hook = SimpleEventHook { log:info (device, string.format ("new active route(%s) found of device(%s)", route.name, dev_info.name)) + route_info.prev_active = true + route_info.active = true selected_routes [tostring (route.device)] = Json.Object { index = route_info.index }:to_string ()