Compare commits

...

10 Commits

Author SHA1 Message Date
ebf3f8a35a
:3 2024-08-26 00:18:19 +03:00
63704f0447
:3 2024-08-26 00:18:11 +03:00
59dc5edde5
:3 2024-08-25 23:56:48 +03:00
4df6073f9c
:3 2024-08-25 23:52:04 +03:00
dfa9e305ab
:3 2024-08-25 23:48:10 +03:00
85dac18494
:3 added bindings for bootloader lib 2024-08-25 23:44:09 +03:00
2b744a5813
added exports to modules 2024-08-25 23:31:35 +03:00
ffa88f010c
:3 2024-08-25 23:21:31 +03:00
51b6b7fc95
:3 2024-08-25 23:19:12 +03:00
efc78c87b7
:3 2024-08-25 23:16:54 +03:00
7 changed files with 71 additions and 9 deletions

23
bindings.lua Normal file
View File

@ -0,0 +1,23 @@
--- @class Exports
--- @field log Logger
--- @field updater Updater
--- @field notifier Notifier
--- @field json JsonParser
--- @class Logger
--- @field error fun(...)
--- @field warn fun(...)
--- @field info fun(...)
--- @field debug fun(...)
--- @class Updater
--- @field addEntry fun(self: Updater, path: string, branch: string, url: string)
--- @class JsonParser
--- @field decode fun(s: string): table
--- @field encode fun(s: table): string
--- @class Notifier
--- @field notify fun(priority: "1"|"2"|"3"|"4"|"5", body: string)

View File

