local shell=require("shell") local computer=require("computer") local fs=require("filesystem") local args,opts=shell.parse(...) local MARK="/etc/yaru.crash" local function unload() for k in pairs(package.loaded)do if k:match("^yaru%.")then package.loaded[k]=nil end end end local nologin=opts.nologin or opts.n while true do unload() local Y=require("yaru.core") local f=io.open(MARK,"w")if f then f:write("starting")f:close()end local ok,res=xpcall(Y.run,debug.traceback,{nologin=nologin,onStarted=function()fs.remove(MARK)end}) fs.remove(MARK) unload() if not ok then local lf=io.open("/tmp/desktop.log","a")if lf then lf:write(tostring(res),"\n")lf:close()end local mf=io.open("/tmp/.desktop_msg","w") if mf then mf:write("Desktop error: "..tostring(res):match("[^\n]*").." (details: /tmp/desktop.log)")mf:close()end local gpu=require("component").gpu gpu.setBackground(0)gpu.setForeground(0xFFFFFF) local w,h=gpu.getResolution() gpu.fill(1,1,w,h," ") require("term").setCursor(1,1) io.stderr:write("The desktop stopped with an error:\n"..tostring(res).."\n") io.write("Falling back to the text shell. Run 'desktop' to try again.\n") return 1 end if res=="reboot"then computer.shutdown(true) elseif res=="shutdown"then computer.shutdown() elseif res=="restart-shell"then nologin=true else nologin=false if res=="exit"then return 0 end end end