Add Timed message widget

This commit is contained in:
Evgeny
2024-11-15 13:10:11 +07:00
parent 0069d1ed67
commit a4960a9b60
2 changed files with 58 additions and 2 deletions

View File

@@ -867,8 +867,6 @@ In order for AIO Launcher to correctly display information about the script in t
-- name = "Covid info" -- name = "Covid info"
-- description = "Cases of illness and death from covid" -- description = "Cases of illness and death from covid"
-- data_source = "https://covid19api.com" -- data_source = "https://covid19api.com"
-- arguments_help = "Specify the country code"
-- arguments_default = "RU"
-- type = "widget" -- type = "widget"
-- foldable = "false" -- foldable = "false"
-- author = "Evgeny Zobnin (zobnin@gmail.com)" -- author = "Evgeny Zobnin (zobnin@gmail.com)"

View File

@@ -0,0 +1,58 @@
-- name = "Timed message"
-- description = "A message that is displayed at a specific time"
-- type = "widget"
-- foldable = "false"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0"
local prefs = require "prefs"
function on_load()
prefs._dialog_order = "message,start_time,end_time"
if not prefs.message then
prefs.message = "Sample message"
end
if not prefs.start_time then
prefs.start_time = "09:00"
end
if not prefs.end_time then
prefs.end_time = "10:00"
end
end
function on_resume()
ui:show_text(prefs.message)
hide_or_show()
end
function on_settings()
prefs:show_dialog()
end
function hide_or_show()
local start_time = convert_to_unix_time(prefs.start_time)
local end_time = convert_to_unix_time(prefs.end_time)
local current_time = os.time()
if current_time > start_time and current_time < end_time then
ui:show_widget()
else
ui:hide_widget()
end
end
function convert_to_unix_time(time_str)
local hour, minute = time_str:match("^(%d%d):(%d%d)$")
hour, minute = tonumber(hour), tonumber(minute)
local current_date = os.date("*t")
current_date.hour = hour
current_date.min = minute
current_date.sec = 0
return os.time(current_date)
end