add get_system_info function
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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)`.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
32
community/sys-info-widget.lua
Normal file
32
community/sys-info-widget.lua
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user