mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
Adding Touch Menu Wifi Status icon/Toggler for Kobo and Kindle. Change to
NetworkMgr:getWifiStatus() to ping default gateway instead of 8.8.8.8.
This commit is contained in:
@@ -72,11 +72,15 @@ function NetworkMgr:promptWifiOff()
|
||||
end
|
||||
|
||||
function NetworkMgr:getWifiStatus()
|
||||
if os.execute("ping -c3 8.8.8.8") == 0 then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
local default_string = io.popen("ip r | grep default")
|
||||
local result = default_string:read()
|
||||
if result ~= nil then
|
||||
local gateway = string.match(result,"%d+.%d+.%d+.%d+")
|
||||
if os.execute("ping -q -c1 "..gateway) == 0 then
|
||||
return true
|
||||
end -- ping to gateway
|
||||
end -- test for empty string
|
||||
return false
|
||||
end
|
||||
|
||||
return NetworkMgr
|
||||
|
||||
@@ -20,6 +20,7 @@ local Geom = require("ui/geometry")
|
||||
local Font = require("ui/font")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
local NetworkMgr = require("ui/networkmgr")
|
||||
|
||||
--[[
|
||||
TouchMenuItem widget
|
||||
@@ -314,10 +315,28 @@ function TouchMenu:init()
|
||||
self.page_info_text,
|
||||
self.page_info_right_chev
|
||||
}
|
||||
--group for device info
|
||||
self.time_info = TextWidget:new{
|
||||
text = "",
|
||||
face = self.fface,
|
||||
}
|
||||
if Device:isKindle() or Device:isKobo() then
|
||||
self.net_info = Button:new{
|
||||
icon = "resources/icons/appbar.wifi.png",
|
||||
callback = function() self:netToggle() end,
|
||||
bordersize = 0,
|
||||
show_parent = self,
|
||||
}
|
||||
self.net_info.label_widget.dim = not NetworkMgr:getWifiStatus()
|
||||
self.device_info = HorizontalGroup:new{
|
||||
self.time_info,
|
||||
self.net_info,
|
||||
}
|
||||
else
|
||||
self.device_info = HorizontalGroup:new{
|
||||
self.time_info,
|
||||
}
|
||||
end
|
||||
local footer_width = self.width - self.padding*2 - self.bordersize*2
|
||||
self.footer = HorizontalGroup:new{
|
||||
LeftContainer:new{
|
||||
@@ -337,7 +356,7 @@ function TouchMenu:init()
|
||||
},
|
||||
RightContainer:new{
|
||||
dimen = Geom:new{ w = footer_width*0.33, h = self.footer_height},
|
||||
self.time_info,
|
||||
self.device_info,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,6 +454,15 @@ function TouchMenu:updateItems()
|
||||
UIManager.repaint_all = true
|
||||
end
|
||||
|
||||
function TouchMenu:netToggle()
|
||||
if NetworkMgr:getWifiStatus() == true then
|
||||
NetworkMgr:promptWifiOff()
|
||||
else
|
||||
NetworkMgr:promptWifiOn()
|
||||
end
|
||||
self:closeMenu()
|
||||
end
|
||||
|
||||
function TouchMenu:switchMenuTab(tab_num)
|
||||
if self.tab_item_table[tab_num].callback then
|
||||
self.tab_item_table[tab_num].callback()
|
||||
|
||||
BIN
resources/icons/appbar.wifi.png
Normal file
BIN
resources/icons/appbar.wifi.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 484 B |
Reference in New Issue
Block a user