so so much...

This commit is contained in:
2025-12-22 12:01:01 -08:00
parent a19fe74de1
commit 4e0a5871bd
7 changed files with 1740 additions and 0 deletions

85
startup/99_phoneOS.lua Normal file
View File

@@ -0,0 +1,85 @@
local apps = {}
local containers = loadfile("/libs/containers.lua")()
local focusedapp = nil
_G.app = {}
function _G.app.focusapp(pid)
print("focusing "..pid)
if focusedapp ~= nil and focusedapp.win ~= nil then
focusedapp.win.setVisible(false)
end
focusedapp = apps[pid]
print(focusedapp)
if focusedapp ~= nil and focusedapp.win ~= nil then
focusedapp.win.setVisible(true)
end
end
function _G.app.launch(id)
local w,h = term.getSize()
if not fs.exists(fs.combine("/apps",id)) then return false,"App Not Found" end
local win = window.create(term.native(),1,2,w,h-2,false)
print("loading "..id)
local env = containers.getENV(fs.combine("/apps",id),true, win)
local appobj = {win=win,co=nil,id=id,title=""}
function env.setAppTitle(str) appobj.title=str end
print("loaded "..id)
appobj.co = coroutine.create(function () containers.start(env) end)
local pid = -1
for k=1,#apps+1 do
if apps[k] == nil then
apps[k] = appobj
pid = k
end
end
app.focusapp(pid)
end
local function render()
while true do
local w,h = term.getSize()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.black)
term.clearLine()
term.write(os.date("%I:%M %p"))
local candidate = network.getCandidate()
local right = "id: "..tostring(candidate.id).." dist: "..tostring(math.floor(candidate.distance+0.5)).." m"
if candidate.id == -1 then
right = "disconnected"
end
term.setCursorPos(w-right:len()+1,1)
term.write(right)
sleep()
end
end
local function process()
while true do
local event = {os.pullEvent()}
if focusedapp then
if focusedapp.event then
local success, content = coroutine.resume(focusedapp.co,table.unpack(focusedapp.event))
if success then
focusedapp.event = nil
focusedapp.filter = content
else
app.focusapp(-1)
end
elseif focusedapp.filter == nil or focusedapp.filter == event[1] then
local success, content = coroutine.resume(focusedapp.co,table.unpack(event))
if success then
focusedapp.filter = content
else
app.focusapp(-1)
end
end
end
for k,v in pairs(apps) do
if v.filter == nil or v.filter == event[1] and v.event == nil and not v == focusedapp then
v.event = event
end
end
end
end
print("launching test..")
app.launch("test")
print("launched")
parallel.waitForAny(process,render,network.run)