1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-28 01:20:27 +00:00

vnc auto-reconnect

This commit is contained in:
kepler155c@gmail.com 2018-11-10 13:00:22 -05:00
parent 10a0c3a724
commit b3a061d39b
2 changed files with 141 additions and 108 deletions

View File

@ -141,8 +141,9 @@ local systemPage = UI.Page {
}
if turtle then
pcall(function()
local Home = require('turtle.home')
-- TODO: dont rely on turtle.home
local values = { }
Config.load('gps', values.home and { values.home } or { })
@ -196,6 +197,7 @@ if turtle then
return true
end
end
end)
end
if settings then

View File

@ -7,6 +7,7 @@ local Util = require('util')
local colors = _G.colors
local multishell = _ENV.multishell
local os = _G.os
local term = _G.term
local remoteId
@ -26,14 +27,14 @@ if multishell then
multishell.setTitle(multishell.getCurrent(), 'VNC-' .. remoteId)
end
print('connecting...')
local socket, msg = Socket.connect(remoteId, 5900)
local function connect()
local socket, msg = Socket.connect(remoteId, 5900)
if not socket then
error(msg)
end
if not socket then
return false, msg
end
local function writeTermInfo()
local function writeTermInfo()
local w, h = term.getSize()
socket:write({
type = 'termInfo',
@ -41,45 +42,42 @@ local function writeTermInfo()
height = h,
isColor = term.isColor(),
})
end
end
writeTermInfo()
writeTermInfo()
local ct = Util.shallowCopy(term.current())
local ct = Util.shallowCopy(term.current())
if not ct.isColor() then
if not ct.isColor() then
Terminal.toGrayscale(ct)
end
end
Event.addRoutine(function()
ct.clear()
ct.setCursorPos(1, 1)
Event.addRoutine(function()
while true do
local data = socket:read()
if not data then
_debug('exiting routine')
break
end
for _,v in ipairs(data) do
ct[v.f](unpack(v.args))
end
end
end)
end)
ct.clear()
ct.setCursorPos(1, 1)
local filter = Util.transpose({
local filter = Util.transpose({
'char', 'paste', 'key', 'key_up',
'mouse_scroll', 'mouse_click', 'mouse_drag', 'mouse_up',
})
})
while true do
while true do
local e = Event.pullEvent()
local event = e[1]
if not socket.connected then
print()
print('Connection lost')
print('Press enter to exit')
_G.read()
break
end
@ -95,6 +93,39 @@ while true do
ct.setBackgroundColor(colors.black)
ct.clear()
ct.setCursorPos(1, 1)
return true
end
end
return false, "Connection Lost"
end
while true do
term.clear()
term.setCursorPos(1, 1)
print('connecting...')
local s, m = connect()
if s then
break
end
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.clear()
term.setCursorPos(1, 1)
print(m)
print('\nPress any key to exit')
print('\nRetrying in ... ')
local x, y = term.getCursorPos()
for i = 5, 1, -1 do
local timerId = os.startTimer(1)
term.setCursorPos(x, y)
term.write(i)
repeat
local e, id = os.pullEvent()
if e == 'char' or e == 'key' then
return
end
until e == 'timer' and id == timerId
end
end