1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-16 05:34:49 +00:00
opus/sys/apps/system/launcher.lua

89 lines
2.0 KiB
Lua
Raw Normal View History

local Config = require('opus.config')
local UI = require('opus.ui')
local colors = _G.colors
local fs = _G.fs
local config = Config.load('multishell')
local tab = UI.Tab {
2020-04-27 01:39:58 +00:00
title = 'Launcher',
description = 'Set the application launcher',
[1] = UI.Window {
x = 2, y = 2, ex = -2, ey = 5,
},
2019-06-18 19:19:24 +00:00
launcherLabel = UI.Text {
x = 3, y = 3,
2019-06-18 19:19:24 +00:00
value = 'Launcher',
},
launcher = UI.Chooser {
x = 13, y = 3, width = 12,
2019-06-18 19:19:24 +00:00
choices = {
{ name = 'Overview', value = 'sys/apps/Overview.lua' },
{ name = 'Shell', value = 'sys/apps/ShellLauncher.lua' },
{ name = 'Custom', value = 'custom' },
},
},
custom = UI.TextEntry {
x = 13, ex = -3, y = 4,
2019-06-18 19:19:24 +00:00
shadowText = 'File name',
},
button = UI.Button {
x = -8, ex = -2, y = -2,
text = 'Apply',
2019-06-18 19:19:24 +00:00
event = 'update',
},
labelText = UI.TextArea {
x = 2, ex = -2, y = 6, ey = -4,
backgroundColor = colors.black,
2019-06-18 19:19:24 +00:00
textColor = colors.yellow,
marginLeft = 1, marginRight = 1, marginTop = 1,
2019-06-18 19:19:24 +00:00
value = 'Choose an application launcher',
},
}
function tab:enable()
2019-06-18 19:19:24 +00:00
local launcher = config.launcher and 'custom' or 'sys/apps/Overview.lua'
2019-06-18 19:19:24 +00:00
for _, v in pairs(self.launcher.choices) do
if v.value == config.launcher then
launcher = v.value
break
end
end
UI.Tab.enable(self)
2019-06-18 19:19:24 +00:00
self.launcher.value = launcher
self.custom.enabled = launcher == 'custom'
end
function tab:eventHandler(event)
if event.type == 'choice_change' then
2019-06-18 19:19:24 +00:00
self.custom.enabled = event.value == 'custom'
if self.custom.enabled then
self.custom.value = config.launcher
end
self:draw()
2019-06-18 19:19:24 +00:00
elseif event.type == 'update' then
local launcher
2019-06-18 19:19:24 +00:00
if self.launcher.value ~= 'custom' then
launcher = self.launcher.value
elseif fs.exists(self.custom.value) and not fs.isDir(self.custom.value) then
launcher = self.custom.value
end
2019-06-18 19:19:24 +00:00
if launcher then
config.launcher = launcher
Config.update('multishell', config)
self:emit({ type = 'success_message', message = 'Updated' })
else
self:emit({ type = 'error_message', message = 'Invalid file' })
end
end
end
return tab