local Y=require("yaru.core") local gfx=require("yaru.gfx") local ui=require("yaru.ui") local computer=require("computer") local component=require("component") local fs=require("filesystem") local unicode=require("unicode") local M={} local function bar(x,y,w,frac,fg,bg) frac=math.max(0,math.min(1,frac)) local n=math.floor(w*frac+.5) gfx.fill(x,y,w,1,bg) if n>0 then gfx.fill(x,y,n,1,fg)end end function M.powerDialog() Y.dialog{title="Power Off",text="Choose what the computer should do.", buttons={{"Cancel"},{"Log Out",function()Y.quit("logout")end}, {"Restart",function()Y.quit("reboot")end,"suggested"}, {"Power Off",function()Y.quit("shutdown")end,"destructive"}}} end function M.open() local W=Y.size() local pw,ph=40,17 local x0,y0=W-pw-1,3 local o={kind="quick",tick=function()gfx.damage(x0,y0-1,pw+1,ph+3)end,tickInterval=2} local boot=fs.get("/") local dTotal=boot and boot.spaceTotal()or 0 local dUsed=boot and boot.spaceUsed()or 0 local function pill(x,y,label,on,fn) local t=Y.theme local bg=on and t.accent or t.menuHi local fg=on and 0xFFFFFF or t.menuFg ui.pill(x,y,18,bg) gfx.text(x+2,y,ui.trunc(label,15),fg,bg) o.hits[#o.hits+1]={x,y,18,1,fn} end function o.draw() local t=Y.theme local x,y=x0,y0 ui.card(x,y,pw,ph,t.menu) o.hits[#o.hits+1]={x,y,pw,ph,function()end} local maxE=computer.maxEnergy() local e=maxE>0 and string.format("ϟ %d%%",math.floor(computer.energy()*100/maxE))or"ϟ —" gfx.text(x+2,y+1,e,t.menuFg,t.menu) ui.button(o,x+pw-22,y+1,"☼",function()Y.closeOverlay();Y.launch("settings")end,nil,3) ui.button(o,x+pw-18,y+1,"Lock",function()Y.closeOverlay();Y.lazy("lock").open(Y.cfg.password~=nil)end,nil,6) ui.button(o,x+pw-11,y+1,"⌽ Off…",function()Y.closeOverlay();M.powerDialog()end,nil,9) local net=component.isAvailable("internet")and"Internet"or component.isAvailable("modem")and"Network"or"Offline" pill(x+2,y+3,"⇅ "..net,net~="Offline",function() Y.notify("Network",net=="Offline"and"No network card installed"or(net.." card is available")) end) pill(x+20,y+3,"♪ Sound",Y.cfg.beeps,function()Y.cfg.beeps=not Y.cfg.beeps;Y.saveConfig()end) pill(x+2,y+5,"◐ Dark Style",Y.cfg.dark,function()Y.cfg.dark=not Y.cfg.dark;Y.saveConfig();Y.applyTheme()end) pill(x+20,y+5,"☾ Do Not Disturb",Y.cfg.dnd,function()Y.cfg.dnd=not Y.cfg.dnd;Y.saveConfig()end) pill(x+2,y+7,"▮ RAM in panel",Y.cfg.showMemory,function()Y.cfg.showMemory=not Y.cfg.showMemory;Y.saveConfig()end) pill(x+20,y+7,"◉ Screen Lock",(Y.cfg.blank or 0)>0,function() Y.cfg.blank=(Y.cfg.blank or 0)>0 and 0 or 5;Y.saveConfig() end) local total,free=computer.totalMemory(),computer.freeMemory() gfx.text(x+2,y+9,"Memory",t.menuFg,t.menu) local ms=string.format("%s / %s",ui.size(total-free),ui.size(total)) gfx.text(x+pw-2-unicode.len(ms),y+9,ms,t.dim,t.menu) ui.progress(x+2,y+10,pw-4,(total-free)/total,(total-free)/total>.85 and t.danger or t.accent) gfx.text(x+2,y+11,"Disk",t.menuFg,t.menu) local ds=string.format("%s / %s",ui.size(dUsed),ui.size(dTotal)) gfx.text(x+pw-2-unicode.len(ds),y+11,ds,t.dim,t.menu) ui.progress(x+2,y+12,pw-4,dTotal>0 and dUsed/dTotal or 0,t.accent) gfx.text(x+2,y+14,"Uptime "..string.format("%d:%02d",computer.uptime()//3600,computer.uptime()//60%60),t.dim,t.menu) ui.button(o,x+pw-11,y+14,"Log Out…",function()Y.closeOverlay();M.powerDialog()end,"flat",9) end function o.touch()Y.closeOverlay()return true end function o.key(_,char,code)if code==Y.K.esc then Y.closeOverlay()end end Y.openOverlay(o) return o end return M