mirror of
https://github.com/kepler155c/opus
synced 2025-10-21 18:57:41 +00:00
web running os
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
require = requireInjector(getfenv(1))
|
||||
local Util = require('util')
|
||||
local class = require('class')
|
||||
local UI = require('ui')
|
||||
local Event = require('event')
|
||||
|
||||
local sandboxEnv = Util.shallowCopy(getfenv(1))
|
||||
setmetatable(sandboxEnv, { __index = _G })
|
||||
@@ -10,12 +8,14 @@ setmetatable(sandboxEnv, { __index = _G })
|
||||
multishell.setTitle(multishell.getCurrent(), 'App Store')
|
||||
UI:configure('Appstore', ...)
|
||||
|
||||
local APP_DIR = 'usr/apps'
|
||||
|
||||
local sources = {
|
||||
|
||||
{ text = "STD Default",
|
||||
event = 'source',
|
||||
url = "http://pastebin.com/raw/zVws7eLq" }, --stock
|
||||
|
||||
--[[
|
||||
{ text = "Discover",
|
||||
event = 'source',
|
||||
generateName = true,
|
||||
@@ -24,9 +24,10 @@ local sources = {
|
||||
{ text = "Opus",
|
||||
event = 'source',
|
||||
url = "http://pastebin.com/raw/ajQ91Rmn" },
|
||||
]]
|
||||
}
|
||||
|
||||
shell.setDir('/apps')
|
||||
shell.setDir(APP_DIR)
|
||||
|
||||
function downloadApp(app)
|
||||
local h
|
||||
@@ -49,8 +50,8 @@ function runApp(app, checkExists, ...)
|
||||
local path, fn
|
||||
local args = { ... }
|
||||
|
||||
if checkExists and fs.exists(fs.combine('/apps', app.name)) then
|
||||
path = fs.combine('/apps', app.name)
|
||||
if checkExists and fs.exists(fs.combine(APP_DIR, app.name)) then
|
||||
path = fs.combine(APP_DIR, app.name)
|
||||
else
|
||||
local program = downloadApp(app)
|
||||
|
||||
@@ -89,7 +90,7 @@ local installApp = function(app)
|
||||
return false, "Failed to download"
|
||||
end
|
||||
|
||||
local fullPath = fs.combine('/apps', app.name)
|
||||
local fullPath = fs.combine(APP_DIR, app.name)
|
||||
Util.writeFile(fullPath, program)
|
||||
return true, 'Installed as ' .. fullPath
|
||||
end
|
||||
@@ -103,6 +104,7 @@ local viewApp = function(app)
|
||||
|
||||
Util.writeFile('/.source', program)
|
||||
shell.openForegroundTab('edit /.source')
|
||||
fs.delete('/.source')
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -190,7 +192,7 @@ function appPage:enable(source, app)
|
||||
UI.Page.enable(self)
|
||||
|
||||
self.container.viewport:setScrollPosition(0)
|
||||
if fs.exists(fs.combine('/apps', app.name)) then
|
||||
if fs.exists(fs.combine(APP_DIR, app.name)) then
|
||||
self.menuBar.removeButton:enable('Remove')
|
||||
else
|
||||
self.menuBar.removeButton:disable('Remove')
|
||||
@@ -215,13 +217,13 @@ function appPage:eventHandler(event)
|
||||
if self.app.runOnly then
|
||||
s,m = runApp(self.app, false, 'uninstall')
|
||||
else
|
||||
fs.delete(fs.combine('/apps', self.app.name))
|
||||
fs.delete(fs.combine(APP_DIR, self.app.name))
|
||||
self.notification:success("Uninstalled " .. self.app.name, 3)
|
||||
self:focusFirst(self)
|
||||
self.menuBar.removeButton:disable('Remove')
|
||||
self.menuBar:draw()
|
||||
|
||||
os.unregisterApp(fs.combine('/apps', self.app.name))
|
||||
os.unregisterApp(self.app.creator .. '.' .. self.app.name)
|
||||
end
|
||||
|
||||
elseif event.type == 'install' then
|
||||
@@ -246,11 +248,11 @@ function appPage:eventHandler(event)
|
||||
end
|
||||
|
||||
os.registerApp({
|
||||
run = fs.combine('/apps', self.app.name),
|
||||
run = fs.combine(APP_DIR, self.app.name),
|
||||
title = self.app.title,
|
||||
category = category,
|
||||
icon = self.app.icon,
|
||||
})
|
||||
}, self.app.creator .. '.' .. self.app.name)
|
||||
end
|
||||
else
|
||||
self.notification:error(m, 3)
|
||||
@@ -348,7 +350,7 @@ function categoryPage.grid:sortCompare(a, b)
|
||||
end
|
||||
|
||||
function categoryPage.grid:getRowTextColor(row, selected)
|
||||
if fs.exists(fs.combine('/apps', row.name)) then
|
||||
if fs.exists(fs.combine(APP_DIR, row.name)) then
|
||||
return colors.orange
|
||||
end
|
||||
return UI.Grid:getRowTextColor(row, selected)
|
||||
@@ -370,7 +372,7 @@ function categoryPage:eventHandler(event)
|
||||
self:draw()
|
||||
|
||||
elseif event.type == 'quit' then
|
||||
Event.exitPullEvents()
|
||||
UI:exitPullEvents()
|
||||
|
||||
else
|
||||
return UI.Page.eventHandler(self, event)
|
||||
@@ -382,5 +384,5 @@ print("Retrieving catalog list")
|
||||
categoryPage:setSource(sources[1])
|
||||
|
||||
UI:setPage(categoryPage)
|
||||
Event.pullEvents()
|
||||
UI:pullEvents()
|
||||
UI.term:reset()
|
||||
|
@@ -158,8 +158,8 @@ function page.container:setCategory(categoryName)
|
||||
filtered = { }
|
||||
|
||||
for _,v in ipairs(config.Recent) do
|
||||
local app = Util.find(applications, 'run', v)
|
||||
if app and fs.exists(app.run) then
|
||||
local app = Util.find(applications, 'key', v)
|
||||
if app then -- and fs.exists(app.run) then
|
||||
table.insert(filtered, app)
|
||||
end
|
||||
end
|
||||
@@ -273,12 +273,12 @@ function page:eventHandler(event)
|
||||
|
||||
elseif event.type == 'button' then
|
||||
for k,v in ipairs(config.Recent) do
|
||||
if v == event.button.app.run then
|
||||
if v == event.button.app.key then
|
||||
table.remove(config.Recent, k)
|
||||
break
|
||||
end
|
||||
end
|
||||
table.insert(config.Recent, 1, event.button.app.run)
|
||||
table.insert(config.Recent, 1, event.button.app.key)
|
||||
if #config.Recent > maxRecent then
|
||||
table.remove(config.Recent, maxRecent + 1)
|
||||
end
|
||||
|
@@ -5,7 +5,7 @@ local Socket = require('socket')
|
||||
local Config = require('config')
|
||||
|
||||
local GROUPS_PATH = 'usr/groups'
|
||||
local SCRIPTS_PATH = 'usr/scripts'
|
||||
local SCRIPTS_PATH = 'sys/etc/scripts'
|
||||
|
||||
multishell.setTitle(multishell.getCurrent(), 'Script')
|
||||
UI:configure('script', ...)
|
||||
|
@@ -79,14 +79,11 @@ end
|
||||
|
||||
function shell.resolveProgram( _sCommand )
|
||||
|
||||
local sPath = PATH or ''
|
||||
|
||||
if ALIASES[ _sCommand ] ~= nil then
|
||||
_sCommand = ALIASES[ _sCommand ]
|
||||
end
|
||||
|
||||
local path = shell.resolve(_sCommand)
|
||||
|
||||
if fs.exists(path) and not fs.isDir(path) then
|
||||
return path
|
||||
end
|
||||
@@ -104,9 +101,9 @@ function shell.resolveProgram( _sCommand )
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Otherwise, look on the path variable
|
||||
for sPath in string.gmatch(sPath, "[^:]+") do
|
||||
sPath = fs.combine( shell.resolve(sPath), _sCommand )
|
||||
-- Otherwise, look on the path variable
|
||||
for sPath in string.gmatch(PATH or '', "[^:]+") do
|
||||
sPath = fs.combine(sPath, _sCommand )
|
||||
if fs.exists( sPath ) and not fs.isDir( sPath ) then
|
||||
return sPath
|
||||
end
|
||||
|
Reference in New Issue
Block a user