From 260ec67225827ee405f213689f4dddf612bc34c2 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Wed, 1 Sep 2021 10:06:43 +0300 Subject: [PATCH] add get_system_info function --- README.md | 7 ++++--- README_ru.md | 3 ++- community/battery-widget.lua | 9 +++++---- community/sys-info-widget.lua | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 community/sys-info-widget.lua diff --git a/README.md b/README.md index 9e63817..33a19fc 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,8 @@ If the first argument of the dialog contains two lines separated by `\n`, the se ``` ui:show_context_menu({ - { "share", "Menu item 1" } - { "copy", "Menu item 2" } + { "share", "Menu item 1" }, + { "copy", "Menu item 2" }, { "trash", "Menu item 3" }, }) ``` @@ -86,7 +86,8 @@ When you click on any menu item, the collab `on_context_menu_click(item_idx)` wi * `system:share_text(string)` - opens the "Share" system dialog; * `system:get_lang()` - returns the language selected in the system; * `system:get_tz_offset()` - returns TimeZone offset in seconds; -* `system:get_battery_info()` - return table with battery info. +* `system:get_battery_info()` - returns table with battery info; +* `system:get_system_info()` - returns table with system info; The result of executing a shell command is sent to the `on_shell_result(string)` callback. diff --git a/README_ru.md b/README_ru.md index a773279..87f2529 100644 --- a/README_ru.md +++ b/README_ru.md @@ -86,7 +86,8 @@ ui:show_context_menu({ * `system:share_text(string)` - открывает системный диалог "Поделиться"; * `system:get_lang()` - возвращает выбранный в системе язык; * `system:get_tz_offset()` - возвращает time zone offset в секундах. -* `system:get_battery_info()` - возвращает таблицу с информацией о состоянии батареи. +* `system:get_battery_info()` - возвращает таблицу с информацией о состоянии батареи; +* `system:get_system_info()` - возвращает таблицу с различной системной информацией. Результат выполнения shell-команды приходит в колбек `on_shell_result(string)`. diff --git a/community/battery-widget.lua b/community/battery-widget.lua index a000b87..403f8d8 100644 --- a/community/battery-widget.lua +++ b/community/battery-widget.lua @@ -1,9 +1,10 @@ -- name = "Battery info" -ticks = 0 +ticks = -1 function on_tick() -- Update one time per 10 seconds + ticks = ticks + 1 if ticks % 10 ~= 0 then return end @@ -19,12 +20,12 @@ function stringify_table(tab) local new_tab = {} for k,v in pairs(tab) do - table.insert(new_tab, k:capitalize()..": "..tostring(v)) + table.insert(new_tab, capitalize(k)..": "..tostring(v)) end return new_tab end -function string:capitalize() - return (self:gsub("^%l", string.upper)) +function capitalize(string) + return string:gsub("^%l", string.upper) end diff --git a/community/sys-info-widget.lua b/community/sys-info-widget.lua new file mode 100644 index 0000000..cc7b0d7 --- /dev/null +++ b/community/sys-info-widget.lua @@ -0,0 +1,32 @@ +-- name = "System info" + +ticks = -1 + +function on_tick() + -- Update one time per 10 seconds + ticks = ticks + 1 + if ticks % 10 ~= 0 then + return + end + + ticks = 0 + + local info = system:get_system_info() + local strings = stringify_table(info) + + ui:show_lines(strings) +end + +function stringify_table(tab) + local new_tab = {} + + for k,v in pairs(tab) do + table.insert(new_tab, capitalize(k):replace("_", " ")..": "..tostring(v)) + end + + return new_tab +end + +function capitalize(string) + return string:gsub("^%l", string.upper) +end