2016-06-26 00:53:08 +00:00
|
|
|
|
--[[--
|
|
|
|
|
Network setting widget.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
local network_list = {
|
|
|
|
|
{
|
|
|
|
|
ssid = "foo",
|
|
|
|
|
signal_level = -58,
|
|
|
|
|
flags = "[WPA2-PSK-CCMP][ESS]",
|
|
|
|
|
signal_quality = 84,
|
|
|
|
|
password = "123abc",
|
|
|
|
|
connected = true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ssid = "bar",
|
|
|
|
|
signal_level = -258,
|
|
|
|
|
signal_quality = 44,
|
|
|
|
|
flags = "[WEP][ESS]",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
UIManager:show(require("ui/widget/networksetting"):new{
|
|
|
|
|
network_list = network_list,
|
|
|
|
|
connect_callback = function()
|
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
|
|
|
|
-- connect_callback will be called when a *connect* (NOT disconnect)
|
|
|
|
|
-- attempt has been successful.
|
|
|
|
|
-- You can update UI widgets in the callback.
|
|
|
|
|
end,
|
|
|
|
|
disconnect_callback = function()
|
|
|
|
|
-- This one will fire unconditionally after a disconnect attempt.
|
2016-06-26 00:53:08 +00:00
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
]]
|
|
|
|
|
|
2020-01-04 00:18:51 +00:00
|
|
|
|
local BD = require("ui/bidi")
|
2019-03-27 21:50:44 +00:00
|
|
|
|
local bit = require("bit")
|
2017-09-11 08:32:39 +00:00
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2016-06-26 00:53:08 +00:00
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2017-09-11 08:32:39 +00:00
|
|
|
|
local Device = require("device")
|
|
|
|
|
local Font = require("ui/font")
|
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
2016-06-26 00:53:08 +00:00
|
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
|
|
|
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
2020-12-19 11:18:30 +00:00
|
|
|
|
local IconWidget = require("ui/widget/iconwidget")
|
2016-06-26 00:53:08 +00:00
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
2017-09-11 08:32:39 +00:00
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2016-06-26 00:53:08 +00:00
|
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
2017-09-11 08:32:39 +00:00
|
|
|
|
local LeftContainer = require("ui/widget/container/leftcontainer")
|
2016-06-26 00:53:08 +00:00
|
|
|
|
local ListView = require("ui/widget/listview")
|
2017-09-11 08:32:39 +00:00
|
|
|
|
local RightContainer = require("ui/widget/container/rightcontainer")
|
|
|
|
|
local NetworkMgr = require("ui/network/manager")
|
|
|
|
|
local OverlapGroup = require("ui/widget/overlapgroup")
|
2017-09-13 14:56:20 +00:00
|
|
|
|
local Size = require("ui/size")
|
2016-06-26 00:53:08 +00:00
|
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
|
|
|
|
local UIManager = require("ui/uimanager")
|
2023-11-09 20:08:26 +00:00
|
|
|
|
local util = require("util")
|
2017-09-11 08:32:39 +00:00
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
|
local Widget = require("ui/widget/widget")
|
2016-06-26 00:53:08 +00:00
|
|
|
|
local _ = require("gettext")
|
2017-09-11 08:32:39 +00:00
|
|
|
|
local T = require("ffi/util").template
|
|
|
|
|
local Screen = Device.screen
|
2016-11-05 23:40:39 +00:00
|
|
|
|
|
2019-03-27 21:50:44 +00:00
|
|
|
|
local band = bit.band
|
|
|
|
|
|
2016-11-05 23:40:39 +00:00
|
|
|
|
local function obtainIP()
|
2019-08-23 17:53:53 +00:00
|
|
|
|
--- @todo check for DHCP result
|
2016-11-05 23:40:39 +00:00
|
|
|
|
local info = InfoMessage:new{text = _("Obtaining IP address…")}
|
|
|
|
|
UIManager:show(info)
|
|
|
|
|
UIManager:forceRePaint()
|
|
|
|
|
NetworkMgr:obtainIP()
|
|
|
|
|
UIManager:close(info)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
|
local MinimalPaginator = Widget:extend{
|
2016-06-26 00:53:08 +00:00
|
|
|
|
width = nil,
|
|
|
|
|
height = nil,
|
|
|
|
|
progress = nil,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function MinimalPaginator:getSize()
|
|
|
|
|
return Geom:new{w = self.width, h = self.height}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function MinimalPaginator:paintTo(bb, x, y)
|
|
|
|
|
self.dimen = self:getSize()
|
|
|
|
|
self.dimen.x, self.dimen.y = x, y
|
|
|
|
|
-- paint background
|
|
|
|
|
bb:paintRoundedRect(x, y,
|
|
|
|
|
self.dimen.w, self.dimen.h,
|
2019-03-14 19:58:45 +00:00
|
|
|
|
Blitbuffer.COLOR_LIGHT_GRAY)
|
2016-06-26 00:53:08 +00:00
|
|
|
|
-- paint percentage infill
|
|
|
|
|
bb:paintRect(x, y,
|
|
|
|
|
math.ceil(self.dimen.w*self.progress), self.dimen.h,
|
2019-03-14 19:58:45 +00:00
|
|
|
|
Blitbuffer.COLOR_DARK_GRAY)
|
2016-06-26 00:53:08 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function MinimalPaginator:setProgress(progress) self.progress = progress end
|
|
|
|
|
|
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
|
local NetworkItem = InputContainer:extend{
|
2016-06-26 00:53:08 +00:00
|
|
|
|
dimen = nil,
|
|
|
|
|
height = Screen:scaleBySize(44),
|
2020-12-19 11:18:30 +00:00
|
|
|
|
icon_size = Screen:scaleBySize(32),
|
2016-06-26 00:53:08 +00:00
|
|
|
|
width = nil,
|
|
|
|
|
info = nil,
|
2023-11-09 20:08:26 +00:00
|
|
|
|
display_ssid = nil,
|
2016-06-26 00:53:08 +00:00
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function NetworkItem:init()
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
|
self.dimen = Geom:new{x = 0, y = 0, w = self.width, h = self.height}
|
2016-06-26 00:53:08 +00:00
|
|
|
|
if not self.info.ssid then
|
|
|
|
|
self.info.ssid = "[hidden]"
|
|
|
|
|
end
|
2023-11-09 20:08:26 +00:00
|
|
|
|
self.display_ssid = util.fixUtf8(self.info.ssid, "<EFBFBD>")
|
2016-06-26 00:53:08 +00:00
|
|
|
|
|
2020-12-19 11:18:30 +00:00
|
|
|
|
local wifi_icon
|
2016-06-26 00:53:08 +00:00
|
|
|
|
if string.find(self.info.flags, "WPA") then
|
2020-12-19 11:18:30 +00:00
|
|
|
|
wifi_icon = "wifi.secure.%d"
|
2016-06-26 00:53:08 +00:00
|
|
|
|
else
|
2020-12-19 11:18:30 +00:00
|
|
|
|
wifi_icon = "wifi.open.%d"
|
2016-06-26 00:53:08 +00:00
|
|
|
|
end
|
2020-12-21 17:48:33 +00:00
|
|
|
|
-- Based on NetworkManager's nmc_wifi_strength_bars
|
|
|
|
|
-- c.f., https://github.com/NetworkManager/NetworkManager/blob/2fa8ef9fb9c7fe0cc2d9523eed6c5a3749b05175/clients/common/nm-client-utils.c#L585-L612
|
|
|
|
|
if self.info.signal_quality > 80 then
|
|
|
|
|
wifi_icon = string.format(wifi_icon, 100)
|
|
|
|
|
elseif self.info.signal_quality > 55 then
|
|
|
|
|
wifi_icon = string.format(wifi_icon, 75)
|
|
|
|
|
elseif self.info.signal_quality > 30 then
|
|
|
|
|
wifi_icon = string.format(wifi_icon, 50)
|
|
|
|
|
elseif self.info.signal_quality > 5 then
|
|
|
|
|
wifi_icon = string.format(wifi_icon, 25)
|
2016-06-26 00:53:08 +00:00
|
|
|
|
else
|
2020-12-21 17:48:33 +00:00
|
|
|
|
wifi_icon = string.format(wifi_icon, 0)
|
2016-06-26 00:53:08 +00:00
|
|
|
|
end
|
2020-12-21 17:48:33 +00:00
|
|
|
|
|
2017-09-13 14:56:20 +00:00
|
|
|
|
local horizontal_space = HorizontalSpan:new{width = Size.span.horizontal_default}
|
2016-06-26 00:53:08 +00:00
|
|
|
|
self.content_container = OverlapGroup:new{
|
|
|
|
|
dimen = self.dimen:copy(),
|
|
|
|
|
LeftContainer:new{
|
|
|
|
|
dimen = self.dimen:copy(),
|
|
|
|
|
HorizontalGroup:new{
|
|
|
|
|
horizontal_space,
|
2020-12-19 11:18:30 +00:00
|
|
|
|
IconWidget:new{
|
|
|
|
|
icon = wifi_icon,
|
|
|
|
|
width = self.icon_size,
|
|
|
|
|
height = self.icon_size,
|
2016-06-26 00:53:08 +00:00
|
|
|
|
},
|
|
|
|
|
horizontal_space,
|
|
|
|
|
TextWidget:new{
|
2023-11-09 20:08:26 +00:00
|
|
|
|
text = self.display_ssid,
|
2016-06-26 00:53:08 +00:00
|
|
|
|
face = Font:getFace("cfont"),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.btn_disconnect = nil
|
|
|
|
|
self.btn_edit_nw = nil
|
|
|
|
|
if self.info.connected then
|
|
|
|
|
self.btn_disconnect = FrameContainer:new{
|
|
|
|
|
bordersize = 0,
|
|
|
|
|
padding = 0,
|
|
|
|
|
TextWidget:new{
|
|
|
|
|
text = _("disconnect"),
|
|
|
|
|
face = Font:getFace("cfont"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
table.insert(self.content_container, RightContainer:new{
|
|
|
|
|
dimen = self.dimen:copy(),
|
|
|
|
|
HorizontalGroup:new{
|
|
|
|
|
self.btn_disconnect,
|
|
|
|
|
horizontal_space,
|
|
|
|
|
}
|
|
|
|
|
})
|
2016-11-05 23:40:39 +00:00
|
|
|
|
self.setting_ui:setConnectedItem(self)
|
2016-06-26 00:53:08 +00:00
|
|
|
|
elseif self.info.password then
|
|
|
|
|
self.btn_edit_nw = FrameContainer:new{
|
|
|
|
|
bordersize = 0,
|
|
|
|
|
padding = 0,
|
|
|
|
|
TextWidget:new{
|
|
|
|
|
text = _("edit"),
|
|
|
|
|
face = Font:getFace("cfont"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
table.insert(self.content_container, RightContainer:new{
|
|
|
|
|
dimen = self.dimen:copy(),
|
|
|
|
|
HorizontalGroup:new{
|
|
|
|
|
self.btn_edit_nw,
|
|
|
|
|
horizontal_space,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
|
padding = 0,
|
|
|
|
|
margin = 0,
|
|
|
|
|
background = self.background,
|
|
|
|
|
bordersize = 0,
|
|
|
|
|
width = self.width,
|
|
|
|
|
self.content_container,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if Device:isTouchDevice() then
|
2022-10-27 00:01:51 +00:00
|
|
|
|
self.ges_events.TapSelect = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "tap",
|
|
|
|
|
range = self.dimen,
|
2016-06-26 00:53:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NetworkItem:refresh()
|
|
|
|
|
self:init()
|
|
|
|
|
UIManager:setDirty(self.setting_ui, function() return "ui", self.dimen end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NetworkItem:connect()
|
2016-11-05 23:40:39 +00:00
|
|
|
|
local connected_item = self.setting_ui:getConnectedItem()
|
2016-06-26 00:53:08 +00:00
|
|
|
|
if connected_item then connected_item:disconnect() end
|
|
|
|
|
|
|
|
|
|
local success, err_msg = NetworkMgr:authenticateNetwork(self.info)
|
|
|
|
|
|
|
|
|
|
local text
|
|
|
|
|
if success then
|
2016-11-05 23:40:39 +00:00
|
|
|
|
obtainIP()
|
2016-06-26 00:53:08 +00:00
|
|
|
|
self.info.connected = true
|
|
|
|
|
self.setting_ui:setConnectedItem(self)
|
|
|
|
|
text = _("Connected.")
|
|
|
|
|
else
|
|
|
|
|
text = err_msg
|
|
|
|
|
end
|
|
|
|
|
|
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
|
|
|
|
-- Do what it says on the tin, and only trigger the connect_callback on a *successful* connect.
|
2021-03-01 00:35:12 +00:00
|
|
|
|
-- NOTE: This callback comes from NetworkManager, where it's named complete_callback.
|
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
|
|
|
|
if success and self.setting_ui.connect_callback then
|
2016-06-26 00:53:08 +00:00
|
|
|
|
self.setting_ui.connect_callback()
|
|
|
|
|
end
|
2016-11-05 23:40:39 +00:00
|
|
|
|
|
|
|
|
|
self:refresh()
|
2018-11-30 17:14:40 +00:00
|
|
|
|
UIManager:show(InfoMessage:new{text = text, timeout = 3})
|
2016-06-26 00:53:08 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NetworkItem:disconnect()
|
|
|
|
|
local info = InfoMessage:new{text = _("Disconnecting…")}
|
|
|
|
|
UIManager:show(info)
|
|
|
|
|
UIManager:forceRePaint()
|
|
|
|
|
|
|
|
|
|
NetworkMgr:disconnectNetwork(self.info)
|
|
|
|
|
NetworkMgr:releaseIP()
|
|
|
|
|
|
|
|
|
|
UIManager:close(info)
|
|
|
|
|
self.info.connected = nil
|
|
|
|
|
self:refresh()
|
2016-11-05 23:40:39 +00:00
|
|
|
|
self.setting_ui:setConnectedItem(nil)
|
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
|
|
|
|
if self.setting_ui.disconnect_callback then
|
|
|
|
|
self.setting_ui.disconnect_callback()
|
2016-06-26 00:53:08 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NetworkItem:saveAndConnectToNetwork(password_input)
|
|
|
|
|
local new_passwd = password_input:getInputText()
|
2021-09-08 20:48:58 +00:00
|
|
|
|
-- Dont set a empty password if WPA encryption, go through if it’s an open AP
|
2021-09-09 22:23:41 +00:00
|
|
|
|
if (new_passwd == nil or #new_passwd == 0) and string.find(self.info.flags, "WPA") then
|
2016-06-26 00:53:08 +00:00
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
|
text = _("Password cannot be empty."),
|
|
|
|
|
})
|
|
|
|
|
else
|
|
|
|
|
if new_passwd ~= self.info.password then
|
|
|
|
|
self.info.password = new_passwd
|
2017-03-26 22:16:48 +00:00
|
|
|
|
self.info.psk = nil
|
2016-06-26 00:53:08 +00:00
|
|
|
|
NetworkMgr:saveNetwork(self.info)
|
|
|
|
|
end
|
|
|
|
|
self:connect()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
UIManager:close(password_input)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NetworkItem:onEditNetwork()
|
|
|
|
|
local password_input
|
|
|
|
|
password_input = InputDialog:new{
|
2023-11-09 20:08:26 +00:00
|
|
|
|
title = self.display_ssid,
|
2016-06-26 00:53:08 +00:00
|
|
|
|
input = self.info.password,
|
2021-09-08 22:34:26 +00:00
|
|
|
|
input_hint = _("password (leave empty for open networks)"),
|
2016-06-26 00:53:08 +00:00
|
|
|
|
input_type = "text",
|
|
|
|
|
text_type = "password",
|
|
|
|
|
buttons = {
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
text = _("Cancel"),
|
2022-03-04 20:20:00 +00:00
|
|
|
|
id = "close",
|
2016-06-26 00:53:08 +00:00
|
|
|
|
callback = function()
|
|
|
|
|
UIManager:close(password_input)
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text = _("Forget"),
|
|
|
|
|
callback = function()
|
|
|
|
|
NetworkMgr:deleteNetwork(self.info)
|
|
|
|
|
self.info.password = nil
|
|
|
|
|
-- remove edit button
|
|
|
|
|
table.remove(self.content_container, 2)
|
|
|
|
|
UIManager:close(password_input)
|
|
|
|
|
self:refresh()
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text = _("Connect"),
|
|
|
|
|
is_enter_default = true,
|
|
|
|
|
callback = function()
|
|
|
|
|
self:saveAndConnectToNetwork(password_input)
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
UIManager:show(password_input)
|
2018-03-30 10:46:36 +00:00
|
|
|
|
password_input:onShowKeyboard()
|
2016-06-26 00:53:08 +00:00
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NetworkItem:onAddNetwork()
|
|
|
|
|
local password_input
|
|
|
|
|
password_input = InputDialog:new{
|
2023-11-09 20:08:26 +00:00
|
|
|
|
title = self.display_ssid,
|
2016-06-26 00:53:08 +00:00
|
|
|
|
input = "",
|
2021-09-08 22:34:26 +00:00
|
|
|
|
input_hint = _("password (leave empty for open networks)"),
|
2016-06-26 00:53:08 +00:00
|
|
|
|
input_type = "text",
|
|
|
|
|
text_type = "password",
|
|
|
|
|
buttons = {
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
text = _("Cancel"),
|
2022-03-04 20:20:00 +00:00
|
|
|
|
id = "close",
|
2016-06-26 00:53:08 +00:00
|
|
|
|
callback = function()
|
|
|
|
|
UIManager:close(password_input)
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text = _("Connect"),
|
|
|
|
|
is_enter_default = true,
|
|
|
|
|
callback = function()
|
|
|
|
|
self:saveAndConnectToNetwork(password_input)
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
UIManager:show(password_input)
|
2018-03-30 10:46:36 +00:00
|
|
|
|
password_input:onShowKeyboard()
|
2016-06-26 00:53:08 +00:00
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NetworkItem:onTapSelect(arg, ges_ev)
|
2021-09-08 20:48:58 +00:00
|
|
|
|
-- Open AP dont have specific flag so we can’t include them alongside WPA
|
|
|
|
|
-- so we exclude WEP instead (more encryption to exclude? not really future proof)
|
|
|
|
|
if string.find(self.info.flags, "WEP") then
|
2016-06-26 00:53:08 +00:00
|
|
|
|
UIManager:show(InfoMessage:new{
|
2021-09-08 20:48:58 +00:00
|
|
|
|
text = _("Networks with WEP encryption are not supported.")
|
2016-06-26 00:53:08 +00:00
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
if self.btn_disconnect then
|
|
|
|
|
-- noop if touch is not on disconnect button
|
|
|
|
|
if ges_ev.pos:intersectWith(self.btn_disconnect.dimen) then
|
|
|
|
|
self:disconnect()
|
|
|
|
|
end
|
|
|
|
|
elseif self.info.password then
|
|
|
|
|
if self.btn_edit_nw and ges_ev.pos:intersectWith(self.btn_edit_nw.dimen) then
|
|
|
|
|
self:onEditNetwork()
|
|
|
|
|
else
|
|
|
|
|
self:connect()
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
self:onAddNetwork()
|
|
|
|
|
end
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
|
local NetworkSetting = InputContainer:extend{
|
2016-06-26 00:53:08 +00:00
|
|
|
|
width = nil,
|
|
|
|
|
height = nil,
|
|
|
|
|
-- sample network_list entry: {
|
|
|
|
|
-- bssid = "any",
|
|
|
|
|
-- ssid = "foo",
|
|
|
|
|
-- signal_level = -58,
|
|
|
|
|
-- signal_quality = 84,
|
|
|
|
|
-- frequency = 5660,
|
|
|
|
|
-- flags = "[WPA2-PSK-CCMP][ESS]",
|
|
|
|
|
-- }
|
|
|
|
|
network_list = nil,
|
|
|
|
|
connect_callback = nil,
|
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
|
|
|
|
disconnect_callback = nil,
|
2016-06-26 00:53:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function NetworkSetting:init()
|
|
|
|
|
self.width = self.width or Screen:getWidth() - Screen:scaleBySize(50)
|
|
|
|
|
self.width = math.min(self.width, Screen:scaleBySize(600))
|
|
|
|
|
|
2019-03-14 19:58:45 +00:00
|
|
|
|
local gray_bg = Blitbuffer.COLOR_GRAY_E
|
2016-06-26 00:53:08 +00:00
|
|
|
|
local items = {}
|
|
|
|
|
table.sort(self.network_list,
|
|
|
|
|
function(l, r) return l.signal_quality > r.signal_quality end)
|
2018-07-07 15:06:58 +00:00
|
|
|
|
for idx, network in ipairs(self.network_list) do
|
2016-06-26 00:53:08 +00:00
|
|
|
|
local bg
|
2019-03-27 21:50:44 +00:00
|
|
|
|
if band(idx, 1) == 0 then
|
2016-06-26 00:53:08 +00:00
|
|
|
|
bg = gray_bg
|
|
|
|
|
else
|
|
|
|
|
bg = Blitbuffer.COLOR_WHITE
|
|
|
|
|
end
|
|
|
|
|
table.insert(items, NetworkItem:new{
|
|
|
|
|
width = self.width,
|
|
|
|
|
info = network,
|
|
|
|
|
background = bg,
|
|
|
|
|
setting_ui = self,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self.status_text = TextWidget:new{
|
|
|
|
|
text = "",
|
|
|
|
|
face = Font:getFace("ffont"),
|
|
|
|
|
}
|
|
|
|
|
self.page_text = TextWidget:new{
|
|
|
|
|
text = "",
|
|
|
|
|
face = Font:getFace("ffont"),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.pagination = MinimalPaginator:new{
|
|
|
|
|
width = self.width,
|
|
|
|
|
height = Screen:scaleBySize(8),
|
|
|
|
|
percentage = 0,
|
2016-12-04 14:15:15 +00:00
|
|
|
|
progress = 0,
|
2016-06-26 00:53:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.height = self.height or math.min(Screen:getHeight()*3/4,
|
|
|
|
|
Screen:scaleBySize(800))
|
|
|
|
|
self.popup = FrameContainer:new{
|
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
|
padding = 0,
|
2017-09-13 14:56:20 +00:00
|
|
|
|
bordersize = Size.border.window,
|
2016-06-26 00:53:08 +00:00
|
|
|
|
VerticalGroup:new{
|
|
|
|
|
align = "left",
|
|
|
|
|
self.pagination,
|
|
|
|
|
ListView:new{
|
|
|
|
|
padding = 0,
|
|
|
|
|
items = items,
|
|
|
|
|
width = self.width,
|
|
|
|
|
height = self.height-self.pagination:getSize().h,
|
|
|
|
|
page_update_cb = function(curr_page, total_pages)
|
|
|
|
|
self.pagination:setProgress(curr_page/total_pages)
|
|
|
|
|
-- self.page_text:setText(curr_page .. "/" .. total_pages)
|
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
|
return "ui", self.dimen
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self[1] = CenterContainer:new{
|
|
|
|
|
dimen = {w = Screen:getWidth(), h = Screen:getHeight()},
|
|
|
|
|
self.popup,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
|
self.ges_events.TapClose = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "tap",
|
|
|
|
|
range = Geom:new{
|
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
end
|
2016-11-05 23:40:39 +00:00
|
|
|
|
|
|
|
|
|
UIManager:nextTick(function()
|
|
|
|
|
local connected_item = self:getConnectedItem()
|
|
|
|
|
if connected_item ~= nil then
|
|
|
|
|
obtainIP()
|
2018-07-07 15:06:58 +00:00
|
|
|
|
if G_reader_settings:nilOrTrue("auto_dismiss_wifi_scan") then
|
2021-04-19 19:29:12 +00:00
|
|
|
|
UIManager:close(self, "ui", self.dimen)
|
2018-07-07 15:06:58 +00:00
|
|
|
|
end
|
2016-11-05 23:40:39 +00:00
|
|
|
|
UIManager:show(InfoMessage:new{
|
2023-11-09 20:08:26 +00:00
|
|
|
|
text = T(_("Connected to network %1"), BD.wrap(connected_item.display_ssid)),
|
2019-10-21 08:06:03 +00:00
|
|
|
|
timeout = 3,
|
2016-11-05 23:40:39 +00:00
|
|
|
|
})
|
|
|
|
|
if self.connect_callback then
|
|
|
|
|
self.connect_callback()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end)
|
2016-06-26 00:53:08 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NetworkSetting:setConnectedItem(item)
|
|
|
|
|
self.connected_item = item
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NetworkSetting:getConnectedItem()
|
|
|
|
|
return self.connected_item
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NetworkSetting:onTapClose(arg, ges_ev)
|
|
|
|
|
if ges_ev.pos:notIntersectWith(self.popup.dimen) then
|
|
|
|
|
UIManager:close(self)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return NetworkSetting
|