diff --git a/sys/apps/package.lua b/sys/apps/package.lua index 3d95c17..d1d963e 100644 --- a/sys/apps/package.lua +++ b/sys/apps/package.lua @@ -9,6 +9,12 @@ local term = _G.term local args = { ... } local action = table.remove(args, 1) +local function makeSandbox() + local sandbox = setmetatable(Util.shallowCopy(_ENV), { __index = _G }) + _G.requireInjector(sandbox) + return sandbox +end + local function Syntax(msg) _G.printError(msg) print('\nSyntax: Package list | install [name] ... | update [name] | uninstall [name]') @@ -71,6 +77,17 @@ local function install(name, isUpdate, ignoreDeps) end showProgress() end) + + if not isUpdate then + if manifest.install then + local s, m = pcall(function() + load(manifest.install, 'install', nil, makeSandbox()) + end) + if not s and m then + _G.printError(m) + end + end + end end if action == 'list' then @@ -121,6 +138,15 @@ if action == 'uninstall' then if not Packages:isInstalled(name) then error('Package is not installed') end + local manifest = Packages:getManifest(name) + if manifest.uninstall then + local s, m = pcall(function() + load(manifest.uninstall, 'uninstall', nil, makeSandbox()) + end) + if not s and m then + _G.printError(m) + end + end local packageDir = fs.combine('packages', name) fs.delete(packageDir) print('removed: ' .. packageDir) diff --git a/sys/modules/opus/alternate.lua b/sys/modules/opus/alternate.lua index 532fc20..33e668b 100644 --- a/sys/modules/opus/alternate.lua +++ b/sys/modules/opus/alternate.lua @@ -44,7 +44,7 @@ function Alt.addChoice(key, value) config.choices[key] = { } end if not Util.contains(config.choices[key], value) then - config.choices[key] = value + table.insert(config.choices[key], value) Config.update('alternate', config) end end