From 818412da9e93d2b6354b06ffa33a9c6e27c16a72 Mon Sep 17 00:00:00 2001 From: MCorange Date: Sun, 25 Aug 2024 22:56:32 +0300 Subject: [PATCH] :3 --- rtmc.lua | 16 ++++++++++++++-- src/notifier.lua | 16 ++++++++++++++++ src/updater.lua | 7 ++++--- x.py | 3 ++- 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 src/notifier.lua diff --git a/rtmc.lua b/rtmc.lua index 775d1c3..f60da83 100644 --- a/rtmc.lua +++ b/rtmc.lua @@ -336,6 +336,7 @@ end) rawset(__BUNDLER_FILES, "updater", function () local log = require("log"); local json = require("json"); + local notifier = require("notifier"); local _; local updater = {}; updater.__index = updater; @@ -420,12 +421,23 @@ rawset(__BUNDLER_FILES, "updater", function () local fd = fs.open(path, "w"); fd.write(body); fd.close(); + local notif = "Computer #" .. tostring( os.getComputerID() ) .. " updating"; + notifier.notify("default", notif); log.debug("New update written to disk (" .. path .. ")"); end - function updater:notify() - end return updater; end) +rawset(__BUNDLER_FILES, "notifier", function () + local notifier = {}; + notifier.__index = notifier; + function notifier.notify(priority, body) + local headers = { + ["Priority"] = priority; + }; + http.post("https://ntfy.sh/keypadOS_alerts", body, headers); + end + return notifier; +end) if pcall(debug.getlocal, 4, 1) then local exports = {}; for k, v in pairs(__BUNDLER_FILES) do diff --git a/src/notifier.lua b/src/notifier.lua new file mode 100644 index 0000000..ee23e2a --- /dev/null +++ b/src/notifier.lua @@ -0,0 +1,16 @@ + +--- @class Notifier +local notifier = {}; +notifier.__index = notifier; + +--- @param priority "max"|"urgent"|"high"|"default"|"low"|"min" +--- @param body string +function notifier.notify(priority, body) + local headers = { + ["Priority"] = priority; + }; + http.post("https://ntfy.sh/keypadOS_alerts", body, headers); +end + +return notifier; + diff --git a/src/updater.lua b/src/updater.lua index 0cfc7e3..8a77c61 100644 --- a/src/updater.lua +++ b/src/updater.lua @@ -1,5 +1,6 @@ local log = require("log"); local json = require("json"); +local notifier = require("notifier"); --- @class UpdaterEntry --- @field url string @@ -108,11 +109,11 @@ function updater:update(path, url) local fd = fs.open(path, "w"); fd.write(body); fd.close(); + + local notif = "Computer #" .. tostring( os.getComputerID() ) .. " updating"; + notifier.notify("default", notif); log.debug("New update written to disk (" .. path .. ")"); end -function updater:notify() - -- http.post(config.ntfy_url, "Computer #" .. tostring( os.getComputerID() ) .. " updating") -end return updater; diff --git a/x.py b/x.py index 92c4e20..3263724 100755 --- a/x.py +++ b/x.py @@ -4,7 +4,8 @@ FILES= [ "main.lua", "log.lua", "json.lua", - "updater.lua" + "updater.lua", + "notifier.lua" ] VERSION="1.0.0d"