|
1 | 1 | -- Vicious module initialization |
2 | 2 | -- Copyright (C) 2009 Lucas de Vries <[email protected]> |
3 | 3 | -- Copyright (C) 2009-2013 Adrian C. (anrxc) <[email protected]> |
4 | | --- Copyright (C) 2011 Joerg T. (Mic92) <[email protected]> |
| 4 | +-- Copyright (C) 2011-2017 Joerg Thalheim <[email protected]> |
5 | 5 | -- Copyright (C) 2012 Arvydas Sidorenko <[email protected]> |
6 | | --- Copyright (C) 2012 Jörg Thalheim <[email protected]> |
7 | 6 | -- Copyright (C) 2013 Dodo <[email protected]> |
8 | | --- Copyright (C) 2013-2014,2017 Jörg Thalheim <[email protected]> |
9 | 7 | -- Copyright (C) 2014 blastmaster <[email protected]> |
10 | | --- Copyright (C) 2015 Daniel Hahler <git@thequod.de> |
| 8 | +-- Copyright (C) 2015,2019 Daniel Hahler <github@thequod.de> |
11 | 9 | -- Copyright (C) 2017 James Reed <[email protected]> |
12 | | --- Copyright (C) 2017 Joerg Thalheim <[email protected]> |
13 | 10 | -- Copyright (C) 2017 getzze <[email protected]> |
14 | 11 | -- Copyright (C) 2017 mutlusun <[email protected]> |
15 | 12 | -- Copyright (C) 2018 Beniamin Kalinowski <[email protected]> |
16 | | --- Copyright (C) 2018 Nguyễn Gia Phong <[email protected]> |
17 | | --- Copyright (C) 2019 Daniel Hahler <[email protected]> |
| 13 | +-- Copyright (C) 2018,2020 Nguyễn Gia Phong <[email protected]> |
18 | 14 | -- |
19 | 15 | -- This file is part of Vicious. |
20 | 16 | -- |
@@ -322,16 +318,39 @@ function vicious.activate(widget) |
322 | 318 | end |
323 | 319 | -- }}} |
324 | 320 |
|
325 | | --- {{{ Get custom widget format data |
326 | | -function vicious.call(myw, format, warg) |
327 | | - local mydata = myw(format, warg) |
| 321 | +-- {{{ Get formatted data from a synchronous widget type |
| 322 | +function vicious.call(wtype, format, warg) |
| 323 | + if wtype.async ~= nil then return nil end |
| 324 | + |
| 325 | + local data = wtype(format, warg) |
328 | 326 | if type(format) == "string" then |
329 | | - return helpers.format(format, mydata) |
| 327 | + return helpers.format(format, data) |
330 | 328 | elseif type(format) == "function" then |
331 | | - return format(myw, mydata) |
| 329 | + return format(wtype, data) |
332 | 330 | end |
333 | 331 | end |
334 | 332 | -- }}} |
335 | 333 |
|
| 334 | +-- {{{ Get formatted data from an asynchronous widget type |
| 335 | +function vicious.call_async(wtype, format, warg, callback) |
| 336 | + if wtype.async == nil then |
| 337 | + callback() |
| 338 | + return |
| 339 | + end |
| 340 | + |
| 341 | + wtype.async( |
| 342 | + format, warg, |
| 343 | + function (data) |
| 344 | + if type(format) == "string" then |
| 345 | + callback(helpers.format(format, data)) |
| 346 | + elseif type(format) == "function" then |
| 347 | + callback(format(wtype, data)) |
| 348 | + else |
| 349 | + callback() |
| 350 | + end |
| 351 | + end) |
| 352 | +end |
| 353 | +-- }}} |
| 354 | + |
336 | 355 | return vicious |
337 | 356 | -- }}} |
0 commit comments