Lots of shit

This commit is contained in:
2025-06-02 10:23:40 +03:00
parent f1b31c5c3e
commit 42b7d798e1
68 changed files with 11580 additions and 516 deletions

198
base_apps/App Store.lua Normal file
View File

@@ -0,0 +1,198 @@
local basalt = require("/lib/basalt")
local main = basalt.getMainFrame()
local latest_apps_json = {}
function http_get(url)
local req = http.get(url)
local resp = req.readAll()
req.close()
return resp
end
local app_views = {}
local y = 2
function add_app(name, colour, url, file, installed, upgradeable, app_remote_version, app_remote_path)
local frame = main:addFrame()
:setBackground(colours.lightGrey)
:setSize(26, 3)
:setPosition(1, y)
frame:addFrame()
:setPosition(1, 1)
:setSize(1, 3)
:setBackground(colours[colour])
frame:addLabel()
:setPosition(3, 2)
:setText(name)
local install_btn = frame:addButton()
:setPosition(15, 2)
:setSize(10, 1)
:setBackground(colours.grey)
:setForeground(colours.black)
:onClick(function(install_btn)
local current_manifest = {}
local manifest_file_content = ""
local mf_handle = fs.open("/app_manifest.json", "r")
if mf_handle then
manifest_file_content = mf_handle.readAll()
mf_handle.close()
end
if manifest_file_content ~= "" then
local unserialised_data = textutils.unserialiseJSON(manifest_file_content)
if type(unserialised_data) == "table" then
current_manifest = unserialised_data
else
end
else
end
if installed then
if upgradeable then
local app_content = http_get(url)
local app_file_handle = fs.open(file, "w")
if app_file_handle then
app_file_handle.write(app_content)
app_file_handle.close()
current_manifest[name] = { version = app_remote_version, path = app_remote_path }
else
end
else
local delete_success = fs.delete(file)
if delete_success then
current_manifest[name] = nil
else
current_manifest[name] = nil
end
end
else
local app_content = http_get(url)
local app_file_handle = fs.open(file, "w")
if app_file_handle then
app_file_handle.write(app_content)
app_file_handle.close()
current_manifest[name] = { version = app_remote_version, path = app_remote_path }
else
end
end
local serialized_manifest_to_write = textutils.serialiseJSON(current_manifest)
local mf_handle_write = fs.open("/app_manifest.json", "w")
if mf_handle_write then
mf_handle_write.write(serialized_manifest_to_write)
mf_handle_write.close()
else
end
refresh()
end)
table.insert(app_views, frame)
if installed then
install_btn:setText("Remove")
install_btn:setBackground(colours.red)
else
install_btn:setText("Install")
end
if upgradeable then
install_btn:setText("Update")
install_btn:setBackground(colours.yellow)
end
y = y + 4
end
function refresh()
local apps_json_content = http_get("https://git.mcorangehq.xyz/xomf/slabOS/raw/branch/main/apps.json")
local unserialise_apps_success, unserialised_apps_json = pcall(textutils.unserialiseJSON, apps_json_content)
if not unserialise_apps_success or type(unserialised_apps_json) ~= "table" then
return
end
latest_apps_json = unserialised_apps_json
local local_manifest = {}
local manifest_file_content = ""
local mf_handle = fs.open("/app_manifest.json", "r")
if mf_handle then
manifest_file_content = mf_handle.readAll()
mf_handle.close()
else
end
if manifest_file_content ~= "" then
local unserialised_data = textutils.unserialiseJSON(manifest_file_content)
if type(unserialised_data) == "table" then
local_manifest = unserialised_data
else
end
end
for _, view_frame in pairs(app_views) do
view_frame:destroy()
end
app_views = {}
y = 2
for app_name, app_data in pairs(latest_apps_json) do
local installed = false
local upgradeable = false
if local_manifest[app_name] then
installed = true
if app_data.version ~= local_manifest[app_name].version then
upgradeable = true
else
end
else
end
add_app(app_name, app_data.colour, app_data.url, app_data.path, installed, upgradeable, app_data.version, app_data.path)
end
end
term.setBackgroundColour(colours.white)
term.clear()
refresh()
basalt.run()

