mirror of
https://github.com/kepler155c/opus
synced 2024-12-24 15:40:26 +00:00
package manager
This commit is contained in:
parent
4387264960
commit
4977ea94d7
@ -33,6 +33,17 @@ function Packages:isInstalled(package)
|
||||
return self:installed()[package]
|
||||
end
|
||||
|
||||
function Packages:downloadList()
|
||||
local packages = {
|
||||
[ 'develop-1.8' ] = 'https://pastebin.com/raw/WhEiNGZE',
|
||||
[ 'master-1.8' ] = 'https://pastebin.com/raw/pexZpAxt',
|
||||
}
|
||||
|
||||
if packages[_G.OPUS_BRANCH] then
|
||||
Util.download(packages[_G.OPUS_BRANCH], 'usr/config/packages')
|
||||
end
|
||||
end
|
||||
|
||||
function Packages:getManifest(package)
|
||||
local fname = 'packages/' .. package .. '/.package'
|
||||
if fs.exists(fname) then
|
||||
|
@ -10,7 +10,7 @@ UI:configure('PackageManager', ...)
|
||||
|
||||
local page = UI.Page {
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = 7, x = 2, ex = -12,
|
||||
x = 2, ex = -12, y = 2, ey = 7,
|
||||
values = { },
|
||||
columns = {
|
||||
{ heading = 'Package', key = 'name' },
|
||||
@ -34,10 +34,15 @@ local page = UI.Page {
|
||||
help = 'Remove',
|
||||
},
|
||||
description = UI.TextArea {
|
||||
x = 2, y = 9, ey = -2,
|
||||
x = 2, y = 9, ey = -4,
|
||||
--backgroundColor = colors.white,
|
||||
},
|
||||
statusBar = UI.StatusBar { },
|
||||
load = UI.Button {
|
||||
x = 2, y = -3,
|
||||
text = 'Update package list',
|
||||
event = 'reload',
|
||||
help = 'Download the latest package list',
|
||||
},
|
||||
action = UI.SlideOut {
|
||||
backgroundColor = colors.cyan,
|
||||
titleBar = UI.TitleBar {
|
||||
@ -54,8 +59,39 @@ local page = UI.Page {
|
||||
backgroundColor = colors.cyan,
|
||||
},
|
||||
},
|
||||
statusBar = UI.StatusBar { },
|
||||
}
|
||||
|
||||
function page:loadPackages()
|
||||
self.grid.values = { }
|
||||
self.statusBar:setStatus('Downloading...')
|
||||
self:sync()
|
||||
|
||||
for k in pairs(Packages:list()) do
|
||||
local manifest = Packages:getManifest(k)
|
||||
if not manifest then
|
||||
manifest = {
|
||||
invalid = true,
|
||||
description = 'Unable to download manifest',
|
||||
title = '',
|
||||
}
|
||||
end
|
||||
table.insert(self.grid.values, {
|
||||
installed = not not Packages:isInstalled(k),
|
||||
name = k,
|
||||
manifest = manifest,
|
||||
})
|
||||
end
|
||||
self.grid:update()
|
||||
self.grid:setIndex(1)
|
||||
self.grid:emit({
|
||||
type = 'grid_focus_row',
|
||||
selected = self.grid:getSelected(),
|
||||
element = self.grid,
|
||||
})
|
||||
self.statusBar:setStatus('Updated packages')
|
||||
end
|
||||
|
||||
function page.grid:getRowTextColor(row, selected)
|
||||
if row.installed then
|
||||
return colors.yellow
|
||||
@ -108,6 +144,10 @@ function page:eventHandler(event)
|
||||
self.description:draw()
|
||||
self:updateSelection(event.selected)
|
||||
|
||||
elseif event.type == 'reload' then
|
||||
Packages:downloadList()
|
||||
self:loadPackages()
|
||||
|
||||
elseif event.type == 'action' then
|
||||
local selected = self.grid:getSelected()
|
||||
if selected then
|
||||
@ -138,27 +178,7 @@ function page:eventHandler(event)
|
||||
UI.Page.eventHandler(self, event)
|
||||
end
|
||||
|
||||
for k in pairs(Packages:list()) do
|
||||
local manifest = Packages:getManifest(k)
|
||||
if not manifest then
|
||||
manifest = {
|
||||
invalid = true,
|
||||
description = 'Unable to download manifest',
|
||||
title = '',
|
||||
}
|
||||
end
|
||||
table.insert(page.grid.values, {
|
||||
installed = not not Packages:isInstalled(k),
|
||||
name = k,
|
||||
manifest = manifest,
|
||||
})
|
||||
end
|
||||
page.grid:update()
|
||||
page.grid:emit({
|
||||
type = 'grid_focus_row',
|
||||
selected = page.grid:getSelected(),
|
||||
element = page.grid,
|
||||
})
|
||||
page:loadPackages()
|
||||
|
||||
UI:setPage(page)
|
||||
UI:pullEvents()
|
||||
|
@ -1,5 +1,3 @@
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local Util = require('util')
|
||||
|
||||
local fs = _G.fs
|
||||
@ -29,17 +27,6 @@ if not fs.exists('usr/config/shell') then
|
||||
})
|
||||
end
|
||||
|
||||
if not fs.exists('usr/config/packages') then
|
||||
local packages = {
|
||||
[ 'develop-1.8' ] = 'https://pastebin.com/raw/WhEiNGZE',
|
||||
[ 'master-1.8' ] = 'https://pastebin.com/raw/pexZpAxt',
|
||||
}
|
||||
|
||||
if packages[_G.OPUS_BRANCH] then
|
||||
Util.download(packages[_G.OPUS_BRANCH], 'usr/config/packages')
|
||||
end
|
||||
end
|
||||
|
||||
local config = Util.readTable('usr/config/shell')
|
||||
if config.aliases then
|
||||
for k in pairs(shell.aliases()) do
|
||||
|
@ -1,5 +1,3 @@
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local Packages = require('packages')
|
||||
local Util = require('util')
|
||||
|
||||
@ -7,6 +5,10 @@ local fs = _G.fs
|
||||
local help = _G.help
|
||||
local shell = _ENV.shell
|
||||
|
||||
if not fs.exists('usr/config/packages') then
|
||||
Packages:downloadList()
|
||||
end
|
||||
|
||||
local appPaths = Util.split(shell.path(), '(.-):')
|
||||
local luaPaths = Util.split(_G.LUA_PATH, '(.-);')
|
||||
local helpPaths = Util.split(help.path(), '(.-):')
|
||||
@ -50,6 +52,5 @@ for name in pairs(Packages:installed()) do
|
||||
end
|
||||
|
||||
help.setPath(table.concat(helpPaths, ':'))
|
||||
|
||||
shell.setPath(table.concat(appPaths, ':'))
|
||||
_G.LUA_PATH = table.concat(luaPaths, ';')
|
||||
|
Loading…
Reference in New Issue
Block a user