updates for environment handling changes
This commit is contained in:
@@ -57,7 +57,7 @@ local function downloadApp(app)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function runApp(app, checkExists, ...)
|
local function runApp(app, checkExists, ...)
|
||||||
local env = shell.makeEnv()
|
local env = shell.makeEnv(_ENV)
|
||||||
local path, fn
|
local path, fn
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
|
|
||||||
@@ -83,9 +83,8 @@ local function runApp(app, checkExists, ...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
multishell.openTab({
|
multishell.openTab(_ENV, {
|
||||||
title = app.name,
|
title = app.name,
|
||||||
env = env,
|
|
||||||
path = path,
|
path = path,
|
||||||
fn = fn,
|
fn = fn,
|
||||||
focused = true,
|
focused = true,
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ local page = UI.Page {
|
|||||||
self.menuBar:draw()
|
self.menuBar:draw()
|
||||||
|
|
||||||
elseif event.type == 'grid_select' then
|
elseif event.type == 'grid_select' then
|
||||||
multishell.openTab({
|
multishell.openTab(_ENV, {
|
||||||
path = 'sys/apps/Lua.lua',
|
path = 'sys/apps/Lua.lua',
|
||||||
args = { event.selected },
|
args = { event.selected },
|
||||||
focused = true,
|
focused = true,
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ page = UI.Page {
|
|||||||
fn = 'turtle.turnRight',
|
fn = 'turtle.turnRight',
|
||||||
},
|
},
|
||||||
info = UI.TextArea {
|
info = UI.TextArea {
|
||||||
x = 15, y = 2,
|
x = 15, y = 1,
|
||||||
inactive = true,
|
inactive = true,
|
||||||
},
|
},
|
||||||
showBlocks = function(self)
|
showBlocks = function(self)
|
||||||
@@ -240,13 +240,13 @@ page = UI.Page {
|
|||||||
return string.format('%s\n%s\n%s', bu, bf, bd)
|
return string.format('%s\n%s\n%s', bu, bf, bd)
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local s, m = self:runFunction(script, true)
|
local s, m = page:runFunction(script, true)
|
||||||
self.info:setText(s or m)
|
self.info:setText(s or m)
|
||||||
end,
|
end,
|
||||||
eventHandler = function(self, event)
|
eventHandler = function(self, event)
|
||||||
if event.type == 'button_press' then
|
if event.type == 'button_press' then
|
||||||
if event.button.fn then
|
if event.button.fn then
|
||||||
self:runFunction(event.button.fn, event.button.nowrap)
|
page:runFunction(event.button.fn, event.button.nowrap)
|
||||||
self:showBlocks()
|
self:showBlocks()
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ _G._syslog = function(...)
|
|||||||
local oldTerm = term.redirect(mon)
|
local oldTerm = term.redirect(mon)
|
||||||
Util.print(...)
|
Util.print(...)
|
||||||
term.redirect(oldTerm)
|
term.redirect(oldTerm)
|
||||||
|
oldDebug(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
|
|||||||
@@ -1024,7 +1024,7 @@ actions = {
|
|||||||
else
|
else
|
||||||
local fn, msg = load(_concat(tLines, '\n'), fileInfo.path)
|
local fn, msg = load(_concat(tLines, '\n'), fileInfo.path)
|
||||||
if fn then
|
if fn then
|
||||||
multishell.openTab({
|
multishell.openTab(_ENV, {
|
||||||
fn = fn,
|
fn = fn,
|
||||||
focused = true,
|
focused = true,
|
||||||
title = fs.getName(fileInfo.path),
|
title = fs.getName(fileInfo.path),
|
||||||
@@ -1544,5 +1544,5 @@ local s, m = pcall(function() UI:start() end)
|
|||||||
if not s then
|
if not s then
|
||||||
actions.save('/crash.txt')
|
actions.save('/crash.txt')
|
||||||
print('Editor has crashed. File saved as /crash.txt')
|
print('Editor has crashed. File saved as /crash.txt')
|
||||||
error(m)
|
error(m, -1)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
_G.requireInjector(_ENV)
|
|
||||||
local config = require('opus.config').load('gps')
|
local config = require('opus.config').load('gps')
|
||||||
if config.home then
|
if config.home then
|
||||||
if turtle.enableGPS() then
|
if turtle.enableGPS() then
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
turtle.run(function()
|
turtle.run(function()
|
||||||
_G.requireInjector(_ENV)
|
|
||||||
|
|
||||||
local GPS = require('opus.gps')
|
local GPS = require('opus.gps')
|
||||||
|
|
||||||
if not turtle.enableGPS() then
|
if not turtle.enableGPS() then
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
_G.requireInjector(_ENV)
|
|
||||||
local Config = require('opus.config')
|
local Config = require('opus.config')
|
||||||
local pt = turtle.enableGPS()
|
local pt = turtle.enableGPS()
|
||||||
if pt then
|
if pt then
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
local function summon(id)
|
local function summon(id)
|
||||||
|
|
||||||
_G.requireInjector(_ENV)
|
|
||||||
|
|
||||||
local GPS = require('opus.gps')
|
local GPS = require('opus.gps')
|
||||||
local Point = require('opus.point')
|
local Point = require('opus.point')
|
||||||
local Socket = require('opus.socket')
|
local Socket = require('opus.socket')
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ end
|
|||||||
|
|
||||||
if options.daemon then
|
if options.daemon then
|
||||||
_G.device.keyboard.addHotkey('control-P', function()
|
_G.device.keyboard.addHotkey('control-P', function()
|
||||||
multishell.openTab({
|
multishell.openTab(_ENV, {
|
||||||
path = 'sys/apps/shell.lua',
|
path = 'sys/apps/shell.lua',
|
||||||
args = { arg[0], '--noResize', '--rawOutput', 'recorder.gif' },
|
args = { arg[0], '--noResize', '--rawOutput', 'recorder.gif' },
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
local Alt = require('opus.alternate')
|
||||||
local Terminal = require('opus.terminal')
|
local Terminal = require('opus.terminal')
|
||||||
local trace = require('opus.trace')
|
local trace = require('opus.trace')
|
||||||
local Util = require('opus.util')
|
local Util = require('opus.util')
|
||||||
@@ -25,8 +26,7 @@ local monName = args[1]
|
|||||||
local running
|
local running
|
||||||
local parentMon
|
local parentMon
|
||||||
|
|
||||||
local defaultEnv = Util.shallowCopy(_ENV)
|
_ENV.multishell = multishell
|
||||||
defaultEnv.multishell = multishell
|
|
||||||
if monName then
|
if monName then
|
||||||
parentMon = peripheral.wrap(monName) or syntax()
|
parentMon = peripheral.wrap(monName) or syntax()
|
||||||
else
|
else
|
||||||
@@ -93,8 +93,8 @@ end
|
|||||||
--[[ A runnable process ]]--
|
--[[ A runnable process ]]--
|
||||||
local Process = { }
|
local Process = { }
|
||||||
|
|
||||||
function Process:new(args)
|
function Process:new(env, args)
|
||||||
args.env = args.env or Util.shallowCopy(defaultEnv)
|
args.env = shell.makeEnv(env)
|
||||||
args.width = args.width or termDim.width
|
args.width = args.width or termDim.width
|
||||||
args.height = args.height or termDim.height
|
args.height = args.height or termDim.height
|
||||||
|
|
||||||
@@ -329,7 +329,7 @@ function multishell.getTabs()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function multishell.launch(env, file, ...)
|
function multishell.launch(env, file, ...)
|
||||||
return multishell.openTab({
|
return multishell.openTab(env, {
|
||||||
path = file,
|
path = file,
|
||||||
env = env,
|
env = env,
|
||||||
title = 'shell',
|
title = 'shell',
|
||||||
@@ -337,8 +337,8 @@ function multishell.launch(env, file, ...)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function multishell.openTab(tabInfo)
|
function multishell.openTab(env, tabInfo)
|
||||||
local process = Process:new(tabInfo)
|
local process = Process:new(env, tabInfo)
|
||||||
|
|
||||||
table.insert(processes, 1, process)
|
table.insert(processes, 1, process)
|
||||||
|
|
||||||
@@ -380,7 +380,7 @@ function multishell.loadSession(filename)
|
|||||||
local config = Util.readTable(filename)
|
local config = Util.readTable(filename)
|
||||||
if config then
|
if config then
|
||||||
for k = #config, 1, -1 do
|
for k = #config, 1, -1 do
|
||||||
multishell.openTab(config[k])
|
multishell.openTab(_ENV, config[k])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -497,7 +497,7 @@ local function addShell()
|
|||||||
process.co = coroutine.create(function()
|
process.co = coroutine.create(function()
|
||||||
print('To run a program on the monitor, type "fg <program>"')
|
print('To run a program on the monitor, type "fg <program>"')
|
||||||
print('To quit, type "exit"')
|
print('To quit, type "exit"')
|
||||||
os.run(Util.shallowCopy(defaultEnv), shell.resolveProgram('shell'))
|
os.run(shell.makeEnv(_ENV), Alt.get('shell'))
|
||||||
multishell.stop()
|
multishell.stop()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ function page:eventHandler(event)
|
|||||||
self:scan()
|
self:scan()
|
||||||
|
|
||||||
elseif event.type == 'grid_select' and event.element == self.detail.grid then
|
elseif event.type == 'grid_select' and event.element == self.detail.grid then
|
||||||
multishell.openTab({
|
multishell.openTab(_ENV, {
|
||||||
path = 'sys/apps/Lua.lua',
|
path = 'sys/apps/Lua.lua',
|
||||||
args = { event.selected },
|
args = { event.selected },
|
||||||
focused = true,
|
focused = true,
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ local function update()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
kernel.run({
|
kernel.run(_ENV, {
|
||||||
hidden = true,
|
hidden = true,
|
||||||
fn = update,
|
fn = update,
|
||||||
})
|
})
|
||||||
|
|||||||
134
neural/nwm.lua
134
neural/nwm.lua
@@ -11,10 +11,11 @@ local Glasses = require('neural.glasses')
|
|||||||
local UI = require('opus.ui')
|
local UI = require('opus.ui')
|
||||||
local Util = require('opus.util')
|
local Util = require('opus.util')
|
||||||
|
|
||||||
local fs = _G.fs
|
local device = _G.device
|
||||||
local kernel = _G.kernel
|
local fs = _G.fs
|
||||||
local multishell = _ENV.multishell
|
local kernel = _G.kernel
|
||||||
local shell = _ENV.shell
|
local shell = _ENV.shell
|
||||||
|
local window = _G.window
|
||||||
|
|
||||||
local config = Config.load('nwm', { session = { } })
|
local config = Config.load('nwm', { session = { } })
|
||||||
|
|
||||||
@@ -22,6 +23,14 @@ local config = Config.load('nwm', { session = { } })
|
|||||||
local scale = .5
|
local scale = .5
|
||||||
local xs, ys = 6 * scale, 9 * scale
|
local xs, ys = 6 * scale, 9 * scale
|
||||||
local dragging
|
local dragging
|
||||||
|
local canvas = device['plethora:glasses'].canvas()
|
||||||
|
local cw, ch = canvas.getSize()
|
||||||
|
local opacity = 127
|
||||||
|
|
||||||
|
local multishell = Util.shallowCopy(_ENV.multishell)
|
||||||
|
_ENV.multishell = multishell
|
||||||
|
|
||||||
|
cw, ch = cw / xs, ch / ys
|
||||||
|
|
||||||
local events = {
|
local events = {
|
||||||
glasses_click = 'mouse_click',
|
glasses_click = 'mouse_click',
|
||||||
@@ -42,7 +51,7 @@ local function hook(e, eventData)
|
|||||||
elseif e == 'glasses_drag' then
|
elseif e == 'glasses_drag' then
|
||||||
local dx = x - dragging.ax
|
local dx = x - dragging.ax
|
||||||
local dy = y - dragging.ay
|
local dy = y - dragging.ay
|
||||||
dragging.tab.window.move(dragging.wx + dx, dragging.wy + dy)
|
dragging.tab.gwindow.move(dragging.wx + dx, dragging.wy + dy)
|
||||||
dragging.tab.titleBar.move(dragging.wx + dx, dragging.wy + dy - 1)
|
dragging.tab.titleBar.move(dragging.wx + dx, dragging.wy + dy - 1)
|
||||||
|
|
||||||
dragging.tab.wmargs.x = dragging.wx + dx
|
dragging.tab.wmargs.x = dragging.wx + dx
|
||||||
@@ -53,9 +62,9 @@ local function hook(e, eventData)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for _,tab in ipairs(kernel.routines) do
|
for _,tab in ipairs(kernel.routines) do
|
||||||
if tab.window.type == 'glasses' then
|
if tab.gwindow then
|
||||||
local wx, wy = tab.window.getPosition()
|
local wx, wy = tab.gwindow.getPosition()
|
||||||
local ww, wh = tab.window.getSize()
|
local ww, wh = tab.gwindow.getSize()
|
||||||
|
|
||||||
if x >= wx and x <= wx + ww and y > wy and y < wy + wh then
|
if x >= wx and x <= wx + ww and y > wy and y < wy + wh then
|
||||||
clicked = tab
|
clicked = tab
|
||||||
@@ -75,46 +84,90 @@ local function hook(e, eventData)
|
|||||||
|
|
||||||
if clicked then
|
if clicked then
|
||||||
if clicked ~= current then
|
if clicked ~= current then
|
||||||
clicked.window.raise()
|
clicked.gwindow.raise()
|
||||||
kernel.raise(clicked.uid)
|
kernel.raise(clicked.uid)
|
||||||
end
|
end
|
||||||
|
|
||||||
kernel.event(events[e], {
|
kernel.event(events[e], {
|
||||||
eventData[1], x, y, clicked.window.side,
|
eventData[1], x, y, clicked.gwindow.side,
|
||||||
})
|
})
|
||||||
|
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function run(args)
|
function multishell.openTab(env, tab)
|
||||||
|
if not tab.wmargs then
|
||||||
|
tab.wmargs = {
|
||||||
|
x = math.random(1, cw - 51 + 1),
|
||||||
|
y = math.random(1, ch - 19 + 1),
|
||||||
|
width = 51,
|
||||||
|
height = 19,
|
||||||
|
opacity = opacity,
|
||||||
|
path = tab.path,
|
||||||
|
args = tab.args,
|
||||||
|
}
|
||||||
|
table.insert(config.session, tab.wmargs)
|
||||||
|
Config.update('nwm', config)
|
||||||
|
else
|
||||||
|
tab.path = tab.wmargs.path
|
||||||
|
tab.args = tab.wmargs.args
|
||||||
|
end
|
||||||
|
|
||||||
|
if tab.path ~= 'sys/apps/shell.lua' then
|
||||||
|
if tab.args and #tab.args > 0 then
|
||||||
|
tab.args = { tab.path .. ' ' .. table.concat(tab.args or { }, ' ') }
|
||||||
|
else
|
||||||
|
tab.args = { tab.path }
|
||||||
|
end
|
||||||
|
tab.path = 'sys/apps/shell.lua'
|
||||||
|
end
|
||||||
|
|
||||||
|
local wmargs = tab.wmargs
|
||||||
|
|
||||||
local titleBar = Glasses.create({
|
local titleBar = Glasses.create({
|
||||||
x = args.x,
|
x = wmargs.x,
|
||||||
y = args.y - 1,
|
y = wmargs.y - 1,
|
||||||
height = 1,
|
height = 1,
|
||||||
width = args.width,
|
width = wmargs.width,
|
||||||
opacity = args.opacity,
|
opacity = wmargs.opacity,
|
||||||
})
|
})
|
||||||
titleBar.canvas:clear('yellow')
|
titleBar.canvas:clear('yellow')
|
||||||
titleBar.canvas:write(1, 1, ' ' .. fs.getName(args.path), nil, 'black')
|
titleBar.canvas:write(1, 1, ' ' .. fs.getName(tab.path), nil, 'black')
|
||||||
titleBar.canvas:write(args.width - 2, 1, ' x ', nil, 'black')
|
titleBar.canvas:write(wmargs.width - 2, 1, ' x ', nil, 'black')
|
||||||
titleBar.redraw()
|
titleBar.redraw()
|
||||||
|
|
||||||
kernel.run({
|
if not tab.title and tab.path then
|
||||||
path = args.path,
|
tab.title = fs.getName(tab.path):match('([^%.]+)')
|
||||||
args = args.args,
|
end
|
||||||
hidden = true,
|
tab.hidden = true
|
||||||
title = fs.getName(args.path),
|
tab.title = tab.title or 'untitled'
|
||||||
onExit = function(self)
|
|
||||||
Util.removeByValue(config.session, args)
|
local w, h = device.terminal.getSize()
|
||||||
Config.update('nwm', config)
|
tab.window = window.create(device.terminal, 1, 2, w, h - 1, false)
|
||||||
self.window.destroy()
|
tab.gwindow = Glasses.create(wmargs)
|
||||||
titleBar.destroy()
|
tab.terminal = tab.gwindow
|
||||||
end,
|
tab.titleBar = titleBar
|
||||||
window = Glasses.create(args),
|
tab.onExit = tab.onExit or function(self)
|
||||||
titleBar = titleBar,
|
Util.removeByValue(config.session, tab.wmargs)
|
||||||
wmargs = args,
|
Config.update('nwm', config)
|
||||||
})
|
self.gwindow.destroy()
|
||||||
|
self.titleBar.destroy()
|
||||||
|
end
|
||||||
|
|
||||||
|
local routine, message = kernel.run(env, tab)
|
||||||
|
return routine and routine.uid, message
|
||||||
|
end
|
||||||
|
|
||||||
|
function multishell.setTitle(tabId, title)
|
||||||
|
local tab = kernel.find(tabId)
|
||||||
|
if tab then
|
||||||
|
tab.title = title
|
||||||
|
tab.titleBar.canvas:clear('yellow')
|
||||||
|
tab.titleBar.canvas:write(1, 1, ' ' .. title, nil, 'black')
|
||||||
|
tab.titleBar.canvas:write(tab.wmargs.width - 2, 1, ' x ', nil, 'black')
|
||||||
|
tab.titleBar.redraw()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
UI:setPage(UI.Page {
|
UI:setPage(UI.Page {
|
||||||
@@ -131,6 +184,12 @@ UI:setPage(UI.Page {
|
|||||||
formLabel = 'Opacity', formKey = 'opacity', formIndex = 3,
|
formLabel = 'Opacity', formKey = 'opacity', formIndex = 3,
|
||||||
labelWidth = 3,
|
labelWidth = 3,
|
||||||
transform = math.floor,
|
transform = math.floor,
|
||||||
|
eventHandler = function(self, event)
|
||||||
|
if event.type == 'slider_update' then
|
||||||
|
opacity = event.value
|
||||||
|
end
|
||||||
|
return UI.Slider.eventHandler(self, event)
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
UI.Text {
|
UI.Text {
|
||||||
x = 10, y = 5,
|
x = 10, y = 5,
|
||||||
@@ -168,14 +227,15 @@ UI:setPage(UI.Page {
|
|||||||
if event.type == 'form_complete' then
|
if event.type == 'form_complete' then
|
||||||
local opts = Util.shallowCopy(event.values)
|
local opts = Util.shallowCopy(event.values)
|
||||||
local words = Util.split(opts.run, '(.-) ')
|
local words = Util.split(opts.run, '(.-) ')
|
||||||
opts.path = shell.resolveProgram(table.remove(words, 1))
|
words[1] = shell.resolveProgram(words[1])
|
||||||
if not opts.path then
|
if not words[1] then
|
||||||
self.notification:error('Invalid program')
|
self.notification:error('Invalid program')
|
||||||
else
|
else
|
||||||
opts.args = #words > 0 and words
|
opts.path = 'sys/apps/shell.lua'
|
||||||
|
opts.args = table.concat(words, ' ')
|
||||||
table.insert(config.session, opts)
|
table.insert(config.session, opts)
|
||||||
Config.update('nwm', config)
|
Config.update('nwm', config)
|
||||||
run(opts)
|
multishell.openTab(_ENV, { wmargs = opts })
|
||||||
self.notification:success('Started program')
|
self.notification:success('Started program')
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -190,7 +250,7 @@ local hookEvents = Util.keys(events)
|
|||||||
kernel.hook(hookEvents, hook)
|
kernel.hook(hookEvents, hook)
|
||||||
|
|
||||||
for _,v in pairs(config.session) do
|
for _,v in pairs(config.session) do
|
||||||
run(v)
|
multishell.openTab(_ENV, { wmargs = v })
|
||||||
end
|
end
|
||||||
|
|
||||||
UI:start()
|
UI:start()
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ local function showScreenSaver()
|
|||||||
|
|
||||||
local w, h = kernel.terminal.getSize()
|
local w, h = kernel.terminal.getSize()
|
||||||
local win = window.create(kernel.terminal, 1, 1, w, h, true)
|
local win = window.create(kernel.terminal, 1, 1, w, h, true)
|
||||||
saverUid = multishell.openTab({
|
saverUid = multishell.openTab(_ENV, {
|
||||||
path = saver,
|
path = saver,
|
||||||
focused = true,
|
focused = true,
|
||||||
title = 'Saver',
|
title = 'Saver',
|
||||||
|
|||||||
@@ -7,109 +7,107 @@ local keyboard = device.keyboard
|
|||||||
local multishell = _ENV.multishell
|
local multishell = _ENV.multishell
|
||||||
|
|
||||||
if not multishell then
|
if not multishell then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local config = Config.load('secure', {
|
local config = Config.load('secure', {
|
||||||
enabled = false,
|
enabled = false,
|
||||||
timeout = 60,
|
timeout = 60,
|
||||||
})
|
})
|
||||||
|
|
||||||
local timer = config.enabled and os.startTimer(config.timeout)
|
local timer = config.enabled and os.startTimer(config.timeout)
|
||||||
|
|
||||||
local function buildLockScreen()
|
local function buildLockScreen()
|
||||||
_G.requireInjector(_ENV)
|
local Event = require('opus.event')
|
||||||
|
local Security = require('opus.security')
|
||||||
|
local SHA = require('opus.crypto.sha2')
|
||||||
|
local UI = require('opus.ui')
|
||||||
|
|
||||||
local Event = require('opus.event')
|
local counter = .1
|
||||||
local Security = require('opus.security')
|
|
||||||
local SHA = require('opus.crypto.sha2')
|
|
||||||
local UI = require('opus.ui')
|
|
||||||
|
|
||||||
local counter = .1
|
local page = UI.Page {
|
||||||
|
pass = UI.TextEntry {
|
||||||
|
x = 10, ex = -10, y = "50%",
|
||||||
|
limit = 32,
|
||||||
|
mask = true,
|
||||||
|
shadowText = 'password',
|
||||||
|
accelerators = {
|
||||||
|
enter = 'password',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
notification = UI.Notification(),
|
||||||
|
}
|
||||||
|
function page:eventHandler(event)
|
||||||
|
if event.type == 'password' then
|
||||||
|
|
||||||
local page = UI.Page {
|
if self.pass.value and
|
||||||
pass = UI.TextEntry {
|
#self.pass.value > 0 and
|
||||||
x = 10, ex = -10, y = "50%",
|
Security.verifyPassword(SHA.compute(self.pass.value)) then
|
||||||
limit = 32,
|
|
||||||
mask = true,
|
|
||||||
shadowText = 'password',
|
|
||||||
accelerators = {
|
|
||||||
enter = 'password',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
notification = UI.Notification(),
|
|
||||||
}
|
|
||||||
function page:eventHandler(event)
|
|
||||||
if event.type == 'password' then
|
|
||||||
|
|
||||||
if self.pass.value and
|
UI:quit() -- valid
|
||||||
#self.pass.value > 0 and
|
else
|
||||||
Security.verifyPassword(SHA.compute(self.pass.value)) then
|
self.notification:error('Invalid password', math.max(counter, 2))
|
||||||
|
self:sync()
|
||||||
|
os.sleep(counter)
|
||||||
|
counter = counter * 2
|
||||||
|
|
||||||
UI:quit() -- valid
|
self.pass:reset()
|
||||||
else
|
end
|
||||||
self.notification:error('Invalid password', math.max(counter, 2))
|
else
|
||||||
self:sync()
|
UI.Page.eventHandler(self, event)
|
||||||
os.sleep(counter)
|
end
|
||||||
counter = counter * 2
|
end
|
||||||
|
|
||||||
self.pass:reset()
|
Event.onTerminate(function() return false end)
|
||||||
end
|
|
||||||
else
|
|
||||||
UI.Page.eventHandler(self, event)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Event.onTerminate(function() return false end)
|
UI:setPage(page)
|
||||||
|
UI:start()
|
||||||
|
|
||||||
UI:setPage(page)
|
-- restart lock timer
|
||||||
UI:start()
|
timer = os.startTimer(config.timeout)
|
||||||
|
|
||||||
-- restart lock timer
|
|
||||||
timer = os.startTimer(config.timeout)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function showLockScreen()
|
local function showLockScreen()
|
||||||
timer = nil
|
timer = nil
|
||||||
multishell.openTab({
|
multishell.openTab(_ENV, {
|
||||||
path = 'sys/apps/Lock.lua',
|
path = 'sys/apps/Lock.lua',
|
||||||
fn = buildLockScreen,
|
fn = buildLockScreen,
|
||||||
noTerminate = true,
|
noTerminate = true,
|
||||||
pinned = true,
|
pinned = true,
|
||||||
focused = true,
|
focused = true,
|
||||||
title = 'Lock',
|
title = 'Lock',
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
keyboard.addHotkey('control-l', function()
|
keyboard.addHotkey('control-l', function()
|
||||||
if timer then
|
if timer then
|
||||||
os.cancelTimer(timer)
|
os.cancelTimer(timer)
|
||||||
showLockScreen()
|
showLockScreen()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
kernel.hook({ 'mouse_up', 'mouse_drag', 'key_up', 'mouse_scroll' }, function()
|
kernel.hook({ 'mouse_up', 'mouse_drag', 'key_up', 'mouse_scroll' }, function()
|
||||||
if timer then
|
if timer then
|
||||||
os.cancelTimer(timer)
|
os.cancelTimer(timer)
|
||||||
timer = os.startTimer(config.timeout)
|
timer = os.startTimer(config.timeout)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
kernel.hook('timer', function(_, eventData)
|
kernel.hook('timer', function(_, eventData)
|
||||||
if timer and eventData[1] == timer then
|
if timer and eventData[1] == timer then
|
||||||
showLockScreen()
|
showLockScreen()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
kernel.hook('config_update', function(_, eventData)
|
kernel.hook('config_update', function(_, eventData)
|
||||||
if eventData[1] == 'secure' then
|
if eventData[1] == 'secure' then
|
||||||
Util.merge(config, eventData[2])
|
Util.merge(config, eventData[2])
|
||||||
if timer then
|
if timer then
|
||||||
os.cancelTimer(timer)
|
os.cancelTimer(timer)
|
||||||
timer = nil
|
timer = nil
|
||||||
end
|
end
|
||||||
if config.enabled then
|
if config.enabled then
|
||||||
timer = os.startTimer(config.timeout)
|
timer = os.startTimer(config.timeout)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -16,15 +16,15 @@ term.setCursorPos(1, 1)
|
|||||||
term.clear()
|
term.clear()
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
local s, m = pcall(function()
|
local s, m = pcall(function()
|
||||||
local password = Terminal.readPassword('Enter password: ')
|
local password = Terminal.readPassword('Enter password: ')
|
||||||
|
|
||||||
if password and Security.verifyPassword(SHA.compute(password)) then
|
if password and Security.verifyPassword(SHA.compute(password)) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
error('Invalid password')
|
error('Invalid password')
|
||||||
end)
|
end)
|
||||||
if not s and m then
|
if not s and m then
|
||||||
_G.printError(m)
|
_G.printError(m)
|
||||||
end
|
end
|
||||||
until s
|
until s
|
||||||
|
|||||||
Reference in New Issue
Block a user