2019-11-09 02:54:41 +00:00
|
|
|
local Alt = require('opus.alternate')
|
2019-06-28 17:50:02 +00:00
|
|
|
local class = require('opus.class')
|
|
|
|
local Config = require('opus.config')
|
|
|
|
local Event = require('opus.event')
|
|
|
|
local NFT = require('opus.nft')
|
|
|
|
local Packages = require('opus.packages')
|
|
|
|
local SHA = require('opus.crypto.sha2')
|
|
|
|
local Tween = require('opus.ui.tween')
|
|
|
|
local UI = require('opus.ui')
|
|
|
|
local Util = require('opus.util')
|
2017-05-21 05:42:41 +00:00
|
|
|
|
2018-01-21 10:44:13 +00:00
|
|
|
local colors = _G.colors
|
2019-03-23 16:20:48 +00:00
|
|
|
local device = _G.device
|
2017-10-08 21:45:01 +00:00
|
|
|
local fs = _G.fs
|
2019-01-28 22:54:00 +00:00
|
|
|
local os = _G.os
|
2017-10-08 21:45:01 +00:00
|
|
|
local pocket = _G.pocket
|
2018-01-21 10:44:13 +00:00
|
|
|
local shell = _ENV.shell
|
2017-10-08 21:45:01 +00:00
|
|
|
local term = _G.term
|
|
|
|
local turtle = _G.turtle
|
2017-09-15 05:08:04 +00:00
|
|
|
|
2018-01-21 10:44:13 +00:00
|
|
|
if not _ENV.multishell then
|
2018-01-24 22:39:38 +00:00
|
|
|
error('multishell is required')
|
2018-01-21 10:44:13 +00:00
|
|
|
end
|
|
|
|
|
2017-10-08 21:45:01 +00:00
|
|
|
local REGISTRY_DIR = 'usr/.registry'
|
2019-04-14 14:04:22 +00:00
|
|
|
local DEFAULT_ICON = NFT.parse("\0308\0317\153\153\153\153\153\
|
|
|
|
\0307\0318\153\153\153\153\153\
|
|
|
|
\0308\0317\153\153\153\153\153")
|
2020-03-31 15:57:23 +00:00
|
|
|
local TRANS_ICON = NFT.parse("\0302\0312\32\32\32\32\32\
|
|
|
|
\0302\0312\32\32\32\32\32\
|
|
|
|
\0302\0312\32\32\32\32\32")
|
2016-12-11 19:24:52 +00:00
|
|
|
|
2019-12-07 19:04:58 +00:00
|
|
|
-- overview
|
|
|
|
local uid = _ENV.multishell.getCurrent()
|
|
|
|
device.keyboard.addHotkey('control-o', function()
|
|
|
|
_ENV.multishell.setFocus(uid)
|
|
|
|
end)
|
|
|
|
|
2016-12-11 19:24:52 +00:00
|
|
|
UI:configure('Overview', ...)
|
|
|
|
|
|
|
|
local config = {
|
2018-01-24 22:39:38 +00:00
|
|
|
Recent = { },
|
|
|
|
currentCategory = 'Apps',
|
2016-12-11 19:24:52 +00:00
|
|
|
}
|
|
|
|
Config.load('Overview', config)
|
2017-05-19 23:00:23 +00:00
|
|
|
|
2018-10-14 19:35:40 +00:00
|
|
|
local extSupport = Util.getVersion() >= 1.76
|
2017-05-21 03:46:38 +00:00
|
|
|
|
2018-12-10 15:33:56 +00:00
|
|
|
local applications = { }
|
|
|
|
local buttons = { }
|
2016-12-11 19:24:52 +00:00
|
|
|
|
|
|
|
local sx, sy = term.current().getSize()
|
|
|
|
local maxRecent = math.ceil(sx * sy / 62)
|
|
|
|
|
2019-01-23 20:28:43 +00:00
|
|
|
local function ellipsis(s, len)
|
2018-01-24 22:39:38 +00:00
|
|
|
if #s > len then
|
|
|
|
s = s:sub(1, len - 2) .. '..'
|
|
|
|
end
|
|
|
|
return s
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function parseIcon(iconText)
|
2018-01-24 22:39:38 +00:00
|
|
|
local icon
|
|
|
|
|
|
|
|
local s, m = pcall(function()
|
|
|
|
icon = NFT.parse(iconText)
|
|
|
|
if icon then
|
|
|
|
if icon.height > 3 or icon.width > 8 then
|
2018-10-14 19:35:40 +00:00
|
|
|
error('Must be an NFT image - 3 rows, 8 cols max')
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
2020-03-31 15:57:23 +00:00
|
|
|
NFT.transparency(icon)
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
|
|
|
return icon
|
|
|
|
end)
|
|
|
|
|
|
|
|
if s then
|
|
|
|
return icon
|
|
|
|
end
|
|
|
|
|
|
|
|
return s, m
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2017-09-27 19:42:40 +00:00
|
|
|
UI.VerticalTabBar = class(UI.TabBar)
|
2017-10-11 15:37:52 +00:00
|
|
|
function UI.VerticalTabBar:setParent()
|
2018-01-24 22:39:38 +00:00
|
|
|
self.x = 1
|
|
|
|
self.width = 8
|
|
|
|
self.height = nil
|
2019-01-28 22:54:00 +00:00
|
|
|
self.ey = -2
|
2018-01-24 22:39:38 +00:00
|
|
|
UI.TabBar.setParent(self)
|
|
|
|
for k,c in pairs(self.children) do
|
|
|
|
c.x = 1
|
|
|
|
c.y = k + 1
|
|
|
|
c.ox, c.oy = c.x, c.y
|
|
|
|
c.ow = 8
|
|
|
|
c.width = 8
|
2020-03-31 15:57:23 +00:00
|
|
|
c:reposition(c.x, c.y, c.width, c.height)
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
2017-09-27 19:42:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local cx = 9
|
|
|
|
local cy = 1
|
|
|
|
|
2016-12-11 19:24:52 +00:00
|
|
|
local page = UI.Page {
|
2018-01-24 22:39:38 +00:00
|
|
|
container = UI.Viewport {
|
|
|
|
x = cx,
|
|
|
|
y = cy,
|
|
|
|
},
|
2019-01-28 22:54:00 +00:00
|
|
|
tray = UI.Window {
|
|
|
|
y = -1, width = 8,
|
|
|
|
backgroundColor = colors.lightGray,
|
|
|
|
newApp = UI.Button {
|
|
|
|
text = '+', event = 'new',
|
|
|
|
},
|
2019-02-09 00:21:20 +00:00
|
|
|
--[[
|
2019-01-28 22:54:00 +00:00
|
|
|
volume = UI.Button {
|
|
|
|
x = 3,
|
|
|
|
text = '\15', event = 'volume',
|
2019-02-09 00:21:20 +00:00
|
|
|
},]]
|
2019-01-28 22:54:00 +00:00
|
|
|
},
|
|
|
|
editor = UI.SlideOut {
|
2019-01-30 20:11:41 +00:00
|
|
|
y = -12, height = 12,
|
2019-01-28 22:54:00 +00:00
|
|
|
titleBar = UI.TitleBar {
|
|
|
|
title = 'Edit Application',
|
|
|
|
event = 'slide_hide',
|
|
|
|
},
|
|
|
|
form = UI.Form {
|
|
|
|
y = 2, ey = -2,
|
|
|
|
[1] = UI.TextEntry {
|
2020-03-31 15:57:23 +00:00
|
|
|
formLabel = 'Title', formKey = 'title', limit = 11, width = 13, help = 'Application title',
|
2019-01-28 22:54:00 +00:00
|
|
|
required = true,
|
|
|
|
},
|
|
|
|
[2] = UI.TextEntry {
|
|
|
|
formLabel = 'Run', formKey = 'run', limit = 100, help = 'Full path to application',
|
|
|
|
required = true,
|
|
|
|
},
|
|
|
|
[3] = UI.TextEntry {
|
2020-03-31 15:57:23 +00:00
|
|
|
formLabel = 'Category', formKey = 'category', limit = 6, width = 8, help = 'Category of application',
|
2019-01-28 22:54:00 +00:00
|
|
|
required = true,
|
|
|
|
},
|
2020-03-31 15:57:23 +00:00
|
|
|
editIcon = UI.Button {
|
|
|
|
x = 11, y = 9,
|
|
|
|
text = 'Edit', event = 'editIcon', help = 'Edit icon file',
|
2019-01-28 22:54:00 +00:00
|
|
|
},
|
|
|
|
loadIcon = UI.Button {
|
2020-03-31 15:57:23 +00:00
|
|
|
x = 18, y = 9,
|
2019-01-28 22:54:00 +00:00
|
|
|
text = 'Load', event = 'loadIcon', help = 'Load icon file',
|
|
|
|
},
|
2020-03-31 15:57:23 +00:00
|
|
|
info = UI.TextArea {
|
|
|
|
x = 11, y = 6, height = 2,
|
|
|
|
value = 'magenta is transparent\n3 high - max width is 8'
|
|
|
|
},
|
2019-01-28 22:54:00 +00:00
|
|
|
image = UI.NftImage {
|
|
|
|
backgroundColor = colors.black,
|
2020-03-31 15:57:23 +00:00
|
|
|
y = 6, x = 2, height = 3, width = 8,
|
2019-01-28 22:54:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
notification = UI.Notification(),
|
|
|
|
statusBar = UI.StatusBar(),
|
|
|
|
},
|
2018-01-24 22:39:38 +00:00
|
|
|
notification = UI.Notification(),
|
|
|
|
accelerators = {
|
|
|
|
r = 'refresh',
|
|
|
|
e = 'edit',
|
|
|
|
f = 'files',
|
|
|
|
s = 'shell',
|
|
|
|
l = 'lua',
|
|
|
|
[ 'control-n' ] = 'new',
|
|
|
|
delete = 'delete',
|
|
|
|
},
|
2016-12-11 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 15:33:56 +00:00
|
|
|
local function loadApplications()
|
|
|
|
local requirements = {
|
|
|
|
turtle = not not turtle,
|
|
|
|
advancedTurtle = turtle and term.isColor(),
|
|
|
|
advanced = term.isColor(),
|
|
|
|
pocket = not not pocket,
|
|
|
|
advancedPocket = pocket and term.isColor(),
|
|
|
|
advancedComputer = not turtle and not pocket and term.isColor(),
|
2019-03-23 16:20:48 +00:00
|
|
|
neuralInterface = not not device.neuralInterface,
|
2018-12-10 15:33:56 +00:00
|
|
|
}
|
|
|
|
|
2019-03-23 16:20:48 +00:00
|
|
|
applications = Util.readTable('sys/etc/apps.db')
|
2018-12-10 15:33:56 +00:00
|
|
|
|
|
|
|
for dir in pairs(Packages:installed()) do
|
2018-12-26 09:01:40 +00:00
|
|
|
local path = fs.combine('packages/' .. dir, 'etc/apps.db')
|
2018-12-10 15:33:56 +00:00
|
|
|
if fs.exists(path) then
|
2018-12-26 09:01:40 +00:00
|
|
|
local apps = Util.readTable(path) or { }
|
|
|
|
Util.merge(applications, apps)
|
2018-12-10 15:33:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if fs.exists(REGISTRY_DIR) then
|
|
|
|
local files = fs.list(REGISTRY_DIR)
|
|
|
|
for _,file in pairs(files) do
|
|
|
|
local app = Util.readTable(fs.combine(REGISTRY_DIR, file))
|
|
|
|
if app and app.key then
|
|
|
|
app.filename = fs.combine(REGISTRY_DIR, file)
|
|
|
|
applications[app.key] = app
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Util.each(applications, function(v, k) v.key = k end)
|
|
|
|
applications = Util.filter(applications, function(a)
|
|
|
|
if a.disabled then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if a.requires then
|
|
|
|
return requirements[a.requires]
|
|
|
|
end
|
|
|
|
|
|
|
|
return true -- Util.startsWith(a.run, 'http') or shell.resolveProgram(a.run)
|
|
|
|
end)
|
|
|
|
|
|
|
|
local categories = { }
|
|
|
|
buttons = { }
|
|
|
|
for _,f in pairs(applications) do
|
|
|
|
if not categories[f.category] then
|
|
|
|
categories[f.category] = true
|
|
|
|
table.insert(buttons, {
|
|
|
|
text = f.category,
|
|
|
|
selected = config.currentCategory == f.category
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.sort(buttons, function(a, b) return a.text < b.text end)
|
|
|
|
table.insert(buttons, 1, { text = 'Recent' })
|
|
|
|
|
|
|
|
Util.removeByValue(page.children, page.tabBar)
|
|
|
|
|
|
|
|
page:add {
|
|
|
|
tabBar = UI.VerticalTabBar {
|
|
|
|
buttons = buttons,
|
2020-03-31 15:57:23 +00:00
|
|
|
selectedBackgroundColor = UI.colors.primary,
|
2018-12-10 15:33:56 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
--page.tabBar:selectTab(config.currentCategory or 'Apps')
|
|
|
|
page.container:setCategory(config.currentCategory or 'Apps')
|
|
|
|
end
|
|
|
|
|
2016-12-11 19:24:52 +00:00
|
|
|
UI.Icon = class(UI.Window)
|
2017-10-11 15:37:52 +00:00
|
|
|
UI.Icon.defaults = {
|
2018-01-24 22:39:38 +00:00
|
|
|
UIElement = 'Icon',
|
|
|
|
width = 14,
|
|
|
|
height = 4,
|
2017-10-11 15:37:52 +00:00
|
|
|
}
|
2016-12-11 19:24:52 +00:00
|
|
|
function UI.Icon:eventHandler(event)
|
2018-01-24 22:39:38 +00:00
|
|
|
if event.type == 'mouse_click' then
|
2019-01-10 07:27:02 +00:00
|
|
|
self:setFocus(self.button)
|
2019-01-18 04:33:19 +00:00
|
|
|
--self:emit({ type = self.button.event, button = self.button })
|
2018-01-24 22:39:38 +00:00
|
|
|
return true
|
|
|
|
elseif event.type == 'mouse_doubleclick' then
|
|
|
|
self:emit({ type = self.button.event, button = self.button })
|
|
|
|
elseif event.type == 'mouse_rightclick' then
|
|
|
|
self:setFocus(self.button)
|
|
|
|
self:emit({ type = 'edit', button = self.button })
|
|
|
|
end
|
|
|
|
return UI.Window.eventHandler(self, event)
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2017-10-08 21:45:01 +00:00
|
|
|
function page.container:setCategory(categoryName, animate)
|
2018-01-24 22:39:38 +00:00
|
|
|
-- reset the viewport window
|
|
|
|
self.children = { }
|
2019-02-06 04:03:57 +00:00
|
|
|
self:reset()
|
2018-01-24 22:39:38 +00:00
|
|
|
|
|
|
|
local function filter(it, f)
|
|
|
|
local ot = { }
|
|
|
|
for _,v in pairs(it) do
|
|
|
|
if f(v) then
|
|
|
|
table.insert(ot, v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return ot
|
|
|
|
end
|
|
|
|
|
|
|
|
local filtered
|
|
|
|
|
|
|
|
if categoryName == 'Recent' then
|
|
|
|
filtered = { }
|
|
|
|
|
|
|
|
for _,v in ipairs(config.Recent) do
|
|
|
|
local app = Util.find(applications, 'key', v)
|
|
|
|
if app then -- and fs.exists(app.run) then
|
|
|
|
table.insert(filtered, app)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
filtered = filter(applications, function(a)
|
|
|
|
return a.category == categoryName -- and fs.exists(a.run)
|
|
|
|
end)
|
|
|
|
table.sort(filtered, function(a, b) return a.title < b.title end)
|
|
|
|
end
|
|
|
|
|
|
|
|
for _,program in ipairs(filtered) do
|
|
|
|
|
|
|
|
local icon
|
2018-10-14 19:35:40 +00:00
|
|
|
if extSupport and program.iconExt then
|
|
|
|
icon = parseIcon(program.iconExt)
|
|
|
|
end
|
|
|
|
if not icon and program.icon then
|
2018-01-24 22:39:38 +00:00
|
|
|
icon = parseIcon(program.icon)
|
|
|
|
end
|
|
|
|
if not icon then
|
2018-12-10 15:33:56 +00:00
|
|
|
icon = DEFAULT_ICON
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
|
|
|
|
2019-01-23 20:28:43 +00:00
|
|
|
local title = ellipsis(program.title, 8)
|
2018-01-24 22:39:38 +00:00
|
|
|
|
|
|
|
local width = math.max(icon.width + 2, #title + 2)
|
|
|
|
table.insert(self.children, UI.Icon({
|
|
|
|
width = width,
|
|
|
|
image = UI.NftImage({
|
|
|
|
x = math.floor((width - icon.width) / 2) + 1,
|
|
|
|
image = icon,
|
|
|
|
}),
|
|
|
|
button = UI.Button({
|
|
|
|
x = math.floor((width - #title - 2) / 2) + 1,
|
|
|
|
y = 4,
|
|
|
|
text = title,
|
2020-03-31 15:57:23 +00:00
|
|
|
backgroundColor = self:getProperty('backgroundColor'),
|
2018-01-24 22:39:38 +00:00
|
|
|
backgroundFocusColor = colors.gray,
|
|
|
|
textColor = colors.white,
|
|
|
|
textFocusColor = colors.white,
|
|
|
|
width = #title + 2,
|
|
|
|
event = 'button',
|
|
|
|
app = program,
|
|
|
|
}),
|
|
|
|
}))
|
|
|
|
end
|
|
|
|
|
|
|
|
local gutter = 2
|
|
|
|
if UI.term.width <= 26 then
|
|
|
|
gutter = 1
|
|
|
|
end
|
|
|
|
local col, row = gutter, 2
|
|
|
|
local count = #self.children
|
|
|
|
|
2020-03-31 15:57:23 +00:00
|
|
|
local r = math.random(1, 7)
|
|
|
|
local frames = 5
|
2018-01-24 22:39:38 +00:00
|
|
|
-- reposition all children
|
|
|
|
for k,child in ipairs(self.children) do
|
|
|
|
if r == 1 then
|
|
|
|
child.x = math.random(1, self.width)
|
2019-02-06 04:03:57 +00:00
|
|
|
child.y = math.random(1, self.height - 3)
|
2018-01-24 22:39:38 +00:00
|
|
|
elseif r == 2 then
|
|
|
|
child.x = self.width
|
2019-02-06 04:03:57 +00:00
|
|
|
child.y = self.height - 3
|
2018-01-24 22:39:38 +00:00
|
|
|
elseif r == 3 then
|
|
|
|
child.x = math.floor(self.width / 2)
|
|
|
|
child.y = math.floor(self.height / 2)
|
|
|
|
elseif r == 4 then
|
|
|
|
child.x = self.width - col
|
|
|
|
child.y = row
|
|
|
|
elseif r == 5 then
|
|
|
|
child.x = col
|
|
|
|
child.y = row
|
|
|
|
if k == #self.children then
|
|
|
|
child.x = self.width
|
2019-02-06 04:03:57 +00:00
|
|
|
child.y = self.height - 3
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
2020-03-31 15:57:23 +00:00
|
|
|
elseif r == 6 then
|
|
|
|
child.x = col
|
|
|
|
child.y = 1
|
|
|
|
elseif r == 7 then
|
|
|
|
child.x = 1
|
|
|
|
child.y = self.height - 3
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
2020-03-31 15:57:23 +00:00
|
|
|
child.tween = Tween.new(frames, child, { x = col, y = row }, 'inQuad')
|
2018-01-24 22:39:38 +00:00
|
|
|
|
|
|
|
if not animate then
|
|
|
|
child.x = col
|
|
|
|
child.y = row
|
|
|
|
end
|
|
|
|
|
2020-03-31 15:57:23 +00:00
|
|
|
self:setViewHeight(row + 3)
|
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
if k < count then
|
|
|
|
col = col + child.width
|
|
|
|
if col + self.children[k + 1].width + gutter - 2 > self.width then
|
|
|
|
col = gutter
|
|
|
|
row = row + 5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self:initChildren()
|
2019-02-06 04:03:57 +00:00
|
|
|
if animate then
|
|
|
|
local function transition()
|
2018-01-24 22:39:38 +00:00
|
|
|
local i = 1
|
2019-02-06 04:03:57 +00:00
|
|
|
return function()
|
2018-01-24 22:39:38 +00:00
|
|
|
for _,child in pairs(self.children) do
|
|
|
|
child.tween:update(1)
|
2020-03-31 15:57:23 +00:00
|
|
|
child:move(math.floor(child.x), math.floor(child.y))
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
2020-03-31 15:57:23 +00:00
|
|
|
--os.sleep(.5)
|
2018-01-24 22:39:38 +00:00
|
|
|
i = i + 1
|
2020-03-31 15:57:23 +00:00
|
|
|
return i <= frames
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
self:addTransition(transition)
|
|
|
|
end
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function page:refresh()
|
2018-01-24 22:39:38 +00:00
|
|
|
local pos = self.container.offy
|
|
|
|
self:focusFirst(self)
|
|
|
|
self.container:setCategory(config.currentCategory)
|
|
|
|
self.container:setScrollPosition(pos)
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function page:resize()
|
2018-01-24 22:39:38 +00:00
|
|
|
UI.Page.resize(self)
|
|
|
|
self:refresh()
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function page:eventHandler(event)
|
2018-01-24 22:39:38 +00:00
|
|
|
if event.type == 'tab_select' then
|
|
|
|
self.container:setCategory(event.button.text, true)
|
|
|
|
self.container:draw()
|
|
|
|
|
|
|
|
config.currentCategory = event.button.text
|
|
|
|
Config.update('Overview', config)
|
|
|
|
|
|
|
|
elseif event.type == 'button' then
|
|
|
|
for k,v in ipairs(config.Recent) do
|
|
|
|
if v == event.button.app.key then
|
|
|
|
table.remove(config.Recent, k)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.insert(config.Recent, 1, event.button.app.key)
|
|
|
|
if #config.Recent > maxRecent then
|
|
|
|
table.remove(config.Recent, maxRecent + 1)
|
|
|
|
end
|
|
|
|
Config.update('Overview', config)
|
|
|
|
shell.switchTab(shell.openTab(event.button.app.run))
|
|
|
|
|
|
|
|
elseif event.type == 'shell' then
|
2019-11-09 02:54:41 +00:00
|
|
|
shell.switchTab(shell.openTab(Alt.get('shell')))
|
2018-01-24 22:39:38 +00:00
|
|
|
|
|
|
|
elseif event.type == 'lua' then
|
2019-11-09 02:54:41 +00:00
|
|
|
shell.switchTab(shell.openTab(Alt.get('lua')))
|
2018-01-24 22:39:38 +00:00
|
|
|
|
|
|
|
elseif event.type == 'files' then
|
2019-11-09 02:54:41 +00:00
|
|
|
shell.switchTab(shell.openTab(Alt.get('files')))
|
2018-01-24 22:39:38 +00:00
|
|
|
|
|
|
|
elseif event.type == 'focus_change' then
|
|
|
|
if event.focused.parent.UIElement == 'Icon' then
|
|
|
|
event.focused.parent:scrollIntoView()
|
|
|
|
end
|
|
|
|
|
|
|
|
elseif event.type == 'refresh' then -- remove this after fixing notification
|
|
|
|
loadApplications()
|
|
|
|
self:refresh()
|
|
|
|
self:draw()
|
|
|
|
self.notification:success('Refreshed')
|
|
|
|
|
|
|
|
elseif event.type == 'delete' then
|
|
|
|
local focused = page:getFocused()
|
|
|
|
if focused.app then
|
2019-01-18 04:33:19 +00:00
|
|
|
if focused.app.filename then
|
|
|
|
fs.delete(focused.app.filename)
|
|
|
|
else
|
|
|
|
focused.app.disabled = true
|
|
|
|
local filename = focused.app.filename or fs.combine(REGISTRY_DIR, focused.app.key)
|
|
|
|
Util.writeTable(filename, focused.app)
|
|
|
|
end
|
2018-01-24 22:39:38 +00:00
|
|
|
loadApplications()
|
|
|
|
page:refresh()
|
|
|
|
page:draw()
|
|
|
|
self.notification:success('Removed')
|
|
|
|
end
|
|
|
|
|
|
|
|
elseif event.type == 'new' then
|
|
|
|
local category = 'Apps'
|
|
|
|
if config.currentCategory ~= 'Recent' then
|
|
|
|
category = config.currentCategory or 'Apps'
|
|
|
|
end
|
2019-01-28 22:54:00 +00:00
|
|
|
self.editor:show({ category = category })
|
2018-01-24 22:39:38 +00:00
|
|
|
|
|
|
|
elseif event.type == 'edit' then
|
|
|
|
local focused = page:getFocused()
|
|
|
|
if focused.app then
|
2019-01-28 22:54:00 +00:00
|
|
|
self.editor:show(focused.app)
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
UI.Page.eventHandler(self, event)
|
|
|
|
end
|
|
|
|
return true
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2019-01-28 22:54:00 +00:00
|
|
|
function page.editor:show(app)
|
2018-01-24 22:39:38 +00:00
|
|
|
if app then
|
|
|
|
self.form:setValues(app)
|
|
|
|
|
|
|
|
local icon
|
2018-10-14 19:35:40 +00:00
|
|
|
if extSupport and app.iconExt then
|
|
|
|
icon = parseIcon(app.iconExt)
|
|
|
|
end
|
|
|
|
if not icon and app.icon then
|
2018-01-24 22:39:38 +00:00
|
|
|
icon = parseIcon(app.icon)
|
|
|
|
end
|
|
|
|
self.form.image:setImage(icon)
|
|
|
|
end
|
2019-01-28 22:54:00 +00:00
|
|
|
UI.SlideOut.show(self)
|
2018-01-24 22:39:38 +00:00
|
|
|
self:focusFirst()
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2019-01-28 22:54:00 +00:00
|
|
|
function page.editor.form.image:draw()
|
2018-01-24 22:39:38 +00:00
|
|
|
self:clear()
|
|
|
|
UI.NftImage.draw(self)
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2019-01-28 22:54:00 +00:00
|
|
|
function page.editor:updateApplications(app)
|
2018-01-24 22:39:38 +00:00
|
|
|
if not app.key then
|
2019-06-28 10:33:47 +00:00
|
|
|
app.key = SHA.compute(app.title)
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
|
|
|
local filename = app.filename or fs.combine(REGISTRY_DIR, app.key)
|
|
|
|
Util.writeTable(filename, app)
|
|
|
|
loadApplications()
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2020-03-31 15:57:23 +00:00
|
|
|
function page.editor:loadImage(filename)
|
|
|
|
local s, m = pcall(function()
|
|
|
|
local iconLines = Util.readFile(filename)
|
|
|
|
if not iconLines then
|
|
|
|
error('Must be an NFT image - 3 rows, 8 cols max')
|
|
|
|
end
|
|
|
|
local icon, m = parseIcon(iconLines)
|
|
|
|
if not icon then
|
|
|
|
error(m)
|
|
|
|
end
|
|
|
|
if extSupport then
|
|
|
|
self.form.values.iconExt = iconLines
|
|
|
|
else
|
|
|
|
self.form.values.icon = iconLines
|
|
|
|
end
|
|
|
|
self.form.image:setImage(icon)
|
|
|
|
self.form.image:draw()
|
|
|
|
end)
|
|
|
|
if not s and m then
|
|
|
|
local msg = m:gsub('.*: (.*)', '%1')
|
|
|
|
self.notification:error(msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-28 22:54:00 +00:00
|
|
|
function page.editor:eventHandler(event)
|
2018-01-24 22:39:38 +00:00
|
|
|
if event.type == 'form_cancel' or event.type == 'cancel' then
|
2019-01-28 22:54:00 +00:00
|
|
|
self:hide()
|
2018-01-24 22:39:38 +00:00
|
|
|
|
|
|
|
elseif event.type == 'focus_change' then
|
|
|
|
self.statusBar:setStatus(event.focused.help or '')
|
|
|
|
self.statusBar:draw()
|
|
|
|
|
2020-03-31 15:57:23 +00:00
|
|
|
elseif event.type == 'editIcon' then
|
|
|
|
local filename = '/tmp/editing.nft'
|
|
|
|
NFT.save(self.form.image.image or TRANS_ICON, filename)
|
|
|
|
local success = shell.run('pain.lua ' .. filename)
|
|
|
|
self.parent:dirty(true)
|
|
|
|
if success then
|
|
|
|
self:loadImage(filename)
|
|
|
|
end
|
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
elseif event.type == 'loadIcon' then
|
2020-03-31 15:57:23 +00:00
|
|
|
local success, filename = shell.run('fileui.lua')
|
|
|
|
self.parent:dirty(true)
|
|
|
|
if success and filename then
|
|
|
|
self:loadImage(filename)
|
2019-01-28 22:54:00 +00:00
|
|
|
end
|
2018-01-24 22:39:38 +00:00
|
|
|
|
|
|
|
elseif event.type == 'form_invalid' then
|
2019-01-28 22:54:00 +00:00
|
|
|
self.notification:error(event.message)
|
2018-01-24 22:39:38 +00:00
|
|
|
|
|
|
|
elseif event.type == 'form_complete' then
|
|
|
|
local values = self.form.values
|
2019-01-30 21:27:09 +00:00
|
|
|
self:hide()
|
2018-01-24 22:39:38 +00:00
|
|
|
self:updateApplications(values)
|
2018-12-10 15:33:56 +00:00
|
|
|
--page:refresh()
|
|
|
|
--page:draw()
|
|
|
|
config.currentCategory = values.category
|
|
|
|
Config.update('Overview', config)
|
|
|
|
os.queueEvent('overview_refresh')
|
2018-01-24 22:39:38 +00:00
|
|
|
else
|
2019-01-28 22:54:00 +00:00
|
|
|
return UI.SlideOut.eventHandler(self, event)
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
|
|
|
return true
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
UI:setPages({
|
2018-01-24 22:39:38 +00:00
|
|
|
main = page,
|
2016-12-11 19:24:52 +00:00
|
|
|
})
|
|
|
|
|
2018-12-10 15:33:56 +00:00
|
|
|
local function reload()
|
2018-01-24 22:39:38 +00:00
|
|
|
loadApplications()
|
|
|
|
page:refresh()
|
|
|
|
page:draw()
|
|
|
|
page:sync()
|
2018-12-10 15:33:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Event.on('overview_shortcut', function(_, app)
|
|
|
|
if not app.key then
|
2019-06-28 10:33:47 +00:00
|
|
|
app.key = SHA.compute(app.title)
|
2018-12-10 15:33:56 +00:00
|
|
|
end
|
|
|
|
local filename = app.filename or fs.combine(REGISTRY_DIR, app.key)
|
|
|
|
if not fs.exists(filename) then
|
|
|
|
Util.writeTable(filename, app)
|
|
|
|
reload()
|
|
|
|
end
|
2016-12-11 19:24:52 +00:00
|
|
|
end)
|
|
|
|
|
2018-12-10 15:33:56 +00:00
|
|
|
Event.on('overview_refresh', function()
|
|
|
|
reload()
|
|
|
|
end)
|
|
|
|
|
|
|
|
loadApplications()
|
|
|
|
|
2016-12-11 19:24:52 +00:00
|
|
|
UI:setPage(page)
|
2020-03-31 15:57:23 +00:00
|
|
|
UI:start()
|