mirror of
				https://github.com/kepler155c/opus
				synced 2025-10-31 07:33:00 +00:00 
			
		
		
		
	alternate support
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
							
								
								
									
										80
									
								
								sys/apps/system/alternate.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								sys/apps/system/alternate.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
| @@ -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 | ||||
|   | ||||
| @@ -54,6 +54,7 @@ if multishell and multishell.openTab then | ||||
| 	multishell.openTab({ | ||||
| 		title = 'System Log', | ||||
| 		fn = systemLog, | ||||
| 		noTerminate = true, | ||||
| 		hidden = true, | ||||
| 	}) | ||||
| else | ||||
|   | ||||
| @@ -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', | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 kepler155c@gmail.com
					kepler155c@gmail.com