mirror of
				https://github.com/kepler155c/opus
				synced 2025-10-31 15:43:00 +00:00 
			
		
		
		
	cleanup
This commit is contained in:
		| @@ -5,7 +5,6 @@ local Util     = require('util') | ||||
|  | ||||
| local device    = _G.device | ||||
| local os        = _G.os | ||||
| --local transport = _G.transport | ||||
|  | ||||
| local socketClass = { } | ||||
|  | ||||
| @@ -109,7 +108,7 @@ end | ||||
| function Socket.connect(host, port) | ||||
|  | ||||
|   local socket = newSocket(host == os.getComputerID()) | ||||
|   socket.dhost = host | ||||
|   socket.dhost = tonumber(host) | ||||
|   Logger.log('socket', 'connecting to ' .. port) | ||||
|  | ||||
|   socket.transmit(port, socket.sport, { | ||||
|   | ||||
| @@ -121,7 +121,7 @@ function Manager:init() | ||||
|       local event = self:pointToChild(self.target, x, y) | ||||
|       _ENV.multishell.openTab({ | ||||
|         path = 'sys/apps/Lua.lua', | ||||
|         args = { event.element, self:dump(self.currentPage) }, | ||||
|         args = { event.element }, | ||||
|         focused = true }) | ||||
|  | ||||
|     elseif ch and self.currentPage then | ||||
| @@ -438,31 +438,6 @@ function Manager:exitPullEvents() | ||||
|   Event.exitPullEvents() | ||||
| end | ||||
|  | ||||
| function Manager:dump(inEl) | ||||
|   if inEl then | ||||
|     local function clean(el) | ||||
|       local o = el | ||||
|       el = Util.shallowCopy(el) | ||||
|       el.parent = nil | ||||
|       if el.children then | ||||
|         local children = { } | ||||
|         for k,c in pairs(el.children) do | ||||
|           children[k] = clean(c) | ||||
|         end | ||||
|         el.children = children | ||||
|       end | ||||
|       for k,v in pairs(o) do | ||||
|         if type(v) == 'table' and v.UIElement then | ||||
|           el[k] = nil | ||||
|         end | ||||
|       end | ||||
|  | ||||
|       return el | ||||
|     end | ||||
|     return clean(inEl) | ||||
|   end | ||||
| end | ||||
|  | ||||
| local UI = Manager() | ||||
|  | ||||
| --[[-- Basic drawable area --]]-- | ||||
|   | ||||
| @@ -262,7 +262,9 @@ end | ||||
| function Util.size(list) | ||||
|   if type(list) == 'table' then | ||||
|     local length = 0 | ||||
|     table.foreach(list, function() length = length + 1 end) | ||||
|     for _ in pairs(list) do | ||||
|       length = length + 1 | ||||
|     end | ||||
|     return length | ||||
|   end | ||||
|   return 0 | ||||
| @@ -433,8 +435,7 @@ function Util.runUrl(env, url, ...)   -- os.run equivalent | ||||
|   setmetatable(env, { __index = _G }) | ||||
|   local fn, m = Util.loadUrl(url, env) | ||||
|   if fn then | ||||
|     local args = { ... } | ||||
|     return pcall(function() return fn(table.unpack(args)) end) | ||||
|     return pcall(fn, ...) | ||||
|   end | ||||
|   return fn, m | ||||
| end | ||||
| @@ -443,8 +444,7 @@ function Util.run(env, path, ...) | ||||
|   setmetatable(env, { __index = _G }) | ||||
|   local fn, m = loadfile(path, env) | ||||
|   if fn then | ||||
|     local args = { ... } | ||||
|     return pcall(function() return fn(table.unpack(args)) end) | ||||
|     return pcall(fn, ...) | ||||
|   end | ||||
|   return fn, m | ||||
| end | ||||
| @@ -452,9 +452,7 @@ end | ||||
| function Util.runFunction(env, fn, ...) | ||||
|   setfenv(fn, env) | ||||
|   setmetatable(env, { __index = _G }) | ||||
|  | ||||
|   local args = { ... } | ||||
|   return pcall(function() return fn(table.unpack(args)) end) | ||||
|   return pcall(fn, ...) | ||||
| end | ||||
|  | ||||
| --[[ String functions ]] -- | ||||
|   | ||||
| @@ -35,7 +35,7 @@ local page = UI.Page { | ||||
|         UI.MenuBar.spacer, | ||||
|         { text = 'Reboot      r', event = 'reboot' }, | ||||
|       } }, | ||||
|       { text = 'Chat', event = 'chat' }, | ||||
|       --{ text = 'Chat', event = 'chat' }, | ||||
|       { text = 'Trust', dropdown = { | ||||
|         { text = 'Establish', event = 'trust'   }, | ||||
|         { text = 'Remove',    event = 'untrust' }, | ||||
| @@ -61,7 +61,6 @@ local page = UI.Page { | ||||
| } | ||||
|  | ||||
| local function sendCommand(host, command) | ||||
|  | ||||
|   if not device.wireless_modem then | ||||
|     page.notification:error('Wireless modem not present') | ||||
|     return | ||||
|   | ||||
| @@ -1,43 +0,0 @@ | ||||
| local device     = _G.device | ||||
| local multishell = _ENV.multishell | ||||
| local os         = _G.os | ||||
|  | ||||
| if device.wireless_modem and false then | ||||
|  | ||||
| 	multishell.setTitle(multishell.getCurrent(), 'Chat') | ||||
|  | ||||
| 	multishell.openTab({ | ||||
| 		path   = 'rom/programs/rednet/chat', | ||||
| 		args   = { 'host', 'opusChat-' .. os.getComputerID() }, | ||||
| 		title  = 'Chat Daemon', | ||||
| 		hidden = true, | ||||
| 	}) | ||||
|  | ||||
| 	local tab = multishell.getTab(multishell.getCurrent()) | ||||
|  | ||||
|   _G.requireInjector() | ||||
|  | ||||
| 	local Event = require('event') | ||||
| 	local Util  = require('util') | ||||
|  | ||||
| 	local h = Event.addRoutine(function() | ||||
| 		while true do | ||||
| 			Util.run(_ENV, 'rom/programs/rednet/chat', | ||||
| 				'join', 'opusChat-' .. os.getComputerID(), 'owner') | ||||
| 		end | ||||
| 	end) | ||||
|  | ||||
| 	while true do | ||||
| 		local e = { os.pullEventRaw() } | ||||
| 		if e[1] == 'terminate' then | ||||
| 			multishell.hideTab(tab.tabId) | ||||
| 		else | ||||
| 			if e[1] == 'rednet_message' and e[4] == 'chat' and e[3].sType == 'chat' then | ||||
| 				if tab.hidden then | ||||
| 					multishell.unhideTab(tab.tabId) | ||||
| 				end | ||||
| 			end | ||||
| 			h:resume(table.unpack(e)) | ||||
| 		end | ||||
| 	end | ||||
| end | ||||
| @@ -1,17 +1,25 @@ | ||||
| requireInjector(getfenv(1)) | ||||
| _G.requireInjector() | ||||
|  | ||||
| local Util = require('util') | ||||
|  | ||||
| local device     = _G.device | ||||
| local fs         = _G.fs | ||||
| local multishell = _ENV.multishell | ||||
| local os         = _G.os | ||||
| local printError = _G.printError | ||||
|  | ||||
| local network = { } | ||||
| _G.network = network | ||||
|  | ||||
| multishell.setTitle(multishell.getCurrent(), 'Net Daemon') | ||||
|  | ||||
| _G.network = { } | ||||
|  | ||||
| local function netUp() | ||||
|   requireInjector(getfenv(1)) | ||||
|   local Event = require('event') | ||||
|   _G.requireInjector() | ||||
|  | ||||
|   local Event = require('event') | ||||
| _G._e2 = _ENV | ||||
|   for _,file in pairs(fs.list('sys/network')) do | ||||
|     local fn, msg = Util.run(getfenv(1), 'sys/network/' .. file) | ||||
|     local fn, msg = Util.run(_ENV, 'sys/network/' .. file) | ||||
|     if not fn then | ||||
|       printError(msg) | ||||
|     end | ||||
| @@ -40,8 +48,10 @@ print('Net daemon started') | ||||
| local function startNetwork() | ||||
|   print('Starting network services') | ||||
|  | ||||
| _G._e1 = _ENV | ||||
|  | ||||
|   local success, msg = Util.runFunction( | ||||
|     Util.shallowCopy(getfenv(1)), netUp) | ||||
|     Util.shallowCopy(_ENV), netUp) | ||||
|  | ||||
|   if not success and msg then | ||||
|     printError(msg) | ||||
| @@ -56,7 +66,7 @@ else | ||||
| end | ||||
|  | ||||
| while true do | ||||
|   local e, deviceName = os.pullEvent('device_attach') | ||||
|   local _, deviceName = os.pullEvent('device_attach') | ||||
|   if deviceName == 'wireless_modem' then | ||||
|     startNetwork() | ||||
|   end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 kepler155c@gmail.com
					kepler155c@gmail.com