From 43856c1fc16d04aa94e5db9434cf548798d3d786 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sat, 20 May 2023 09:25:39 +0400 Subject: [PATCH] Add prefs module --- README.md | 24 +++++++++++++++++++++++- samples/prefs-widget.lua | 8 ++++++++ samples/prefs-widget2.lua | 10 ++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 samples/prefs-widget.lua create mode 100644 samples/prefs-widget2.lua diff --git a/README.md b/README.md index 989edbc..a521e0a 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ The type of script is determined by the line (meta tag) at the beginning of the * 4.5.7 - added "fold" and "unfold" actions to the `on_action` callback; * 4.6.0 - added `system:request_location()` and `tasker:send_command()` functions; * 4.7.0 - added `ui:build()` and functions to display search results in different formats; -* 4.7.1 - fontawesome updated to version 6.3.0. +* 4.7.1 - fontawesome updated to version 6.3.0; +* 4.7.4 - added `prefs` module, `settings` module is deprecated. # Widget scripts @@ -451,6 +452,8 @@ All files are created in the subdirectory `/sdcard/Android/data/ru.execbit.aiola ## Settings +_Deprecated in 4.7.4. Use prefs module.` + * `settings:get()` - returns the settings table in an array of words format; * `settings:set(table)` - saves the settings table in an array of words format; * `settings:get_kv()` - returns the settings table in `key=value` format; @@ -461,6 +464,25 @@ User can change settings through the dialog, which is available by clicking on t The standard edit dialog can be replaced by your own if you implement the `on_settings()` function. +## Preferences + +The `prefs` module is designed to permanently store the script settings. It is a simple Lua table which saves to disk all the data written to it. + +You can use it just like any other table with the exception that it cannot be used as a raw array. + +Sample: + +``` +prefs = require "prefs" + +function on_resume() + prefs.new_key = "Hello" + ui:show_lines{prefs.new_key} +end +``` + +The `new_key` will be present in the table even after the AIO Launcher has been restrated. + ## Animation and real time updates _Available only in widget scripts._ diff --git a/samples/prefs-widget.lua b/samples/prefs-widget.lua new file mode 100644 index 0000000..a3ad2de --- /dev/null +++ b/samples/prefs-widget.lua @@ -0,0 +1,8 @@ +prefs = require "prefs" + +prefs._name = "preferencies" + +function on_resume() + prefs.new_key = "Hello" + ui:show_lines{prefs.new_key} +end diff --git a/samples/prefs-widget2.lua b/samples/prefs-widget2.lua new file mode 100644 index 0000000..433bda9 --- /dev/null +++ b/samples/prefs-widget2.lua @@ -0,0 +1,10 @@ +prefs = require("prefs") + +prefs._name = "zzz" + +function on_resume() + prefs[1] = "text Battery level" + prefs[2] = "space" + prefs[3] = "battery" + ui:build(prefs) +end