local Y=require("yaru.core") local gfx=require("yaru.gfx") local ui=require("yaru.ui") local computer=require("computer") local unicode=require("unicode") local M={} function M.open(requirePassword,blank,login) local o={kind="lock",blank=blank,login=login,pw={text="",cur=0},stage=login and"users"or"clock", tickInterval=30} if Y.overlay and Y.overlay.kind=="lock"then Y.overlay.blank=blank gfx.damageAll() return Y.overlay end local function unlock() Y.closeOverlay() Y.lastInput=computer.uptime() if login then Y.notify("Welcome","Super: Activities Ctrl+Alt+T: Terminal Super+A: Applications",{timeout=6})end end local function try() if not requirePassword or require("yaru.sha256").check(Y.cfg.password,o.pw.text)then return unlock()end o.pw.text,o.pw.cur="",0 o.err="Sorry, that didn't work. Please try again." if Y.cfg.beeps then computer.beep(200,0.1)end end local function advance() if o.stage=="users"or o.stage=="clock"then if requirePassword then o.stage="password"else return unlock()end else try()end end function o.tick()gfx.damageAll()end function o.draw() local W,H=Y.size() local t=Y.theme if o.blank then gfx.fill(1,1,W,H,0x000000)return end Y.wallpaper() gfx.blend(1,1,W,H,0,o.stage=="clock"and 0.35 or 0.6) gfx.fill(1,1,W,1,0x000000) local c=Y.date("%a %b %d %H:%M") gfx.text((W-unicode.len(c))//2,1,c,0xFFFFFF) gfx.text(W-3,1,"⌽",0xFFFFFF) o.hits[#o.hits+1]={W-5,1,5,1,function()o.power=not o.power end} if o.power then local mx=W-18 ui.card(mx,3,16,2,t.menu) gfx.text(mx+2,3,"Restart",t.menuFg,t.menu) gfx.text(mx+2,4,"Power Off",t.menuFg,t.menu) o.hits[#o.hits+1]={mx,3,16,1,function()Y.quit("reboot")end} o.hits[#o.hits+1]={mx,4,16,1,function()Y.quit("shutdown")end} end if o.stage=="clock"then local hm=Y.date("%H:%M") local cy=H//2-8 ui.big((W-ui.bigWidth(hm))//2,cy,hm,0xFFFFFF) local d=Y.date("%A, %B %d") Y.label((W-40)//2,cy+10,d,40) local hint=requirePassword and"Click or press a key to unlock"or"Click or press a key to continue" Y.label((W-50)//2,H-3,hint,50) return end local name=os.getenv("USER")or"user" local host=os.getenv("HOSTNAME")or"openos" local cy=H//2-7 local ax=(W-14)//2 ui.card(ax,cy,14,6,t.accent,false) Y.drawIcon(ax+3,cy+1,"user") local nm=name gfx.text((W-unicode.len(nm))//2,cy+8,nm,0xFFFFFF) if o.stage=="users"then local sub="on "..host gfx.text((W-unicode.len(sub))//2,cy+9,sub,0xC0BFBC) o.hits[#o.hits+1]={ax-4,cy-1,22,11,advance} Y.label((W-50)//2,H-3,"Click your name or press Enter to log in",50) else local ew=32 local ex=(W-ew)//2 ui.entry(nil,o.pw,ex,cy+10,ew,true,"Password",true) ui.pill(ex+ew+1,cy+10,3,t.accent) gfx.text(ex+ew+2,cy+10,"→",0xFFFFFF,t.accent) o.hits[#o.hits+1]={ex+ew+1,cy+10,3,1,try} if o.err then gfx.text((W-unicode.len(o.err))//2,cy+12,o.err,0xF66151)end if login then gfx.text(ex,cy+14,"‹ Back",0xC0BFBC) o.hits[#o.hits+1]={ex,cy+14,6,1,function()o.stage="users";o.err=nil end} end end end function o.touch() o.power=false Y.lastInput=computer.uptime() if o.blank then o.blank=false elseif o.stage=="clock"then advance()end gfx.damageAll() return true end function o.key(_,char,code) Y.lastInput=computer.uptime() if o.blank then o.blank=false;gfx.damageAll()return end if o.stage~="password"then if code==Y.K.esc and o.stage=="users"then return end advance() else local r=ui.entryKey(o.pw,char,code) if r=="enter"then try() elseif r=="esc"then o.pw.text,o.pw.cur="",0;if not login then o.stage="clock"end elseif r then o.err=nil end end gfx.damageAll() end function o.paste(_,s)if o.stage=="password"then ui.entryPaste(o.pw,s)gfx.damageAll()end end Y.openOverlay(o) return o end return M