@ -13,6 +13,8 @@ end
rawset(__BUNDLER_FILES, "main", function () rawset(__BUNDLER_FILES, "main", function ()
local updater = require("updater"); local updater = require("updater");
local log = require("log"); local log = require("log");
local notifier = require("notifier")
local json = require("json")
local MODULE_NAME = "keypadOS"; local MODULE_NAME = "keypadOS";
local MODULE_URL = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/keypad/keypadOS.lua"; local MODULE_URL = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/keypad/keypadOS.lua";
if not __VERSION then if not __VERSION then
@ -28,7 +30,20 @@ rawset(__BUNDLER_FILES, "main", function ()
log.info("Starting bootloader (" .. __VERSION .. ")"); log.info("Starting bootloader (" .. __VERSION .. ")");
local upd = updater.new(); local upd = updater.new();
upd:addEntry(MODULE_NAME .. ".lua", "keypad", MODULE_URL); upd:addEntry(MODULE_NAME .. ".lua", "keypad", MODULE_URL);
parallel.waitForAny(function() updaterLoop(upd) end, require(MODULE_NAME)) local lib_exports = {
log = log,
updater = upd,
notifier = notifier,
json = json
};
parallel.waitForAny(
function()
updaterLoop(upd)
end,
function ()
require(MODULE_NAME).main(lib_exports);
end
);
end end
local mod = {}; local mod = {};
mod.main = _start; mod.main = _start;
@ -385,7 +400,7 @@ rawset(__BUNDLER_FILES, "updater", function ()
return false; return false;
end end
local body, berr = req.readAll(); local body, berr = req.readAll();
if not req then if not body then
log.error("Updater:check: Could not get body of request: " .. berr); log.error("Updater:check: Could not get body of request: " .. berr);
return false; return false;
end end
@ -401,6 +416,7 @@ rawset(__BUNDLER_FILES, "updater", function ()
log.debug("Commit hash matches"); log.debug("Commit hash matches");
log.debug(data[1].sha .. " (old) => (new) " .. self.curr_commit_hash); log.debug(data[1].sha .. " (old) => (new) " .. self.curr_commit_hash);
end end
write(".");
return false; return false;
end end
function updater:update(path, url) function updater:update(path, url)
@ -425,7 +441,7 @@ rawset(__BUNDLER_FILES, "updater", function ()
fd.write(body); fd.write(body);
fd.close(); fd.close();
local notif = "Computer #" .. tostring( os.getComputerID() ) .. " updating"; local notif = "Computer #" .. tostring( os.getComputerID() ) .. " updating";
notifier.notify("default", notif); notifier.notify("5", notif);
log.debug("New update written to disk (" .. path .. ")"); log.debug("New update written to disk (" .. path .. ")");
end end
return updater; return updater;

View File

@ -22,6 +22,7 @@
-- SOFTWARE. -- SOFTWARE.
-- --
--- @class JsonParser
local json = { _version = "0.1.2" } local json = { _version = "0.1.2" }
------------------------------------------------------------------------------- -------------------------------------------------------------------------------

View File

@ -1,3 +1,5 @@
--- @class Logger
local log = {}; local log = {};
log.__index = log; log.__index = log;

View File

@ -1,5 +1,7 @@
local updater = require("updater"); local updater = require("updater");
local log = require("log"); local log = require("log");
local notifier = require("notifier")
local json = require("json")
local MODULE_NAME = "keypadOS"; local MODULE_NAME = "keypadOS";
local MODULE_URL = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/keypad/keypadOS.lua"; local MODULE_URL = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/keypad/keypadOS.lua";
@ -8,6 +10,9 @@ if not __VERSION then
__VERSION = "DEV"; __VERSION = "DEV";
end end
--- @param upd Updater --- @param upd Updater
local function updaterLoop(upd) local function updaterLoop(upd)
while true do while true do
@ -20,7 +25,23 @@ local function _start()
log.info("Starting bootloader (" .. __VERSION .. ")"); log.info("Starting bootloader (" .. __VERSION .. ")");
local upd = updater.new(); local upd = updater.new();
upd:addEntry(MODULE_NAME .. ".lua", "keypad", MODULE_URL); upd:addEntry(MODULE_NAME .. ".lua", "keypad", MODULE_URL);
parallel.waitForAny(function() updaterLoop(upd) end, require(MODULE_NAME))
--- @type Exports
local lib_exports = {
log = log,
updater = upd,
notifier = notifier,
json = json
};
parallel.waitForAny(
function()
updaterLoop(upd)
end,
function ()
require(MODULE_NAME).main(lib_exports);
end
);
end end
local mod = {}; local mod = {};

View File

@ -3,7 +3,7 @@
local notifier = {}; local notifier = {};
notifier.__index = notifier; notifier.__index = notifier;
--- @param priority "max"|"urgent"|"high"|"default"|"low"|"min" --- @param priority "1"|"2"|"3"|"4"|"5"
--- @param body string --- @param body string
function notifier.notify(priority, body) function notifier.notify(priority, body)
local headers = { local headers = {

View File

@ -66,11 +66,10 @@ function updater:check(branch)
end end
local body, berr = req.readAll(); local body, berr = req.readAll();
if not req then if not body then
log.error("Updater:check: Could not get body of request: " .. berr); log.error("Updater:check: Could not get body of request: " .. berr);
return false; return false;
end end
local data = json.decode(body); local data = json.decode(body);
if self.curr_commit_hash == "" then if self.curr_commit_hash == "" then
log.debug("No commit hash found, setting"); log.debug("No commit hash found, setting");
@ -84,7 +83,7 @@ function updater:check(branch)
log.debug("Commit hash matches"); log.debug("Commit hash matches");
log.debug(data[1].sha .. " (old) => (new) " .. self.curr_commit_hash); log.debug(data[1].sha .. " (old) => (new) " .. self.curr_commit_hash);
end end
write(".");
return false; return false;
end end
@ -114,7 +113,7 @@ function updater:update(path, url)
fd.close(); fd.close();
local notif = "Computer #" .. tostring( os.getComputerID() ) .. " updating"; local notif = "Computer #" .. tostring( os.getComputerID() ) .. " updating";
notifier.notify("default", notif); notifier.notify("5", notif);
log.debug("New update written to disk (" .. path .. ")"); log.debug("New update written to disk (" .. path .. ")");
end end