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:
co-authored by
WojciechSulocki-Gif
parent
e7bf19364c
commit
a4664d0291
@@ -1,6 +1,6 @@
|
|||||||
id = "blackbartblues/audio-switcher"
|
id = "blackbartblues/audio-switcher"
|
||||||
name = "Audio Switcher"
|
name = "Audio Switcher"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
plugin_api = 9
|
plugin_api = 9
|
||||||
author = "blackbartblues"
|
author = "blackbartblues"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ local function runCommand(args, callback, timeoutMs)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function runPactl(args, callback, timeoutMs)
|
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
|
for _, value in ipairs(args) do table.insert(command, value) end
|
||||||
return runCommand(command, callback, timeoutMs)
|
return runCommand(command, callback, timeoutMs)
|
||||||
end
|
end
|
||||||
@@ -205,6 +205,25 @@ local function firstVolumePercent(volume)
|
|||||||
return 0
|
return 0
|
||||||
end
|
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)
|
local function propertiesOf(item)
|
||||||
return type(item.properties) == "table" and item.properties or {}
|
return type(item.properties) == "table" and item.properties or {}
|
||||||
end
|
end
|
||||||
@@ -508,23 +527,22 @@ local function loadCurrentVolume(kind, callback)
|
|||||||
callback(false)
|
callback(false)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local volumeData = decodeJson(volumeResult.stdout)
|
local volume = parseCurrentVolume(volumeResult.stdout)
|
||||||
if volumeData == nil or type(volumeData.volume) ~= "table" then
|
if volume == nil then
|
||||||
callback(false)
|
callback(false)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local volume = firstVolumePercent(volumeData.volume)
|
|
||||||
runPactl({ "-f", "json", muteCommand, target }, function(muteResult)
|
runPactl({ "-f", "json", muteCommand, target }, function(muteResult)
|
||||||
if muteResult.exitCode ~= 0 then
|
if muteResult.exitCode ~= 0 then
|
||||||
callback(false)
|
callback(false)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local muteData = decodeJson(muteResult.stdout)
|
local muted = parseCurrentMute(muteResult.stdout)
|
||||||
if muteData == nil then
|
if muted == nil then
|
||||||
callback(false)
|
callback(false)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
callback(true, volume, muteData.mute == true)
|
callback(true, volume, muted)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ local function render()
|
|||||||
if snapshot.busy == true then
|
if snapshot.busy == true then
|
||||||
barWidget.setGlyphColor("secondary")
|
barWidget.setGlyphColor("secondary")
|
||||||
elseif snapshot.available == true then
|
elseif snapshot.available == true then
|
||||||
barWidget.setGlyphColor("primary")
|
barWidget.setGlyphColor("default")
|
||||||
else
|
else
|
||||||
barWidget.setGlyphColor("error")
|
barWidget.setGlyphColor("error")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user