[mpd] Deprecate io.popen

This commit is contained in:
Nguyễn Gia Phong 2019-06-05 10:57:18 +07:00
parent b0b6d46937
commit db446c35d9
2 changed files with 32 additions and 35 deletions

View File

@ -20,7 +20,7 @@ Fixed:
- Deprecate the use of `io.popen` in following widgets: - Deprecate the use of `io.popen` in following widgets:
* wifi_linux, wifiiw_linux * wifi_linux, wifiiw_linux
* bat_freebsd, mem_freebsd, net_freebsd * bat_freebsd, mem_freebsd, net_freebsd
* volume, gmail, mdir * volume, gmail, mdir, mpd
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo - [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
- [pkg,weather,contrib/btc] Allow function call without Awesome - [pkg,weather,contrib/btc] Allow function call without Awesome
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf) - [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)

View File

@ -5,11 +5,10 @@
-- {{{ Grab environment -- {{{ Grab environment
local tonumber = tonumber local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
local string = { gmatch = string.gmatch }
local helpers = require("vicious.helpers")
local math = { floor = math.floor } local math = { floor = math.floor }
local helpers = require"vicious.helpers"
local spawn = require"vicious.spawn"
-- }}} -- }}}
@ -55,7 +54,7 @@ end
-- }}} -- }}}
-- {{{ MPD widget type -- {{{ MPD widget type
local function worker(format, warg) function mpd_all.async(format, warg, callback)
-- Fallback values -- Fallback values
local mpd_state = { local mpd_state = {
["{volume}"] = 0, ["{volume}"] = 0,
@ -81,36 +80,34 @@ local function worker(format, warg)
warg and (warg.port or warg[3]) or "6600") warg and (warg.port or warg[3]) or "6600")
-- Get data from MPD server -- Get data from MPD server
local f = io.popen(query .. "|" .. connect) spawn.with_line_callback_with_shell(query .. "|" .. connect, {
for line in f:lines() do stdout = function (line)
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do for k, v in line:gmatch"([%w]+):[%s](.*)$" do
local key = "{" .. k .. "}" local key = "{" .. k .. "}"
if k == "volume" or k == "bitrate" or if k == "volume" or k == "bitrate" or
k == "elapsed" or k == "duration" then k == "elapsed" or k == "duration" then
mpd_state[key] = v and tonumber(v) mpd_state[key] = v and tonumber(v)
elseif k == "repeat" or k == "random" then elseif k == "repeat" or k == "random" then
mpd_state[key] = cbool(v) mpd_state[key] = cbool(v)
elseif k == "state" then elseif k == "state" then
mpd_state[key] = helpers.capitalize(v) mpd_state[key] = helpers.capitalize(v)
elseif k == "Artist" or k == "Title" or elseif k == "Artist" or k == "Title" or
--k == "Name" or k == "file" or --k == "Name" or k == "file" or
k == "Album" or k == "Genre" then k == "Album" or k == "Genre" then
mpd_state[key] = v mpd_state[key] = v
end
end end
end end,
end output_done = function ()
f:close() -- Formatted elapsed and duration
mpd_state["{Elapsed}"], mpd_state["{Duration}"] = format_progress(
-- Formatted elapsed and duration mpd_state["{elapsed}"], mpd_state["{duration}"])
mpd_state["{Elapsed}"], mpd_state["{Duration}"] = format_progress( -- Formatted playing progress percentage
mpd_state["{elapsed}"], mpd_state["{duration}"]) mpd_state["{Progress}"] = format_progress_percentage(
mpd_state["{elapsed}"], mpd_state["{duration}"])
-- Formatted playing progress percentage callback(mpd_state)
mpd_state["{Progress}"] = format_progress_percentage( end })
mpd_state["{elapsed}"], mpd_state["{duration}"])
return mpd_state
end end
-- }}} -- }}}
return setmetatable(mpd_all, { __call = function(_, ...) return worker(...) end }) return helpers.setasyncall(mpd_all)