From 3b0c0fcd7e699a5ad1455639fae1980ef22cc799 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Sat, 30 Mar 2024 11:53:45 +0200 Subject: [PATCH] state-stream: fix storing/restoring notification volume We apparently store things in the :: format, while pipewire-pulse expects .: and this detail was missed in the latest refactoring. It also seems that I forgot to ensure that restoring this metadata key worked. The hook was there, but not registered. Remove the hook and directly populate the metadata object when it is activated, as it seems simpler. Fixes: #604 --- src/scripts/node/state-stream.lua | 47 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/scripts/node/state-stream.lua b/src/scripts/node/state-stream.lua index ac34932c..f5ac95d5 100644 --- a/src/scripts/node/state-stream.lua +++ b/src/scripts/node/state-stream.lua @@ -264,32 +264,25 @@ store_stream_target_hook = SimpleEventHook { end } --- track route-settings metadata changes -route_settings_metadata_added_hook = SimpleEventHook { - name = "node/route-settings-metadata-added", - interests = { - EventInterest { - Constraint { "event.type", "=", "metadata-added" }, - Constraint { "metadata.name", "=", "route-settings" }, - }, - }, - execute = function (event) - local metadata = event:get_subject () +-- populate route-settings metadata +function populateMetadata (metadata) + -- copy state into the metadata + local key = "Output/Audio:media.role:Notification" + local p = getStoredStreamProps (key) + if p then + p.channels = p.channelMap and Json.Array (p.channelMap) + p.volumes = p.channelVolumes and Json.Array (p.channelVolumes) + p.channelMap = nil + p.channelVolumes = nil + p.target = nil - -- copy state into the metadata - local key = "Output/Audio:media.role:Notification" - local p = getStoredStreamProps (key) - if p then - p.channels = p.channelMap and Json.Array (p.channelMap) - p.volumes = p.channelVolumes and Json.Array (p.channelVolumes) - p.channelMap = nil - p.channelVolumes = nil - p.target = nil - metadata:set (0, "restore.stream." .. key, "Spa:String:JSON", - Json.Object (p):to_string ()) - end + -- pipewire-pulse expects the key to be + -- "restore.stream.Output/Audio.media.role:Notification" + key = string.gsub (key, ":", ".", 1); + metadata:set (0, "restore.stream." .. key, "Spa:String:JSON", + Json.Object (p):to_string ()) end -} +end -- track route-settings metadata changes route_settings_metadata_changed_hook = SimpleEventHook { @@ -299,7 +292,7 @@ route_settings_metadata_changed_hook = SimpleEventHook { Constraint { "event.type", "=", "metadata-changed" }, Constraint { "metadata.name", "=", "route-settings" }, Constraint { "event.subject.key", "=", - "restore.stream.Output/Audio:media.role:Notification" }, + "restore.stream.Output/Audio.media.role:Notification" }, Constraint { "event.subject.spa_type", "=", "Spa:String:JSON" }, Constraint { "event.subject.value", "is-present" }, }, @@ -316,6 +309,8 @@ route_settings_metadata_changed_hook = SimpleEventHook { end local vparsed = json:parse () + + -- we store the key as "Output/Audio:media.role:Notification" local key = string.sub (key, string.len ("restore.stream.") + 1) key = string.gsub (key, "%.", ":", 1); @@ -427,6 +422,8 @@ function toggleState (enable) rs_metadata:activate (Features.ALL, function (m, e) if e then log:warning ("failed to activate route-settings metadata: " .. tostring (e)) + else + populateMetadata (m) end end)