Commit 40d52d2d authored by Danny SMc's avatar Danny SMc

Added current code

parent 719eddd6
Discover App Documentation:
===========================
-> Registering Plugins / Extensions
To register a plugin it's as easy as using the API code. This is an internal registering system that shall register event listeners, commands and other for your plugin, most of the time we aim to say try not to use too many otherwise you will make the App unstable due to it's internal clock. Anyway, when creating a new plugin you will need a basic plugin.yml file which should be in it's own folder inside .DA_PLUGINS folder. Here the App will parse and read your details, then install them to the program at runtime. Then it will look for a main or main.lua file. This should have your main code in, of course you can use other files, but that name is the entry point. When that program is called it shall pass over it's API environment, so you can then work with the environment.
-> Adding a menu item
This is relatively straight forward, you will need an icon which is 14 x 4 wide, which should use the custom image format. Once you have this image, it needs to be in your program as a table so then we can pass it to the menu manager. So to do this, you need to use the following:
- DiscoverApp.Register.MenuIcon(icon_name, icon_data);
- Icon name is the name of the icon in the icon database.
- Icon data is of course the table of the icon format.
Now you have registered your new image you will need to register the actual menu entry, this is done like so:
- DiscoverApp.Register.MenuEntry(icon_name, api_name, func_name, thread_name, requires login)
- Icon name is what you set when you registered the icon.
- api_name should be the middle part of the function it will run.
- func name, this is the function name that it will invoke, so the name of the function you created for it, this is the entry point into your own code.
- thread_name, this is the text that will come up in the task switcher.
- requires login is a true or false, and this will check if the user requires to be logged in to use the system, if they are not loggedin, there is no exposed user data.
Now that will register your menu entry.
\ No newline at end of file
......@@ -4,16 +4,81 @@
--]]
function program.account.login()
base.screen.colour("white")
program.draw.menubar("Account: Login")
if (Internal.System.Platform == "Desktop") then
base.screen.colour("white")
program.draw.menubar("Account: Login")
local status = false
while true do
local args = { os.pullEvent() }
if args[1] == "timer" then
program.draw.menubar("Account: Login")
elseif args[1] == "mouse_click" then
if (args[3] >= 1 and args[3] <= screenx) and (args[4] >= 1 and args[4] <= 2) then
program.draw.menu.handler("Account: Login", args[3], args[4])
base.draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
base.draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
base.draw.texta("Username:", 8, 6, false, "lightGrey", "white")
base.draw.texta("Password:", 8, 10, false, "lightGrey", "white")
base.draw.texta("Remember me", 8, 14, false, "lightGrey", "white")
base.draw.texta("Enabled", 37, 14, false, "green", "white")
base.draw.box(1, 51, 19, 1, " ", "grey", "grey")
base.draw.textl(" Cancel", 19, false, "red", "grey")
base.draw.textr("Login ", 19, false, "cyan", "grey")
local function drawStatus()
if status then
base.draw.texta(" Enabled", 36, 14, false, "green", "white")
else
base.draw.texta("Disabled", 36, 14, false, "red", "white")
end
end
drawStatus()
while true do
local args = { os.pullEvent() }
if args[1] == "timer" then
program.draw.menubar("Account: Login")
elseif args[1] == "mouse_click" then
if (args[3] >= 1 and args[3] <= screenx) and (args[4] >= 1 and args[4] <= 2) then
program.draw.menu.handler("Account: Login", args[3], args[4])
elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 14) then
if status then
status = false
else
status = true
end
drawStatus()
elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 7) then
base.draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
base.colour.set("white", "cyan")
term.setCursorPos(8, 7)
write(": ")
username = tostring(base.io.limitRead(32))
elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 11) then
base.draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
base.colour.set("white", "cyan")
term.setCursorPos(8, 11)
write(": ")
password = tostring(base.io.limitRead(32, "*"))
elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then
base.thread.remove("Login")
base.thread.switch("Home")
elseif (args[3] >= 46 and args[3] <= 50) and (args[4] == 19) then
local status = Discover.User:Login(username, password)
if status then
if status then
-- Create Config
local f = fs.open(Internal.Config.Path, "w")
Internal.Account.Username = username
Internal.Account.Password = Discover.Crypto:Sha256(password)
f.write(Discover.Crypto:Base64("encode", textutils.serialize(Internal.Account)))
f.close();
end
base.gui.alert("You have been logged in!")
sleep(0.5)
os.startTimer(1)
base.thread.remove("Login")
base.thread.switch("Home")
else
base.gui.alert("We could not log you in!")
sleep(1.5)
program.account.login()
end
end
end
end
end
......
--[[
Name: Account -> Logout
Description: Logout Function
--]]
function program.account.logout()
program.draw.menubar("Account: Logout")
base.screen.colour("white")
base.draw.textc("Logging out...", 10, false, "red", "white")
local status = Discover.User:Logout()
local status = Discover.User:Reset()
base.thread.remove("Login")
base.thread.switch("Home")
end
\ No newline at end of file
......@@ -12,11 +12,13 @@ local paths = {
"api/api.base.lua";
"core/core.general.lua";
"core/core.icons.lua";
"core/core.dapi.lua";
"core/core.init.lua";
"main/main.menu.lua";
"main/main.home.lua";
"apps/apps.all.lua";
"account/account.login.lua";
"account/account.logout.lua";
"apps/apps.categories.lua";
"apps/apps.versions.lua";
"apps/apps.search.lua";
......
-- Intialize the DiscoverApp API.
Internal.MenuEntries = {};
DiscoverApp = {
Register = {
MenuIcon = function(iconname, icondata)
if Internal.Icons[iconname] == nil then
Internal.Icons[iconname] = icondata;
return true;
else
return false;
end
end;
MenuEntry = function(iconname, api_name, func_name, thread_name, requires_login)
if not type(Internal.MenuEntries) == "table" then
Internal.MenuEntries = {};
end
local new = {};
new["icon_name"] = iconname;
new["base_func"] = api_name;
new["func_name"] = func_name;
new["thrd_name"] = thread_name;
new["req_login"] = requires_login;
table.insert(Internal.MenuEntries, new);
new = nil;
return true;
end;
};
};
\ No newline at end of file
......@@ -21,6 +21,7 @@ Internal = {
Platform = false;
ActiveScreen = false;
};
Account = {};
}
local screenx, screeny = term.getSize();
......
......@@ -37,8 +37,8 @@ function program.core.init()
-- Check for username / password
log("Looking for account credentials ... ")
if Internal.Data.Username and Internal.Data.Password then
local status = Discover.User:ManualLogin(Internal.Data.Username, Internal.Data.Password);
if Internal.Account.Username and Internal.Account.Password then
local status = Discover.User:ManualLogin(Internal.Account.Username, Internal.Account.Password);
Internal.Account.Username = nil;
Internal.Account.Password = nil;
if status then
......@@ -66,6 +66,12 @@ function program.core.init()
-- Initialise Threads
base.thread.create("Home", program.main.home)
base.thread.create("Mail", program.main.home)
base.thread.create("Cloud", program.main.home)
base.thread.create("Apps", program.main.home)
base.thread.create("Snippets", program.main.home)
base.thread.create("Settings", program.main.home)
base.thread.create("BrowserX", program.main.home)
base.thread.switch("Home")
base.thread.run()
......
This diff is collapsed.
......@@ -3,6 +3,7 @@
Desc: Menu bar at the top of everything
--]]
local tasks_bar = false;
local menu_scroll = 0;
Internal.System.ActiveScreen = "Homepage";
function program.draw.menubar(screen)
Internal.System.ActiveScreen = tostring(screen);
......@@ -28,6 +29,60 @@ function program.draw.menu.handler(screen, x, y)
tasks_bar = true
program.draw.menu.tasks(true, true)
end
elseif (x == 1 and y == 2) then
if menu_scroll > 0 then
menu_scroll = menu_scroll - 1
program.draw.menu.tasks(tasks_bar, false)
end
elseif (x == 42 and y == 2) then
if #threads >= 4 + menu_scroll then
menu_scroll = menu_scroll + 1
program.draw.menu.tasks(tasks_bar, false)
end
elseif (x >= 3 and x <= 11) and (y == 2) then
local id = 1 + menu_scroll
if (threads[id]['name'] == currentThread['name']) then
if x == 3 then
base.thread.remove(threads[id]['name'])
end
else
if (base.thread.find(threads[id]['name'])) then
base.thread.switch(threads[id]['name'])
end
end
elseif (x >= 13 and x <= 21) and (y == 2) then
local id = 2 + menu_scroll
if (threads[id]['name'] == currentThread['name']) then
if x == 3 then
base.thread.remove(threads[id]['name'])
end
else
if (base.thread.find(threads[id]['name'])) then
base.thread.switch(threads[id]['name'])
end
end
elseif (x >= 23 and x <= 31) and (y == 2) then
local id = 3 + menu_scroll
if (threads[id]['name'] == currentThread['name']) then
if x == 3 then
base.thread.remove(threads[id]['name'])
end
else
if (base.thread.find(threads[id]['name'])) then
base.thread.switch(threads[id]['name'])
end
end
elseif (x >= 33 and x <= 41) and (y == 2) then
local id = 4 + menu_scroll
if (threads[id]['name'] == currentThread['name']) then
if x == 3 then
base.thread.remove(threads[id]['name'])
end
else
if (base.thread.find(threads[id]['name'])) then
base.thread.switch(threads[id]['name'])
end
end
end
end
end
......@@ -40,22 +95,47 @@ function program.draw.menu.tasks(open, animate)
sleep(0.001)
end
base.draw.textr("Close >", 2, false, "white", "lightGrey")
local chars = {2, 12, 22, 32}
local text = {"Dash", "Apps", "Cloud", "Mail"}
local chars = {3, 13, 23, 33}
local text = {"Dash", "Apps", "Cloud", "Mail", "Settings", "CronTab"}
base.draw.texta("<", 1, 2, false, "red", "lightGrey")
base.draw.texta(">", 42, 2, false, "red", "lightGrey")
for k,v in ipairs(chars) do
base.draw.texta(text[k], chars[k], 2, false, "lightBlue", "lightGrey")
if animate then
sleep(0.01)
end
if (#threads >= k + menu_scroll) then
if (threads[k+menu_scroll]['name'] == currentThread['name']) then
base.draw.texta(" ", chars[k], 2, false, "lightGrey", "lightGrey")
base.draw.texta('x', chars[k], 2, false, "red", "lightGrey")
base.draw.texta(tostring(threads[k+menu_scroll]['name']:sub(1,6)), chars[k]+2, 2, false, "lightBlue", "lightGrey")
else
base.draw.texta(" ", chars[k], 2, false, "lightGrey", "lightGrey")
base.draw.texta(tostring(threads[k+menu_scroll]['name']:sub(1,8)), chars[k], 2, false, "lightBlue", "lightGrey")
end
if animate then
sleep(0.01)
end
end
end
os.startTimer(1);
else
local x,y = term.getSize();
local chars = {2, 12, 22, 32}
local chars = {3, 13, 23, 33}
local text = {"Dash", "Apps", "Cloud", "Mail"}
base.draw.box(1, x, 2, 1, " ", "lightGrey", "lightGrey")
base.draw.textr("Close >", 2, false, "white", "lightGrey")
for k,v in ipairs(chars) do base.draw.texta(text[k], chars[k], 2, false, "lightBlue", "lightGrey"); end
for k,v in ipairs(chars) do
if (#threads >= k + menu_scroll) then
if (threads[k+menu_scroll]['name'] == currentThread['name']) then
base.draw.texta(" ", chars[k], 2, false, "lightGrey", "lightGrey")
base.draw.texta('x', chars[k], 2, false, "red", "lightGrey")
base.draw.texta(tostring(threads[k+menu_scroll]['name']:sub(1,6)), chars[k]+2, 2, false, "lightBlue", "lightGrey")
else
base.draw.texta(" ", chars[k], 2, false, "lightGrey", "lightGrey")
base.draw.texta(tostring(threads[k+menu_scroll]['name']:sub(1,8)), chars[k], 2, false, "lightBlue", "lightGrey");
end
end
end
base.draw.texta("<", 1, 2, false, "red", "lightGrey")
base.draw.texta(">", 42, 2, false, "red", "lightGrey")
end
else
if animate then
......
shell.run("builder.lua run")
shell.run("builder.lua run -l")
shell.run("discoverapp.lua")
print("Build / Run Finished")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment