[volume_freebsd] Use spawn.easy_async instead of io.popen

NOTE: Similar to volume_linux, the default mute symbol has also been changed.
This commit is contained in:
Nguyễn Gia Phong 2019-05-16 18:52:22 +07:00
parent 92a2138296
commit 6f002577b9
3 changed files with 17 additions and 23 deletions

View File

@ -1,6 +1,6 @@
IMPORTANT:
- `volume_linux` now uses 🔉 and 🔈 instead of ♫ and ♩ to show mute state.
- `volume` now uses 🔉 and 🔈 instead of ♫ and ♩ to show mute state.
This BREAKS backward compatibility if users substitute custom symbols
from these default.
@ -16,7 +16,7 @@ Added:
Fixed:
- [volume_linux] Deprecate `io.popen`
- [volume] Deprecate `io.popen`
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
- [pkg,weather,contrib/btc] Allow function call without Awesome
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)

View File

@ -1,9 +1,8 @@
-- {{{ Grab environment
local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
local string = { match = string.match }
local helpers = require("vicious.helpers")
local helpers = require"vicious.helpers"
local spawn = require"vicious.spawn"
-- }}}
@ -13,26 +12,20 @@ local volume_freebsd = {}
-- {{{ Volume widget type
local function worker(format, warg)
if not warg then return end
local STATE = { on = '🔉', off = '🔈' }
local mixer_state = { "", "" }
-- Get mixer control contents
f = io.popen("mixer -s " .. helpers.shellquote(warg))
local mixer = f:read()
f:close()
-- Capture mixer control state: [5%] ... ... [on]
local voll, volr = string.match(mixer, "([%d]+):([%d]+)$")
if voll == "0" and volr == "0" then
return {0, 0, mixer_state[2]}
else
return {voll, volr, mixer_state[1]}
local function parse(stdout, stderr, exitreason, exitcode)
-- Capture mixer control state, e.g. 42 : 42
local voll, volr = string.match(stdout, "([%d]+):([%d]+)$")
if voll == "0" and volr == "0" then return { 0, 0, STATE.off } end
return { tonumber(voll), tonumber(volr), STATE.on }
end
function volume_freebsd.async(format, warg, callback)
if not warg then return callback{} end
spawn.easy_async("mixer -s " .. helpers.shellquote(warg),
function (...) callback(parse(...)) end)
end
-- }}}
return setmetatable(volume_freebsd, { __call = function(_, ...) return worker(...) end })
return helpers.setasyncall(volume_freebsd)

View File

@ -4,6 +4,7 @@
---------------------------------------------------
-- {{{ Grab environment
local type = type
local tonumber = tonumber
local string = { match = string.match }
local table = { concat = table.concat }