summaryrefslogtreecommitdiff
path: root/volumearc-widget
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@users.noreply.github.com>2021-02-07 20:13:27 -0500
committerGitHub <noreply@github.com>2021-02-07 20:13:27 -0500
commitccd6bd4359593195a84458857efa7a9670b1b4cd (patch)
tree2135e7e01ab0eb154d5f451f3267469e8c48e5a9 /volumearc-widget
parentadb6d2accc0ab73ccba58a1ca16a2d3494269319 (diff)
parent0a7bdb85283accf120e2898724aec8e1a5eff311 (diff)
Merge pull request #239 from artemoff85/bug-volumearc-widget
fix to prevent stdout from passing a null string
Diffstat (limited to 'volumearc-widget')
-rw-r--r--volumearc-widget/volumearc.lua17
1 files changed, 10 insertions, 7 deletions
diff --git a/volumearc-widget/volumearc.lua b/volumearc-widget/volumearc.lua
index a62abde..b104ad3 100644
--- a/volumearc-widget/volumearc.lua
+++ b/volumearc-widget/volumearc.lua
@@ -74,15 +74,18 @@ local function worker(user_args)
widget = wibox.container.arcchart
}
- local update_graphic = function(_, stdout, _, _, _)
- local mute = string.match(stdout, "%[(o%D%D?)%]") -- \[(o\D\D?)\] - [on] or [off]
- local volume = string.match(stdout, "(%d?%d?%d)%%") -- (\d?\d?\d)\%)
- volume = tonumber(string.format("% 3d", volume))
-
+ local update_graphic = function(widget, stdout, _, _, _)
+ local mute = "on"
+ local volume = 0
+ if not (stdout == nil or stdout == '') then
+ mute = string.match(stdout, "%[(o%D%D?)%]") -- \[(o\D\D?)\] - [on] or [off]
+ volume = string.match(tostring(stdout), "(%d?%d?%d)%%") -- (\d?\d?\d)\%)
+ volume = tonumber(string.format("% 3d", volume))
+ end
widget.value = volume / 100;
widget.colors = mute == 'off'
- and { mute_color }
- or { main_color }
+ and { mute_color }
+ or { main_color }
end
local button_press = args.button_press or function(_, _, _, button)