add apps module

This commit is contained in:
Evgeny
2021-08-19 15:41:40 +03:00
parent 5b8d6b57ff
commit f2e670b9a8
9 changed files with 77 additions and 8 deletions

View File

@@ -77,7 +77,6 @@ When you click on any menu item, the callback `on_context_menu_click(item_idx, m
# System functions # System functions
* `system:open_app(package_name)` - opens the application by package name;
* `system:open_browser(url)` - opens the specified URL in a browser or application that can handle this type of URL; * `system:open_browser(url)` - opens the specified URL in a browser or application that can handle this type of URL;
* `system:exec(string)` - executes a shell command; * `system:exec(string)` - executes a shell command;
* `system:su(string)` - executes a shell command as root; * `system:su(string)` - executes a shell command as root;
@@ -101,6 +100,20 @@ The result of executing a shell command is sent to the `on_shell_result(string)`
If there is a `arguments_help` field in the widget's metadata, its value will be displayed when editing the widget's arguments. If there is a `arguments_default` field, it will be used to get the default arguments. If there is a `arguments_help` field in the widget's metadata, its value will be displayed when editing the widget's arguments. If there is a `arguments_default` field, it will be used to get the default arguments.
# Application management functions
* `apps:get_list([sort_by])` - returns a table of package names of all installed applications, `sort_by` - sort option (see below);
* `apps:get_name(package)` - returns application name;
* `apps:get_color(package)` - returns the color of the application in #XXXXXXXX format;
* `apps:launch(package)` - launches the application.
Sorting options:
* `abc` - alphabetical (default);
* `launch_count` - by number of launches;
* `launch_time` - by launch time;
* `install_time` - by installation time.
# Network functions # Network functions
* `http:get(url, [id])` - executes an HTTP GET request, id - the request identifier string (see below); * `http:get(url, [id])` - executes an HTTP GET request, id - the request identifier string (see below);
@@ -169,6 +182,7 @@ The standard Lua API is extended with the following features:
* `string:split(delimeter)` - splits the string using the specified delimiter and returns a table; * `string:split(delimeter)` - splits the string using the specified delimiter and returns a table;
* `string:replace(regexp, string)` - replaces the text found by the regular expression with another text; * `string:replace(regexp, string)` - replaces the text found by the regular expression with another text;
* `slice(table, start, end)` - returns the part of the table starting with the `start` index and ending with `end` index;
* `get_index(table, value)` - returns the index of the table element; * `get_index(table, value)` - returns the index of the table element;
* `get_key(table, value)` - returns the key of the table element; * `get_key(table, value)` - returns the key of the table element;
* `round(x, n)` - rounds the number; * `round(x, n)` - rounds the number;

View File

@@ -77,7 +77,6 @@ ui:prepare_context_menu({
# Системные функции # Системные функции
* `system:open_app(package_name)` - открывает приложение, имя пакета которого указано в аргументе;
* `system:open_browser(url)` - открывает указанный URL в браузере или в приложении, умеющем обрабатывать данный тип URL; * `system:open_browser(url)` - открывает указанный URL в браузере или в приложении, умеющем обрабатывать данный тип URL;
* `system:exec(string)` - выполняет shell-команду; * `system:exec(string)` - выполняет shell-команду;
* `system:su(string)` - выполняет shell-команду от имени root; * `system:su(string)` - выполняет shell-команду от имени root;
@@ -101,6 +100,20 @@ ui:prepare_context_menu({
Если в метаданных виджета есть поле `arguments_help`, его значение будет выведено при редактировании аргументов виджета. Если есть поле `arguments_default` - оно будет использовано для получения дефолтовых аргументов. Если в метаданных виджета есть поле `arguments_help`, его значение будет выведено при редактировании аргументов виджета. Если есть поле `arguments_default` - оно будет использовано для получения дефолтовых аргументов.
# Функции управления приложениями
* `apps:get_list([sort_by])` - возвращает таблицу пакетов всех установленных приложений, `sort_by` - вариант сортировки (см. ниже);
* `apps:get_name(package)` - возвращает имя приложения;
* `apps:get_color(package)` - возвращает цвет приложения в формате #XXXXXX;
* `apps:launch(package)` - запускает приложение.
Варианты сортировки:
* `abc` - по алфавиту (по умолчанию);
* `launch_count` - по количеству запусков;
* `launch_time` - по времени запуска;
* `install_time` - по времени установки.
# Сетевые функции # Сетевые функции
* `http:get(url, [id])` - выполняет запрос HTTP GET, id - строка-идентификатор запрос (см. ниже); * `http:get(url, [id])` - выполняет запрос HTTP GET, id - строка-идентификатор запрос (см. ниже);
@@ -169,6 +182,7 @@ AIO Launcher включает в себя интерпретатор LuaJ 3.0.1
* `string:split(delimeter)` - разделяет строку с помощью указанного разделителя и возвращает таблицу; * `string:split(delimeter)` - разделяет строку с помощью указанного разделителя и возвращает таблицу;
* `string:replace(regexp, string)` - заменяет текст, найденный регулярным выражением, на другой текст; * `string:replace(regexp, string)` - заменяет текст, найденный регулярным выражением, на другой текст;
* `slice(table, start, end)` - возвращает часть таблицы, начиная с индекса `start` и заканчивая `end`;
* `get_index(table, value)` - возвращает индекс элемента таблицы; * `get_index(table, value)` - возвращает индекс элемента таблицы;
* `get_key(table, value)` - возвращает ключ элемента таблицы; * `get_key(table, value)` - возвращает ключ элемента таблицы;
* `round(x, n)` - округляет число; * `round(x, n)` - округляет число;

View File

@@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
rm -rf scripts.zip rm -rf scripts.zip scripts.md5
zip -r scripts.zip -j main/*.lua community/*.lua ru/*.lua zip -r scripts.zip -j main/*.lua community/*.lua ru/*.lua
md5sum scripts.zip | cut -d " " -f 1 > scripts.md5 md5sum scripts.zip | cut -d " " -f 1 > scripts.md5

View File

@@ -18,6 +18,17 @@ function string:replace(from, to)
return self:gsub(from, to) return self:gsub(from, to)
end end
function slice(tbl, s, e)
local pos, new = 1, {}
for i = s, e do
new[pos] = tbl[i]
pos = pos + 1
end
return new
end
function get_index(tab, val) function get_index(tab, val)
for index, value in ipairs(tab) do for index, value in ipairs(tab) do
if value == val then if value == val then

View File

@@ -9,5 +9,5 @@ function on_resume()
end end
function on_click(idx) function on_click(idx)
system:open_app(apps_pkgs[idx]) apps:launch(apps_pkgs[idx])
end end

28
samples/apps-sample.lua Normal file
View File

@@ -0,0 +1,28 @@
-- global vars
all_apps = {}
function on_resume()
all_apps = apps:get_list("launch_count")
if (next(all_apps) == nil) then
ui:show_text("The list of apps is not ready yet")
return
end
local apps_names = {}
for k,v in ipairs(all_apps) do
apps_names[k] = get_formatted_name(v)
end
ui:show_table(slice(apps_names, 1, 9), 3)
end
function on_click(idx)
apps:launch(all_apps[idx])
end
-- utils
function get_formatted_name(pkg)
return "<font color=\""..apps:get_color(pkg).."\">"..apps:get_name(pkg).."</color>"
end

View File

@@ -1,11 +1,12 @@
function on_resume() function on_resume()
local table = { local table = {
"1", "20", "30", "12345678", "", "",
"40", "5", "66", "1", "2", "3",
"07", "28", "9", "4", "5", "6",
"7", "8", "9",
} }
ui:show_table(table, 3, true, "Nothing there") ui:show_table(table, 3, true, false, "Nothing there")
end end
function on_click(idx) function on_click(idx)

1
scripts.md5 Normal file
View File

@@ -0,0 +1 @@
68a451374fa801b069e69ed75156c862

BIN
scripts.zip Normal file

Binary file not shown.