fix(audio-switcher): fix an error printed to logs and change widget color to default (#149)

* fix(audio-switcher): remove json decode which parsed a table

* fix(audio-switcher): use default widget coloring

* chore(audio-switcher): bump version to 0.2.1

* fix(audio-switcher): parse pactl volume output safely

---------

Co-authored-by: WojciechSulocki-Gif <wojciechsulocki@gmail.com>
This commit is contained in:
HiImKobeAnd
2026-07-29 15:48:20 -04:00
committed by GitHub
co-authored by WojciechSulocki-Gif
parent e7bf19364c
commit a4664d0291
3 changed files with 27 additions and 9 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
id = "blackbartblues/audio-switcher"
name = "Audio Switcher"
version = "0.2.0"
version = "0.2.1"
plugin_api = 9
author = "blackbartblues"
license = "MIT"
+25 -7
View File
@@ -97,7 +97,7 @@ local function runCommand(args, callback, timeoutMs)
end
local function runPactl(args, callback, timeoutMs)
local command = { "pactl" }
local command = { "env", "LC_ALL=C", "pactl" }
for _, value in ipairs(args) do table.insert(command, value) end
return runCommand(command, callback, timeoutMs)
end
@@ -205,6 +205,25 @@ local function firstVolumePercent(volume)
return 0
end
local function parseCurrentVolume(output)
local decoded = noctalia.json.decode(tostring(output or ""))
if type(decoded) == "table" and type(decoded.volume) == "table" then
return firstVolumePercent(decoded.volume)
end
return tonumber(tostring(output or ""):match("(%d+)%%"))
end
local function parseCurrentMute(output)
local decoded = noctalia.json.decode(tostring(output or ""))
if type(decoded) == "table" and type(decoded.mute) == "boolean" then
return decoded.mute
end
local value = tostring(output or ""):match("Mute:%s*(%a+)")
if value == "yes" then return true end
if value == "no" then return false end
return nil
end
local function propertiesOf(item)
return type(item.properties) == "table" and item.properties or {}
end
@@ -508,23 +527,22 @@ local function loadCurrentVolume(kind, callback)
callback(false)
return
end
local volumeData = decodeJson(volumeResult.stdout)
if volumeData == nil or type(volumeData.volume) ~= "table" then
local volume = parseCurrentVolume(volumeResult.stdout)
if volume == nil then
callback(false)
return
end
local volume = firstVolumePercent(volumeData.volume)
runPactl({ "-f", "json", muteCommand, target }, function(muteResult)
if muteResult.exitCode ~= 0 then
callback(false)
return
end
local muteData = decodeJson(muteResult.stdout)
if muteData == nil then
local muted = parseCurrentMute(muteResult.stdout)
if muted == nil then
callback(false)
return
end
callback(true, volume, muteData.mute == true)
callback(true, volume, muted)
end)
end)
end
+1 -1
View File
@@ -45,7 +45,7 @@ local function render()
if snapshot.busy == true then
barWidget.setGlyphColor("secondary")
elseif snapshot.available == true then
barWidget.setGlyphColor("primary")
barWidget.setGlyphColor("default")
else
barWidget.setGlyphColor("error")
end