diff --git a/sys/apis/packages.lua b/sys/apis/packages.lua index ae7375a..7f39255 100644 --- a/sys/apis/packages.lua +++ b/sys/apis/packages.lua @@ -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 diff --git a/sys/apps/PackageManager.lua b/sys/apps/PackageManager.lua index 322f22a..29f3db4 100644 --- a/sys/apps/PackageManager.lua +++ b/sys/apps/PackageManager.lua @@ -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() diff --git a/sys/extensions/4.user.lua b/sys/extensions/4.user.lua index c6d0d9e..89a7000 100644 --- a/sys/extensions/4.user.lua +++ b/sys/extensions/4.user.lua @@ -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 diff --git a/sys/extensions/6.packages.lua b/sys/extensions/6.packages.lua index 704299f..c7203b3 100644 --- a/sys/extensions/6.packages.lua +++ b/sys/extensions/6.packages.lua @@ -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, ';')