Update sPhone.lua

This commit is contained in:
Ale32bit 2016-09-02 12:57:19 +02:00 committed by GitHub
parent 43bfc7bcff
commit 95f707a2d4

View file

@ -1,9 +1,19 @@
local function kernel() local function kernel()
_G.sPhone = { _G.sPhone = {
version = "Alpha 2.14", version = "Alpha 3",
user = "Guest", user = "Guest",
devMode = false, devMode = false,
mainTerm = term.current() mainTerm = term.current(),
safeMode = false,
}
if safemode then
sPhone.safeMode = true
_G.safemode = nil
end
sPhone.defaultApps = {
["home"] = "/.sPhone/apps/home",
} }
sPhone.theme = { --Default colors sPhone.theme = { --Default colors
@ -20,13 +30,6 @@ local function kernel()
sPhone.defaultTheme = sPhone.theme sPhone.defaultTheme = sPhone.theme
if not fs.exists("/.sPhone/config/newPassword") and fs.exists("/.sPhone/.password") then
fs.move("/.sPhone/.password","/.sPhone/config/.password")
f = fs.open("/.sPhone/config/newPassword","w")
f.write("Ignore Me. I just check if the password is moved to the config folder")
f.close()
end
if not fs.exists("/.sPhone/apis") then if not fs.exists("/.sPhone/apis") then
fs.makeDir("/.sPhone/apis") fs.makeDir("/.sPhone/apis")
end end
@ -51,7 +54,7 @@ local function kernel()
for k, v in pairs(fs.list("/.sPhone/autorun")) do for k, v in pairs(fs.list("/.sPhone/autorun")) do
term.setTextColor(colors.black) term.setTextColor(colors.black)
if not fs.isDir("/.sPhone/autorun/"..v) then if not fs.isDir("/.sPhone/autorun/"..v) then
if not safemode then if not sPhone.safemode then
local f = fs.open("/.sPhone/autorun/"..v,"r") local f = fs.open("/.sPhone/autorun/"..v,"r")
local script = f.readAll() local script = f.readAll()
f.close() f.close()
@ -73,10 +76,6 @@ local function kernel()
end end
end end
if safemode then
_G.safemode = nil
end
if runningOnStartup then if runningOnStartup then
fs.open("/startup","r") fs.open("/startup","r")
end end
@ -140,6 +139,28 @@ local function kernel()
return n return n
end end
function sPhone.setDefaultApp(app, path)
if not path then
error("got nil",2)
end
sPhone.defaultApps[app] = path
config.write("/.sPhone/config/defaultApps",app,path)
end
function sPhone.getDefaultApp(app)
if not app then
error("got nil",2)
end
local n = config.read("/.sPhone/config/defaultApps",app)
return n
end
if not fs.exists("/.sPhone/config/defaultApps") then
sPhone.setDefaultApp("home","/.sPhone/apps/home")
end
local function clear() local function clear()
term.setBackgroundColor(sPhone.theme["backgroundColor"]) term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear() term.clear()
@ -166,7 +187,6 @@ local function kernel()
clear() clear()
w, h = term.getSize() w, h = term.getSize()
term.setCursorPos( (w / 2) - 1, h / 2) term.setCursorPos( (w / 2) - 1, h / 2)
write(" ")
for i = 1,3 do for i = 1,3 do
sleep(0.3) sleep(0.3)
write(".") write(".")
@ -192,7 +212,6 @@ local function kernel()
clear() clear()
w, h = term.getSize() w, h = term.getSize()
term.setCursorPos( (w / 2) - 1, h / 2) term.setCursorPos( (w / 2) - 1, h / 2)
write(" ")
for i = 1,3 do for i = 1,3 do
sleep(0.3) sleep(0.3)
write(".") write(".")
@ -536,168 +555,26 @@ end
end end
end end
local function lChat()
clear()
sPhone.header("RedNet Chat")
term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.setTextColor(sPhone.theme["text"])
term.setCursorPos(2, 5)
if not peripheral.isPresent("back") or not peripheral.getType("back") == "modem" then
print("Modem not found")
print(" Press any key")
os.pullEvent("key")
return
end
write("Host: ")
local h = read()
term.setCursorPos(2,6)
shell.run("/rom/programs/rednet/chat", "join", h, sPhone.user)
sleep(1)
end
local function home() local function home()
sPhone.inHome = true sPhone.inHome = true
local buttonsInHome = {
{"sPhone.header",23,1,25,1,sPhone.theme["header"],sPhone.theme["headerText"],"vvv"},
{"sPhone.appsButton",12,20,14,20,sPhone.theme["backgroundColor"],sPhone.theme["header"],"==="},
{"sPhone.shell",2,3,8,5,colors.black,colors.yellow," Shell",2},
{"sPhone.lock",19,3,24,5,colors.lightGray,colors.black," Lock",2},
{"sPhone.chat",11,3,16,5,colors.black,colors.white," Chat",2},
{"sPhone.kst",2,7,8,9,colors.green,colors.white," Krist",2},
{"sPhone.gps",11,7,15,9,colors.red,colors.black," GPS",2},
{"sPhone.info",18,7,23,9,colors.lightGray,colors.black," Info",2},
{"sPhone.store",2,11,8,13,colors.orange,colors.white," Store",2},
}
local appsOnHome = {
["sPhone.shell"] = "/.sPhone/apps/shell",
["sPhone.sID"] = "/.sPhone/apps/system/sID",
["sPhone.buddies"] = "/.sPhone/apps/buddies",
["sPhone.SMS"] = "/.sPhone/apps/sms",
["sPhone.gps"] = "/.sPhone/apps/gps",
["sPhone.kst"] = "/.sPhone/apps/kstwallet",
["sPhone.info"] = "/.sPhone/apps/system/info",
["sPhone.store"] = "/.sPhone/apps/store",
["sPhone.appsButton"] = "/.sPhone/apps/appList",
}
if not sPhone.locked then
sPhone.lock()
if sPhone.newUpdate then
sPhone.winOk("New Update!")
end
end
if fs.exists("/.sPhone/config/resetDBNews") then
fs.delete("/.sPhone/config/resetDBNews")
end
local function drawHome()
local function box(x,y,text,bg,colorText,page)
graphics.box(x,y,x+1+#text,y+2,bg)
term.setCursorPos(x+1,y+1)
term.setTextColor(colorText)
write(text)
end
clear()
visum.buttons(buttonsInHome,true)
local w, h = term.getSize()
paintutils.drawLine(1,1,w,1, sPhone.theme["header"])
term.setTextColor(sPhone.theme["headerText"])
visum.align("right","vvv ",false,1)
end
local function footerMenu()
sPhone.isFooterMenuOpen = true
function redraw()
drawHome()
local w, h = term.getSize()
graphics.box(1,2,w,4,sPhone.theme["header"])
term.setTextColor(sPhone.theme["headerText"])
term.setBackgroundColor(sPhone.theme["header"])
visum.align("right","^^^ ",false,1)
visum.align("right", "Reboot ",false,3)
term.setCursorPos(11,3)
write("Settings")
term.setCursorPos(2,3)
write("Shutdown")
end
while true do while true do
term.redirect(sPhone.mainTerm) os.pullEvent = os.oldPullEvent
drawHome() term.setBackgroundColor(colors.black)
redraw() term.setTextColor(colors.white)
local _,_,x,y = os.pullEvent("mouse_click") term.clear()
if y == 3 then
if x > 1 and x < 10 then
os.shutdown()
sPhone.inHome = true
elseif x > 19 and x < 26 then
os.reboot()
sPhone.inHome = true
elseif x > 10 and x < 19 then
sPhone.inHome = false
sPhone.run("/.sPhone/apps/system/settings")
sPhone.inHome = true
drawHome()
end
elseif y == 1 then
if x < 26 and x > 22 then
sPhone.isFooterMenuOpen = false
return
end
end
end
end
local function buttonHomeLoop()
while true do
drawHome()
term.setCursorBlink(false)
local autoLockTimer = os.startTimer(10)
local id = visum.buttons(buttonsInHome)
if id == "sPhone.header" then
footerMenu()
elseif id == "sPhone.lock" then
sPhone.inHome = false
login()
sPhone.inHome = true
elseif id == "sPhone.chat" then
sPhone.inHome = false
lChat()
sPhone.inHome = true
elseif appsOnHome[id] then
sPhone.inHome = false
sPhone.run(appsOnHome[id])
sPhone.inHome = true
end
end
sPhone.inHome = false
end
local function updateClock()
while true do
if sPhone.inHome then
term.setCursorPos(1,1) term.setCursorPos(1,1)
term.setBackgroundColor(sPhone.theme["header"])
term.setTextColor(sPhone.theme["headerText"])
term.setCursorPos(1,1)
write(" ")
term.setCursorPos(1,1)
write(" "..textutils.formatTime(os.time(),true))
end
sleep(0)
end
end
parallel.waitForAll(buttonHomeLoop, updateClock)
if not sPhone.safeMode then
if fs.exists(sPhone.getDefaultApp("home")) then
shell.run(sPhone.getDefaultApp("home"))
else
shell.run("/.sPhone/apps/home")
end
else
shell.run("/.sPhone/apps/home")
end
end
sPhone.inHome = false sPhone.inHome = false
end end
function login() function login()
@ -817,9 +694,7 @@ end
term.setCursorPos(1,1) term.setCursorPos(1,1)
term.setTextColor(sPhone.theme["text"]) term.setTextColor(sPhone.theme["text"])
sPhone.user = name sPhone.user = name
local toLabel = sPhone.user.."'s &9sPhone" os.setComputerLabel(sPhone.user.."'s sPhone")
toLabel = toLabel:gsub("&", string.char(0xc2)..string.char(0xa7))
os.setComputerLabel(toLabel)
visum.align("center"," All Set!",false,3) visum.align("center"," All Set!",false,3)
visum.align("center"," Have fun with sPhone",false,5) visum.align("center"," Have fun with sPhone",false,5)
sleep(2) sleep(2)
@ -841,6 +716,10 @@ end
sPhone.newUpdate = false sPhone.newUpdate = false
end end
login()
if sPhone.newUpdate then
sPhone.winOk("New Update!")
end
home() home()
end end