diff --git a/README.md b/README.md index 0c97759..e0f76db 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,6 @@ When you click on any menu item, the callback `on_context_menu_click(item_idx, m # 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:exec(string)` - executes a shell command; * `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. +# 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 * `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: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_key(table, value)` - returns the key of the table element; * `round(x, n)` - rounds the number; diff --git a/README_ru.md b/README_ru.md index e7c2a9f..3ff6c3f 100644 --- a/README_ru.md +++ b/README_ru.md @@ -77,7 +77,6 @@ ui:prepare_context_menu({ # Системные функции -* `system:open_app(package_name)` - открывает приложение, имя пакета которого указано в аргументе; * `system:open_browser(url)` - открывает указанный URL в браузере или в приложении, умеющем обрабатывать данный тип URL; * `system:exec(string)` - выполняет shell-команду; * `system:su(string)` - выполняет shell-команду от имени root; @@ -101,6 +100,20 @@ ui:prepare_context_menu({ Если в метаданных виджета есть поле `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 - строка-идентификатор запрос (см. ниже); @@ -169,6 +182,7 @@ AIO Launcher включает в себя интерпретатор LuaJ 3.0.1 * `string:split(delimeter)` - разделяет строку с помощью указанного разделителя и возвращает таблицу; * `string:replace(regexp, string)` - заменяет текст, найденный регулярным выражением, на другой текст; +* `slice(table, start, end)` - возвращает часть таблицы, начиная с индекса `start` и заканчивая `end`; * `get_index(table, value)` - возвращает индекс элемента таблицы; * `get_key(table, value)` - возвращает ключ элемента таблицы; * `round(x, n)` - округляет число; diff --git a/gen_zip.sh b/gen_zip.sh index a8aec92..6dd8c05 100755 --- a/gen_zip.sh +++ b/gen_zip.sh @@ -1,5 +1,5 @@ #!/bin/sh -rm -rf scripts.zip +rm -rf scripts.zip scripts.md5 zip -r scripts.zip -j main/*.lua community/*.lua ru/*.lua md5sum scripts.zip | cut -d " " -f 1 > scripts.md5 diff --git a/lib/utils.lua b/lib/utils.lua index fdafb21..16c4257 100644 --- a/lib/utils.lua +++ b/lib/utils.lua @@ -18,6 +18,17 @@ function string:replace(from, to) return self:gsub(from, to) 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) for index, value in ipairs(tab) do if value == val then diff --git a/samples/app-buttons-sample.lua b/samples/app-buttons-sample.lua index 3aeb328..9fc350b 100644 --- a/samples/app-buttons-sample.lua +++ b/samples/app-buttons-sample.lua @@ -9,5 +9,5 @@ function on_resume() end function on_click(idx) - system:open_app(apps_pkgs[idx]) + apps:launch(apps_pkgs[idx]) end diff --git a/samples/apps-sample.lua b/samples/apps-sample.lua new file mode 100644 index 0000000..629afc3 --- /dev/null +++ b/samples/apps-sample.lua @@ -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 ""..apps:get_name(pkg).."" +end diff --git a/samples/table-sample.lua b/samples/table-sample.lua index f4a92af..b02ef7f 100644 --- a/samples/table-sample.lua +++ b/samples/table-sample.lua @@ -1,11 +1,12 @@ function on_resume() local table = { - "1", "20", "30", - "40", "5", "66", - "07", "28", "9", + "12345678", "", "", + "1", "2", "3", + "4", "5", "6", + "7", "8", "9", } - ui:show_table(table, 3, true, "Nothing there") + ui:show_table(table, 3, true, false, "Nothing there") end function on_click(idx) diff --git a/scripts.md5 b/scripts.md5 new file mode 100644 index 0000000..34aec90 --- /dev/null +++ b/scripts.md5 @@ -0,0 +1 @@ +68a451374fa801b069e69ed75156c862 diff --git a/scripts.zip b/scripts.zip new file mode 100644 index 0000000..4932212 Binary files /dev/null and b/scripts.zip differ