36
base_apps/Updater.lua Normal file
View File

@@ -0,0 +1,36 @@
local CURRENT_CLIENT_VERSION = "1.0.0.2"
local INSTALL_PATH = "/"
function http_get(url)
local req = http.get(url)
local resp = req.readAll()
req.close()
return resp
end
print("Device Version: " .. CURRENT_CLIENT_VERSION)
print("Fetching latest version...")
local manifest = http_get("https://git.mcorangehq.xyz/xomf/slabOS/raw/branch/main/version.json")
local manifest_json = textutils.unserialiseJSON(manifest)
print("Latest: " .. manifest_json.version)
if manifest_json.version ~= CURRENT_CLIENT_VERSION then
print("Installing update...")
for path,url in pairs(manifest_json.sys_files) do
print("Writing " .. path)
local file = fs.open(INSTALL_PATH .. path, "w")
file.write( http_get(url) )
file.close()
print("Written.")
end
print("Please reboot your device.")
os.reboot()
else
print("No update availiable.")
end

233
base_apps/eCash.lua Normal file
View File

@@ -0,0 +1,233 @@
local basalt = require("/lib/basalt")
local libcredit = require("/lib/libcredit_mobile")
local username = ""
local main = basalt.getMainFrame()
function show_notification(status)
local notifFrame = main:addFrame():setSize(26, 4):setBackground(colours.grey)
notifFrame:addButton():setText("Dismiss"):setSize(26, 1):setPosition(1, 4):onClick(function()
notifFrame:destroy()
end)
local label = notifFrame:addLabel()
if status then
label
:setText("Transaction successful")
:setPosition(4, 2)
:setBackground(colours.lime)
:setForeground(colours.black)
notifFrame:setBackground(colours.lime)
else
label
:setText("Transaction unsuccessful")
:setPosition(3, 2)
:setBackground(colours.red)
:setForeground(colours.white)
notifFrame:setBackground(colours.red)
end
end
local appFrame = main:addFrame():setVisible(false):setSize(26, 19):setBackground(colours.white)
local requestFrame = main:addFrame():setVisible(false):setSize(26, 19):setBackground(colours.white)
requestFrame:addLabel():setText("Username: "):setPosition(2, 6):setSize(10, 1):setForeground(colours.black)
local request_user_input = requestFrame
:addInput()
:setPosition(12, 6)
:setSize(12, 1)
:setBackground(colours.lightGrey)
:setForeground(colours.black)
:setText("")
requestFrame:addLabel():setText("Amount:   "):setPosition(2, 8):setSize(10, 1):setForeground(colours.black)
local request_amount_input = requestFrame
:addInput()
:setPosition(12, 8)
:setSize(12, 1)
:setBackground(colours.lightGrey)
:setForeground(colours.black)
:setText("")
requestFrame
:addButton()
:setText("Request")
:setPosition(7, 15)
:setSize(12, 3)
:setBackground(colours.blue)
:setForeground(colours.white)
:onClick(function(request_btn)
request_btn:setBackground(colours.black)
request_btn:setText("Pending")
local target_usr = request_user_input:getText()
local target_amount = request_amount_input:getText()
target_amount = tonumber(target_amount:match("^%d+$"))
if not target_amount or target_amount <= 0 then
show_notification(false)
request_btn:setBackground(colours.blue)
request_btn:setText("Request")
return
end
libcredit.addTransaction(target_usr, target_amount, username .. " [ecash]", username, function(successful)
request_btn:setBackground(colours.blue)
request_btn:setText("Request")
show_notification(successful)
refresh_ui()
appFrame:setVisible(true)
requestFrame:setVisible(false)
if successful then
request_amount_input:setText("")
request_user_input:setText("")
end
end)
end)
local sendFrame = main:addFrame():setVisible(false):setSize(26, 19):setBackground(colours.white)
sendFrame:addLabel():setText("Recipient: "):setPosition(2, 6):setSize(10, 1):setForeground(colours.black)
local send_user_input = sendFrame
:addInput()
:setPosition(12, 6)
:setSize(12, 1)
:setBackground(colours.lightGrey)
:setForeground(colours.black)
:setText("")
sendFrame:addLabel():setText("Amount:   "):setPosition(2, 8):setSize(10, 1):setForeground(colours.black)
local send_amount_input = sendFrame
:addInput()
:setPosition(12, 8)
:setSize(12, 1)
:setBackground(colours.lightGrey)
:setForeground(colours.black)
:setText("")
sendFrame
:addButton()
:setText("Send")
:setPosition(7, 15)
:setSize(12, 3)
:setBackground(colours.blue)
:setForeground(colours.white)
:onClick(function(send_btn)
send_btn:setBackground(colours.black)
send_btn:setText("Pending")
local target_usr = send_user_input:getText()
local target_amount = send_amount_input:getText()
target_amount = tonumber(target_amount:match("^%d+$"))
if not target_amount or target_amount <= 0 then
show_notification(false)
send_btn:setBackground(colours.blue)
send_btn:setText("Send")
return
end
libcredit.addTransaction(username, target_amount, target_usr .. " [ecash]", target_usr, function(successful)
send_btn:setBackground(colours.blue)
send_btn:setText("Send")
show_notification(successful)
refresh_ui()
appFrame:setVisible(true)
sendFrame:setVisible(false)
if successful then
send_amount_input:setText("")
send_user_input:setText("")
end
end)
end)
local cash_label =
appFrame:addBigFont():setText("__G"):setPosition(6, 2):setBackground(colours.white):setForeground(colours.black)
local request_cash = appFrame
:addButton()
:setText("Request")
:setPosition(8, 10)
:setSize(10, 3)
:setBackground(colours.green)
:setForeground(colours.white)
:onClick(function()
requestFrame:setVisible(true)
appFrame:setVisible(false)
end)
local send_cash = appFrame
:addButton()
:setText("Send")
:setPosition(8, 15)
:setSize(10, 3)
:setBackground(colours.orange)
:setForeground(colours.white)
:onClick(function()
sendFrame:setVisible(true)
appFrame:setVisible(false)
end)
function refresh_ui()
libcredit.getCredit(username, function(amount)
local amount_str = amount .. "G"
cash_label:setText(amount_str)
if #amount_str < 6 then
cash_label:setPosition(6 - (#amount_str / 4) - 1, 2)
else
cash_label:setSize(26, 4)
cash_label:setPosition(1, 2)
end
end)
end
local login = main:addFrame():setBackground(colours.grey):setPosition(1, 1):setSize(26, 19)
login:addLabel():setText("Username: "):setPosition(2, 3):setSize(10, 1):setForeground(colours.white)
local usernameInput = login
:addInput()
:setPosition(12, 3)
:setSize(12, 1)
:setBackground(colours.lightGrey)
:setForeground(colours.black)
:setText("")
local loginButton = login
:addButton()
:setText("Login")
:setPosition(9, 15)
:setSize(8, 3)
:setBackground(colours.blue)
:setForeground(colours.white)
:onClick(function()
username = usernameInput:getText()
if not fs.exists("/.usrcache") then
local file = fs.open("/.usrcache", "w")
file.write(username)
file.close()
end
login:setVisible(false)
appFrame:setVisible(true)
refresh_ui()
end)
if fs.exists("/.usrcache") then
local file = fs.open("/.usrcache", "r")
local username = file.readLine()
file.close()
usernameInput:setText(username)
end
basalt.run()