nwm opacity / improvements - env cleanup
This commit is contained in:
@@ -27,9 +27,6 @@ local function unregisterApp(key)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local sandboxEnv = Util.shallowCopy(_ENV)
|
|
||||||
setmetatable(sandboxEnv, { __index = _G })
|
|
||||||
|
|
||||||
multishell.setTitle(multishell.getCurrent(), 'App Store')
|
multishell.setTitle(multishell.getCurrent(), 'App Store')
|
||||||
UI:configure('Appstore', ...)
|
UI:configure('Appstore', ...)
|
||||||
|
|
||||||
@@ -60,7 +57,7 @@ local function downloadApp(app)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function runApp(app, checkExists, ...)
|
local function runApp(app, checkExists, ...)
|
||||||
|
local env = shell.makeEnv()
|
||||||
local path, fn
|
local path, fn
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
|
|
||||||
@@ -81,14 +78,14 @@ local function runApp(app, checkExists, ...)
|
|||||||
error('Failed to download')
|
error('Failed to download')
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.setfenv(fn, sandboxEnv)
|
_G.setfenv(fn, env)
|
||||||
fn(table.unpack(args))
|
fn(table.unpack(args))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
multishell.openTab({
|
multishell.openTab({
|
||||||
title = app.name,
|
title = app.name,
|
||||||
env = sandboxEnv,
|
env = env,
|
||||||
path = path,
|
path = path,
|
||||||
fn = fn,
|
fn = fn,
|
||||||
focused = true,
|
focused = true,
|
||||||
|
|||||||
@@ -3,55 +3,64 @@
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
local Terminal = require('opus.terminal')
|
local Terminal = require('opus.terminal')
|
||||||
|
local Util = require('opus.util')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
|
|
||||||
local scale = .5
|
|
||||||
local xs, ys = 6 * scale, 9 * scale
|
|
||||||
|
|
||||||
local Glasses = { }
|
local Glasses = { }
|
||||||
|
|
||||||
function Glasses.create(name, sx, sy, w, h)
|
function Glasses.create(args)
|
||||||
w, h = w or 46, h or 19
|
local opts = {
|
||||||
sx, sy = sx or 1, sy or 20
|
x = 1, y = 20,
|
||||||
|
width = 51, height = 19,
|
||||||
|
scale = .5,
|
||||||
|
name = 'glasses',
|
||||||
|
opacity = 0xff,
|
||||||
|
}
|
||||||
|
Util.merge(opts, args)
|
||||||
|
|
||||||
|
local xs, ys = 6 * opts.scale, 9 * opts.scale
|
||||||
local glasses = device['plethora:glasses']
|
local glasses = device['plethora:glasses']
|
||||||
local canvas = glasses.canvas()
|
local canvas = glasses.canvas()
|
||||||
local _, cy = 1, 1
|
local _, cy = 1, 1
|
||||||
local lines = { }
|
local lines = { }
|
||||||
local map = {
|
local map = {
|
||||||
['0'] = 0xF0F0F0FF,
|
['0'] = 0xF0F0F000,
|
||||||
['1'] = 0xF2B233FF,
|
['1'] = 0xF2B23300,
|
||||||
['2'] = 0xE57FD8FF,
|
['2'] = 0xE57FD800,
|
||||||
['3'] = 0x99B2F2FF,
|
['3'] = 0x99B2F200,
|
||||||
['4'] = 0xDEDE6CFF,
|
['4'] = 0xDEDE6C00,
|
||||||
['5'] = 0x7FCC19FF,
|
['5'] = 0x7FCC1900,
|
||||||
['6'] = 0xF2B2CCFF,
|
['6'] = 0xF2B2CC00,
|
||||||
['7'] = 0x4C4C4CFF,
|
['7'] = 0x4C4C4C00,
|
||||||
['8'] = 0x999999FF,
|
['8'] = 0x99999900,
|
||||||
['9'] = 0x4C99B2FF,
|
['9'] = 0x4C99B200,
|
||||||
['a'] = 0xB266E5FF,
|
['a'] = 0xB266E500,
|
||||||
['b'] = 0x3366CCFF,
|
['b'] = 0x3366CC00,
|
||||||
['c'] = 0x7F664CFF,
|
['c'] = 0x7F664C00,
|
||||||
['d'] = 0x57A64EFF,
|
['d'] = 0x57A64E00,
|
||||||
['e'] = 0xCC4C4CFF,
|
['e'] = 0xCC4C4C00,
|
||||||
['f'] = 0x191919FF,
|
['f'] = 0x19191900,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for k,v in pairs(map) do
|
||||||
|
map[k] = v + opts.opacity
|
||||||
|
end
|
||||||
|
|
||||||
-- Position bottom left
|
-- Position bottom left
|
||||||
local pos = { x = sx * xs, y = sy * ys }
|
local pos = { x = opts.x * xs, y = opts.y * ys }
|
||||||
|
|
||||||
local function init(group)
|
local function init(group)
|
||||||
for y = 1, h do
|
for y = 1, opts.height do
|
||||||
lines[y] = {
|
lines[y] = {
|
||||||
text = { },
|
text = { },
|
||||||
bg = { }
|
bg = { }
|
||||||
}
|
}
|
||||||
for x = 1, w do
|
for x = 1, opts.width do
|
||||||
lines[y].bg[x] = group.addRectangle(x * xs, y * ys, xs, ys, 0xF0F0F04F)
|
lines[y].bg[x] = group.addRectangle(x * xs, y * ys, xs, ys, 0xF0F0F04F)
|
||||||
lines[y].text[x] = group.addText({ x * xs, y * ys }, '', 0x7FCC19FF)
|
lines[y].text[x] = group.addText({ x * xs, y * ys }, '', 0x7FCC19FF)
|
||||||
lines[y].text[x].setScale(scale)
|
lines[y].text[x].setScale(opts.scale)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -60,21 +69,9 @@ function Glasses.create(name, sx, sy, w, h)
|
|||||||
init(group)
|
init(group)
|
||||||
|
|
||||||
local gterm = Terminal.window({
|
local gterm = Terminal.window({
|
||||||
getSize = function()
|
|
||||||
return w, h
|
|
||||||
end,
|
|
||||||
isColor = function()
|
isColor = function()
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
clear = function()
|
|
||||||
for y = 1, h do
|
|
||||||
for x = 1, w do
|
|
||||||
local ln = lines[y]
|
|
||||||
ln.bg[x].setColor(0xF0F0F04F)
|
|
||||||
ln.text[x].setText('')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
blit = function(text, fg, bg)
|
blit = function(text, fg, bg)
|
||||||
for x = 1, #text do
|
for x = 1, #text do
|
||||||
local ln = lines[cy]
|
local ln = lines[cy]
|
||||||
@@ -86,19 +83,11 @@ function Glasses.create(name, sx, sy, w, h)
|
|||||||
setCursorPos = function(_, y)
|
setCursorPos = function(_, y)
|
||||||
cy = y -- full lines are always blit
|
cy = y -- full lines are always blit
|
||||||
end,
|
end,
|
||||||
getTextColor = function()
|
|
||||||
return colors.white
|
|
||||||
end,
|
|
||||||
setTextColor = function() end,
|
|
||||||
getBackgroundColor = function()
|
|
||||||
return colors.black
|
|
||||||
end,
|
|
||||||
setBackgroundColor = function() end,
|
|
||||||
setCursorBlink = function() end,
|
setCursorBlink = function() end,
|
||||||
}, 1, 1, w, h, true)
|
}, 1, 1, opts.width, opts.height, true)
|
||||||
|
|
||||||
function gterm.setTextScale() end
|
function gterm.setTextScale() end
|
||||||
function gterm.getPosition() return sx, sy end
|
function gterm.getPosition() return opts.x, opts.y end
|
||||||
function gterm.setVisible() end
|
function gterm.setVisible() end
|
||||||
function gterm.raise()
|
function gterm.raise()
|
||||||
local g = canvas.addGroup(pos)
|
local g = canvas.addGroup(pos)
|
||||||
@@ -110,9 +99,12 @@ function Glasses.create(name, sx, sy, w, h)
|
|||||||
function gterm.destroy()
|
function gterm.destroy()
|
||||||
group.remove()
|
group.remove()
|
||||||
end
|
end
|
||||||
|
function gterm.getTextScale()
|
||||||
|
return opts.scale
|
||||||
|
end
|
||||||
|
|
||||||
gterm.name = name
|
gterm.name = opts.name
|
||||||
gterm.side = name
|
gterm.side = opts.name
|
||||||
gterm.type = 'glasses'
|
gterm.type = 'glasses'
|
||||||
|
|
||||||
return gterm
|
return gterm
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ local kernel = _G.kernel
|
|||||||
local multishell = _ENV.multishell
|
local multishell = _ENV.multishell
|
||||||
local shell = _ENV.shell
|
local shell = _ENV.shell
|
||||||
|
|
||||||
local sandbox = Util.shallowCopy(_ENV)
|
local config = Config.load('nwm', { session = { } })
|
||||||
|
|
||||||
-- TODO: figure out how to better define scaling
|
-- TODO: figure out how to better define scaling
|
||||||
local scale = .5
|
local scale = .5
|
||||||
@@ -25,8 +25,6 @@ local events = {
|
|||||||
glasses_scroll = 'mouse_scroll',
|
glasses_scroll = 'mouse_scroll',
|
||||||
}
|
}
|
||||||
|
|
||||||
local hookEvents = { 'glasses_click', 'glasses_up', 'glasses_drag', 'glasses_scroll' }
|
|
||||||
|
|
||||||
local function hook(e, eventData)
|
local function hook(e, eventData)
|
||||||
local currentTab = kernel.getFocused()
|
local currentTab = kernel.getFocused()
|
||||||
local x = math.floor(eventData[2] / xs)
|
local x = math.floor(eventData[2] / xs)
|
||||||
@@ -61,19 +59,15 @@ local function hook(e, eventData)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local config = Config.load('nwm', { session = { } })
|
local hookEvents = Util.keys(events)
|
||||||
|
kernel.hook(hookEvents, hook)
|
||||||
|
|
||||||
local function run(args)
|
local function run(args)
|
||||||
local window = Glasses.create('glasses', args.x, args.y, args.w, args.h)
|
local window = Glasses.create(args)
|
||||||
|
|
||||||
local env = Util.shallowCopy(sandbox)
|
|
||||||
_G.requireInjector(env)
|
|
||||||
|
|
||||||
multishell.openTab({
|
multishell.openTab({
|
||||||
path = args.path,
|
path = args.path,
|
||||||
args = args.args,
|
args = args.args,
|
||||||
env = env,
|
|
||||||
focused = false,
|
|
||||||
hidden = true,
|
hidden = true,
|
||||||
onDestroy = function()
|
onDestroy = function()
|
||||||
Util.removeByValue(config.session, args)
|
Util.removeByValue(config.session, args)
|
||||||
@@ -84,66 +78,63 @@ local function run(args)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
kernel.hook(hookEvents, hook)
|
|
||||||
|
|
||||||
UI:setPage(UI.Page {
|
UI:setPage(UI.Page {
|
||||||
form = UI.Form {
|
form = UI.Form {
|
||||||
values = {
|
values = {
|
||||||
x = 1, y = 25, w = 51, h = 19,
|
x = 1, y = 25, width = 51, height = 19,
|
||||||
|
opacity = 255,
|
||||||
},
|
},
|
||||||
path = UI.TextEntry {
|
UI.TextEntry {
|
||||||
y = 5,
|
formKey = 'run', formLabel = 'Run', required = true,
|
||||||
formKey = 'path', formLabel = 'Run', required = true,
|
|
||||||
},
|
},
|
||||||
args = UI.TextEntry {
|
UI.Slider {
|
||||||
y = 7,
|
min = 0, max = 255,
|
||||||
formKey = 'args', formLabel = 'Args',
|
formLabel = 'Opacity', formKey = 'opacity', formIndex = 3,
|
||||||
},
|
},
|
||||||
UI.Text {
|
UI.Text {
|
||||||
x = 7, y = 5,
|
x = 10, y = 5,
|
||||||
textColor = 'yellow',
|
textColor = 'yellow',
|
||||||
value = ' x y'
|
value = ' x y'
|
||||||
},
|
},
|
||||||
wx = UI.TextEntry {
|
UI.TextEntry {
|
||||||
x = 7, y = 6, width = 7, limit = 3,
|
x = 10, y = 6, width = 7, limit = 3,
|
||||||
transform = 'number',
|
transform = 'number',
|
||||||
formKey = 'x', required = true,
|
formKey = 'x', required = true,
|
||||||
},
|
},
|
||||||
wy = UI.TextEntry {
|
UI.TextEntry {
|
||||||
x = 15, y = 6, width = 7, limit = 4,
|
x = 18, y = 6, width = 7, limit = 4,
|
||||||
transform = 'number',
|
transform = 'number',
|
||||||
formKey = 'y', required = true,
|
formKey = 'y', required = true,
|
||||||
},
|
},
|
||||||
UI.Text {
|
UI.Text {
|
||||||
x = 7, y = 8,
|
x = 10, y = 8,
|
||||||
textColor = 'yellow',
|
textColor = 'yellow',
|
||||||
value = ' width height'
|
value = ' width height'
|
||||||
},
|
},
|
||||||
ww = UI.TextEntry {
|
UI.TextEntry {
|
||||||
x = 7, y = 9, width = 7, limit = 4,
|
x = 10, y = 9, width = 7, limit = 4,
|
||||||
transform = 'number',
|
transform = 'number',
|
||||||
formKey = 'w', required = true,
|
formKey = 'width', required = true,
|
||||||
},
|
},
|
||||||
wh = UI.TextEntry {
|
UI.TextEntry {
|
||||||
x = 15, y = 9, width = 7, limit = 4,
|
x = 18, y = 9, width = 7, limit = 4,
|
||||||
transform = 'number',
|
transform = 'number',
|
||||||
formKey = 'h', required = true,
|
formKey = 'height', required = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
notification = UI.Notification { },
|
notification = UI.Notification { },
|
||||||
eventHandler = function(self, event)
|
eventHandler = function(self, event)
|
||||||
if event.type == 'form_complete' then
|
if event.type == 'form_complete' then
|
||||||
local args = Util.shallowCopy(event.values)
|
local opts = Util.shallowCopy(event.values)
|
||||||
args.path = shell.resolveProgram(args.path)
|
local words = Util.split(opts.run, '(.-) ')
|
||||||
if not args.path then
|
opts.path = shell.resolveProgram(table.remove(words, 1))
|
||||||
|
if not opts.path then
|
||||||
self.notification:error('Invalid program')
|
self.notification:error('Invalid program')
|
||||||
else
|
else
|
||||||
if args.args then
|
opts.args = #words > 0 and words
|
||||||
args.args = Util.split(args.args, '(.-) ')
|
table.insert(config.session, opts)
|
||||||
end
|
|
||||||
table.insert(config.session, args)
|
|
||||||
Config.update('nwm', config)
|
Config.update('nwm', config)
|
||||||
run(args)
|
run(opts)
|
||||||
self.notification:success('Started program')
|
self.notification:success('Started program')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ local config = Config.load('secure', {
|
|||||||
|
|
||||||
local timer = config.enabled and os.startTimer(config.timeout)
|
local timer = config.enabled and os.startTimer(config.timeout)
|
||||||
|
|
||||||
local sandboxEnv = Util.shallowCopy(_ENV)
|
|
||||||
setmetatable(sandboxEnv, { __index = _G })
|
|
||||||
|
|
||||||
local function buildLockScreen()
|
local function buildLockScreen()
|
||||||
_G.requireInjector(_ENV)
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
@@ -81,7 +78,6 @@ local function showLockScreen()
|
|||||||
pinned = true,
|
pinned = true,
|
||||||
focused = true,
|
focused = true,
|
||||||
title = 'Lock',
|
title = 'Lock',
|
||||||
env = sandboxEnv,
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user