This commit is contained in:
Gvidas Juknevičius 2024-08-25 22:56:32 +03:00
parent 6900a19205
commit 818412da9e
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
4 changed files with 36 additions and 6 deletions

View File

@ -336,6 +336,7 @@ end)
rawset(__BUNDLER_FILES, "updater", function () rawset(__BUNDLER_FILES, "updater", function ()
local log = require("log"); local log = require("log");
local json = require("json"); local json = require("json");
local notifier = require("notifier");
local _; local _;
local updater = {}; local updater = {};
updater.__index = updater; updater.__index = updater;
@ -420,12 +421,23 @@ rawset(__BUNDLER_FILES, "updater", function ()
local fd = fs.open(path, "w"); local fd = fs.open(path, "w");
fd.write(body); fd.write(body);
fd.close(); fd.close();
local notif = "Computer #" .. tostring( os.getComputerID() ) .. " updating";
notifier.notify("default", notif);
log.debug("New update written to disk (" .. path .. ")"); log.debug("New update written to disk (" .. path .. ")");
end end
function updater:notify()
end
return updater; return updater;
end) 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 if pcall(debug.getlocal, 4, 1) then
local exports = {}; local exports = {};
for k, v in pairs(__BUNDLER_FILES) do for k, v in pairs(__BUNDLER_FILES) do

16
src/notifier.lua Normal file
View File

@ -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;

View File

@ -1,5 +1,6 @@
local log = require("log"); local log = require("log");
local json = require("json"); local json = require("json");
local notifier = require("notifier");
--- @class UpdaterEntry --- @class UpdaterEntry
--- @field url string --- @field url string
@ -108,11 +109,11 @@ function updater:update(path, url)
local fd = fs.open(path, "w"); local fd = fs.open(path, "w");
fd.write(body); fd.write(body);
fd.close(); fd.close();
local notif = "Computer #" .. tostring( os.getComputerID() ) .. " updating";
notifier.notify("default", notif);
log.debug("New update written to disk (" .. path .. ")"); log.debug("New update written to disk (" .. path .. ")");
end end
function updater:notify()
-- http.post(config.ntfy_url, "Computer #" .. tostring( os.getComputerID() ) .. " updating")
end
return updater; return updater;

3
x.py
View File

@ -4,7 +4,8 @@ FILES= [
"main.lua", "main.lua",
"log.lua", "log.lua",
"json.lua", "json.lua",
"updater.lua" "updater.lua",
"notifier.lua"
] ]
VERSION="1.0.0d" VERSION="1.0.0d"