Advertisement
FFGFlash

api/app.lua

Sep 29th, 2021 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1. local api = { LoadOrder = 99 }
  2. function api.Build()
  3.   local App = { Apps = data:load(".apps"), Data = data("/nekOS/Apps") }
  4.   App.__index = App
  5.  
  6.   function App:__call()
  7.     local app = { Running = false }
  8.     app.__index = app
  9.     function app:__call(id, ...)
  10.       local inst = setmetatable({ Id = id, Path = "/nekOS/Apps/"..id, EventHandler = events(), Data = data("/nekOS/AppData/"..id) }, self)
  11.       inst:connect("terminate", inst.stop)
  12.       inst:constructor(...)
  13.       return inst
  14.     end
  15.     function app:start() self.Running = true while self.Running do self:draw() self.EventHandler() end end
  16.     function app:constructor() end
  17.     function app:draw() end
  18.     function app:stop() self.Running = false self:emit("stop") end
  19.     function app:emit(e,...) return self.EventHandler:emit(e,...) end
  20.     function app:connect(e,c,t) return self.EventHandler:connect(e,function(...) c(t or self,...) end) end
  21.     function app:disconnect(c) return self.EventHandler:disconnect(c) end
  22.     function app:disconnectAll(e) return self.EventHandler:disconnectAll(e) end
  23.     function app:load(p) return self.Data:load(p) end
  24.     function app:save(p,d) return self.Data:save(p,d) end
  25.     function app:require(p) return App.Data:require(self.Id.."/"..p) end
  26.     function app:list(p,r) return path.list(self.Path.."/"..p,r) end
  27.     function app:setInterval(c,t,...) local r={...} local i=os.startTimer(t) local e=self:connect("timer", function(a,f) if f ~= i then return end c(a,table.unpack(r)) i=os.startTimer(t) end) return {Token=i,Conn=e} end
  28.     function app:clearInterval(i) os.cancelTimer(i.Token) self:disconnect(i.Conn) end
  29.     return setmetatable(app, app)
  30.   end
  31.  
  32.   function App:load(p) return self.Data:load(p) end
  33.   function App:save(p,d) return self.Data:save(p,d) end
  34.   function App:require(p) return self.Data:require(p) end
  35.  
  36.   function App:getApps() local a = {} for i,f in ipairs(path.list("/nekOS/Apps",false)) do local n=string.match(fs.getName(f),"([^\.]+)") local m=self:load(f) a[n]=m end return a end
  37.  
  38.   function App:manifest(id)
  39.     return self:load(id..".manifest")
  40.   end
  41.  
  42.   function App:update(id)
  43.  
  44.   end
  45.  
  46.   function App:execute(id, ...)
  47.     self.Apps()
  48.     if not self.Apps[id] then return false,"Application not found." end
  49.     local m=self:load(id..".manifest")
  50.     if not m.Local then
  51.       s,e=self:update(id)
  52.       if not s then return false,e end
  53.       m()
  54.     end
  55.     local app=self:require(id.."/"..m.Entry)(id,...)
  56.     app:start()
  57.   end
  58.  
  59.   function App:install(id)
  60.     self.Apps()
  61.   end
  62.  
  63.   App.Apps()
  64.   local apps = App:getApps()
  65.   for k,v in pairs(apps) do if not App.Apps[k] then App.Apps[k] = {1,2,-1,false} end App.Apps[k][4]=v.Hidden or false end
  66.   App.Apps:save()
  67.  
  68.   return setmetatable(App, App)
  69. end
  70. return api
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement