2019-02-26 23:03:09 +00:00
|
|
|
local Ansi = require('ansi')
|
2018-12-23 03:11:16 +00:00
|
|
|
local Config = require('config')
|
|
|
|
local UI = require('ui')
|
|
|
|
|
|
|
|
local device = _G.device
|
|
|
|
|
2019-01-30 20:11:41 +00:00
|
|
|
local tab = UI.Tab {
|
2018-12-23 03:11:16 +00:00
|
|
|
tabTitle = 'Network',
|
|
|
|
description = 'Networking options',
|
2019-02-26 23:03:09 +00:00
|
|
|
info = UI.TextArea {
|
|
|
|
x = 3, y = 4,
|
|
|
|
value = string.format(
|
|
|
|
[[%sSet the primary modem used for wireless communications.%s
|
|
|
|
|
|
|
|
Reboot to take effect.]], Ansi.yellow, Ansi.reset)
|
|
|
|
},
|
|
|
|
label = UI.Text {
|
|
|
|
x = 3, y = 2,
|
|
|
|
value = 'Modem',
|
|
|
|
},
|
|
|
|
modem = UI.Chooser {
|
|
|
|
x = 10, ex = -3, y = 2,
|
|
|
|
nochoice = 'auto',
|
2018-12-23 03:11:16 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
function tab:enable()
|
|
|
|
local width = 7
|
|
|
|
local choices = {
|
|
|
|
{ name = 'auto', value = 'auto' },
|
|
|
|
{ name = 'disable', value = 'none' },
|
|
|
|
}
|
|
|
|
|
|
|
|
for k,v in pairs(device) do
|
|
|
|
if v.isWireless and v.isWireless() and k ~= 'wireless_modem' then
|
|
|
|
table.insert(choices, { name = k, value = v.name })
|
|
|
|
width = math.max(width, #k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-26 23:03:09 +00:00
|
|
|
self.modem.choices = choices
|
|
|
|
--self.modem.width = width + 4
|
2018-12-23 03:11:16 +00:00
|
|
|
|
|
|
|
local config = Config.load('os')
|
2019-02-26 23:03:09 +00:00
|
|
|
self.modem.value = config.wirelessModem or 'auto'
|
2018-12-23 03:11:16 +00:00
|
|
|
|
2019-01-30 20:11:41 +00:00
|
|
|
UI.Tab.enable(self)
|
2018-12-23 03:11:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function tab:eventHandler(event)
|
2019-02-26 23:03:09 +00:00
|
|
|
if event.type == 'choice_change' then
|
2018-12-23 03:11:16 +00:00
|
|
|
local config = Config.load('os')
|
2019-02-26 23:03:09 +00:00
|
|
|
config.wirelessModem = self.modem.value
|
2018-12-23 03:11:16 +00:00
|
|
|
Config.update('os', config)
|
|
|
|
self:emit({ type = 'success_message', message = 'reboot to take effect' })
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return tab
|