made software app better
This commit is contained in:
@@ -12,9 +12,9 @@ build.writePackage(package_data,"build/"..appid)
|
||||
local meta = {
|
||||
perms = {
|
||||
repo = true,
|
||||
network = false,
|
||||
app = true,
|
||||
http = false,
|
||||
network = true,
|
||||
app = false,
|
||||
http = true,
|
||||
},
|
||||
author = "Ruffles",
|
||||
name = project_name,
|
||||
|
||||
@@ -1 +1,131 @@
|
||||
print("Hello, World!")
|
||||
local basalt = require("globals.basalt")
|
||||
|
||||
local selected_id = nil
|
||||
local install = nil
|
||||
local remove = nil
|
||||
|
||||
local installed_cache = {} -- id -> bool
|
||||
local dirty = true -- UI needs refresh
|
||||
local need_check = nil -- which id to check installed state for
|
||||
|
||||
local main = basalt.getMainFrame()
|
||||
main:setBackground(colors.gray)
|
||||
|
||||
local w, h = term.getSize()
|
||||
local packages = repo.listPackages("apps")
|
||||
|
||||
local list = main:addList{
|
||||
background = colors.black,
|
||||
foreground = colors.white,
|
||||
width = w,
|
||||
height = h - 5,
|
||||
}
|
||||
|
||||
local name_label = main:addLabel{
|
||||
background = colors.black,
|
||||
foreground = colors.white,
|
||||
y = h - 4,
|
||||
text = "None Selected",
|
||||
}
|
||||
|
||||
local install_button = main:addButton{
|
||||
background = colors.gray,
|
||||
foreground = colors.white,
|
||||
y = h - 3,
|
||||
text = "",
|
||||
}
|
||||
|
||||
local function populate()
|
||||
list:clear()
|
||||
for k, v in pairs(packages) do
|
||||
list:addItem({ text = v.name, id = k })
|
||||
end
|
||||
end
|
||||
|
||||
local function update_ui()
|
||||
if not selected_id then
|
||||
name_label:setText("None Selected")
|
||||
install_button:setText("")
|
||||
install_button:setBackground(colors.gray)
|
||||
return
|
||||
end
|
||||
|
||||
name_label:setText(packages[selected_id].name)
|
||||
|
||||
local is_installed = installed_cache[selected_id]
|
||||
if is_installed == nil then
|
||||
-- we haven't checked yet
|
||||
install_button:setText("Checking...")
|
||||
install_button:setBackground(colors.lightGray)
|
||||
return
|
||||
end
|
||||
|
||||
if is_installed then
|
||||
install_button:setText("Remove")
|
||||
install_button:setBackground(colors.red)
|
||||
else
|
||||
install_button:setText("Install")
|
||||
install_button:setBackground(colors.green)
|
||||
end
|
||||
end
|
||||
|
||||
list:onSelect(function(_, _, item)
|
||||
selected_id = item.id
|
||||
need_check = selected_id
|
||||
dirty = true
|
||||
end)
|
||||
|
||||
install_button:onClick(function()
|
||||
if not selected_id then return end
|
||||
local is_installed = installed_cache[selected_id]
|
||||
if is_installed == nil then return end
|
||||
|
||||
if is_installed then
|
||||
remove = selected_id
|
||||
else
|
||||
install = selected_id
|
||||
end
|
||||
end)
|
||||
|
||||
populate()
|
||||
need_check = selected_id
|
||||
update_ui()
|
||||
|
||||
local function mainloop()
|
||||
while true do
|
||||
if need_check then
|
||||
local id = need_check
|
||||
need_check = nil
|
||||
installed_cache[id] = repo.appInstalled(id)
|
||||
dirty = true
|
||||
end
|
||||
|
||||
if install then
|
||||
local id = install
|
||||
install = nil
|
||||
|
||||
local app = repo.getPackageData("apps", id)
|
||||
repo.installApp(app)
|
||||
installed_cache[id] = true
|
||||
dirty = true
|
||||
end
|
||||
|
||||
if remove then
|
||||
local id = remove
|
||||
remove = nil
|
||||
|
||||
repo.uninstallApp(id)
|
||||
installed_cache[id] = false
|
||||
dirty = true
|
||||
end
|
||||
|
||||
if dirty then
|
||||
dirty = false
|
||||
update_ui()
|
||||
end
|
||||
|
||||
sleep(0.05)
|
||||
end
|
||||
end
|
||||
|
||||
parallel.waitForAll(function() basalt.run() end, mainloop)
|
||||
|
||||
Reference in New Issue
Block a user