From 9df723775510ddfd828a1c237737d1467eeb1b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Mon, 14 Sep 2020 16:45:49 +0700 Subject: [PATCH] Separate vicious.call into sync and async versions --- init.lua | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/init.lua b/init.lua index 7408fe5..d8a293a 100644 --- a/init.lua +++ b/init.lua @@ -1,20 +1,16 @@ -- Vicious module initialization -- Copyright (C) 2009 Lucas de Vries -- Copyright (C) 2009-2013 Adrian C. (anrxc) --- Copyright (C) 2011 Joerg T. (Mic92) +-- Copyright (C) 2011-2017 Joerg Thalheim -- Copyright (C) 2012 Arvydas Sidorenko --- Copyright (C) 2012 Jörg Thalheim -- Copyright (C) 2013 Dodo --- Copyright (C) 2013-2014,2017 Jörg Thalheim -- Copyright (C) 2014 blastmaster --- Copyright (C) 2015 Daniel Hahler +-- Copyright (C) 2015,2019 Daniel Hahler -- Copyright (C) 2017 James Reed --- Copyright (C) 2017 Joerg Thalheim -- Copyright (C) 2017 getzze -- Copyright (C) 2017 mutlusun -- Copyright (C) 2018 Beniamin Kalinowski --- Copyright (C) 2018 Nguyễn Gia Phong --- Copyright (C) 2019 Daniel Hahler +-- Copyright (C) 2018,2020 Nguyễn Gia Phong -- -- This file is part of Vicious. -- @@ -322,16 +318,39 @@ function vicious.activate(widget) end -- }}} --- {{{ Get custom widget format data -function vicious.call(myw, format, warg) - local mydata = myw(format, warg) +-- {{{ Get formatted data from a synchronous widget type +function vicious.call(wtype, format, warg) + if wtype.async ~= nil then return nil end + + local data = wtype(format, warg) if type(format) == "string" then - return helpers.format(format, mydata) + return helpers.format(format, data) elseif type(format) == "function" then - return format(myw, mydata) + return format(wtype, data) end end -- }}} +-- {{{ Get formatted data from an asynchronous widget type +function vicious.call_async(wtype, format, warg, callback) + if wtype.async == nil then + callback() + return + end + + wtype.async( + format, warg, + function (data) + if type(format) == "string" then + callback(helpers.format(format, data)) + elseif type(format) == "function" then + callback(format(wtype, data)) + else + callback() + end + end) +end +-- }}} + return vicious -- }}}