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