diff --git a/sys/apps/ShellLauncher.lua b/sys/apps/ShellLauncher.lua index d905653..f2eebb7 100644 --- a/sys/apps/ShellLauncher.lua +++ b/sys/apps/ShellLauncher.lua @@ -1,8 +1,11 @@ +local Alt = require('opus.alternate') + local kernel = _G.kernel local os = _G.os local shell = _ENV.shell local launcherTab = kernel.getCurrent() +launcherTab.noFocus = true kernel.hook('kernel_focus', function(_, eventData) local focusTab = eventData and eventData[1] @@ -17,7 +20,7 @@ kernel.hook('kernel_focus', function(_, eventData) end end if nextTab == launcherTab then - shell.switchTab(shell.openTab('sys/apps/shell.lua')) + shell.switchTab(shell.openTab(Alt.get('shell'))) else shell.switchTab(nextTab.uid) end diff --git a/sys/apps/package.lua b/sys/apps/package.lua index 61c07af..b5fdba3 100644 --- a/sys/apps/package.lua +++ b/sys/apps/package.lua @@ -41,6 +41,21 @@ local function progress(max) end end +local function runScript(script) + if script then + local s, m = pcall(function() + local fn, m = load(script, 'script', nil, makeSandbox()) + if not fn then + error(m) + end + fn() + end) + if not s and m then + _G.printError(m) + end + end +end + local function install(name, isUpdate, ignoreDeps) local manifest = Packages:downloadManifest(name) or error('Invalid package') @@ -79,14 +94,7 @@ local function install(name, isUpdate, ignoreDeps) 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 + runScript(manifest.install) end end @@ -138,15 +146,10 @@ 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 + runScript(manifest.uninstall) + local packageDir = fs.combine('packages', name) fs.delete(packageDir) print('removed: ' .. packageDir) diff --git a/sys/apps/system/alternate.lua b/sys/apps/system/alternate.lua new file mode 100644 index 0000000..6894428 --- /dev/null +++ b/sys/apps/system/alternate.lua @@ -0,0 +1,80 @@ +local Array = require('opus.array') +local Config = require('opus.config') +local UI = require('opus.ui') + +local colors = _G.colors + +local tab = UI.Tab { + tabTitle = 'Preferred', + description = 'Select preferred applications', + apps = UI.ScrollingGrid { + x = 2, y = 2, + ex = 12, ey = -3, + columns = { + { key = 'name' }, + }, + sortColumn = 'name', + disableHeader = true, + }, + choices = UI.Grid { + x = 14, y = 2, + ex = -2, ey = -3, + disableHeader = true, + columns = { + { key = 'file' }, + } + }, + statusBar = UI.StatusBar { + values = 'Double-click to set as preferred' + }, +} + +function tab.choices:getRowTextColor(row) + if row == self.values[1] then + return colors.yellow + end + return UI.Grid.getRowTextColor(self, row) +end + +function tab:updateChoices() + local app = self.apps:getSelected().name + local choices = { } + for _, v in pairs(self.config[app]) do + table.insert(choices, { file = v }) + end + self.choices:setValues(choices) + self.choices:draw() +end + +function tab:enable() + self.config = Config.load('alternate') + + local apps = { } + for k, _ in pairs(self.config) do + table.insert(apps, { name = k }) + end + self.apps:setValues(apps) + + self:updateChoices() + + UI.Tab.enable(self) +end + +function tab:eventHandler(event) + if event.type == 'grid_focus_row' and event.element == self.apps then + self:updateChoices() + + elseif event.type == 'grid_select' and event.element == self.choices then + local app = self.apps:getSelected().name + Array.removeByValue(self.config[app], event.selected.file) + table.insert(self.config[app], 1, event.selected.file) + self:updateChoices() + Config.update('alternate', self.config) + + else + return UI.Tab.eventHandler(self, event) + end + return true +end + +return tab diff --git a/sys/autorun/hotkeys.lua b/sys/autorun/hotkeys.lua index 5c6b539..cbd93bf 100644 --- a/sys/autorun/hotkeys.lua +++ b/sys/autorun/hotkeys.lua @@ -42,7 +42,7 @@ keyboard.addHotkey('control-tab', function() return a.uid < b.uid end for _,tab in Util.spairs(tabs, compareTab) do - if not tab.hidden then + if not tab.hidden and not tab.noFocus then table.insert(visibleTabs, tab) end end diff --git a/sys/autorun/log.lua b/sys/autorun/log.lua index 4f53ed4..91bb193 100644 --- a/sys/autorun/log.lua +++ b/sys/autorun/log.lua @@ -54,6 +54,7 @@ if multishell and multishell.openTab then multishell.openTab({ title = 'System Log', fn = systemLog, + noTerminate = true, hidden = true, }) else diff --git a/sys/modules/opus/alternate.lua b/sys/modules/opus/alternate.lua index 6f0d24f..101de58 100644 --- a/sys/modules/opus/alternate.lua +++ b/sys/modules/opus/alternate.lua @@ -6,7 +6,7 @@ local function getConfig() return Config.load('alternate', { shell = { 'sys/apps/shell.lua', - 'rom/programs/shell', + 'rom/programs/shell.lua', }, lua = { 'sys/apps/Lua.lua',