mirror of
https://github.com/koreader/koreader.git
synced 2025-12-24 12:14:05 +01:00
prompt users to turn on Wifi if network is unreachable
This commit is contained in:
55
frontend/ui/networkmgr.lua
Normal file
55
frontend/ui/networkmgr.lua
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
local ConfirmBox = require("ui/widget/confirmbox")
|
||||||
|
local UIManager = require("ui/uimanager")
|
||||||
|
local Device = require("ui/device")
|
||||||
|
local DEBUG = require("dbg")
|
||||||
|
local _ = require("gettext")
|
||||||
|
|
||||||
|
local NetworkMgr = {}
|
||||||
|
|
||||||
|
local function kindleEnableWifi(toggle)
|
||||||
|
local lipc = require("liblipclua")
|
||||||
|
local lipc_handle = nil
|
||||||
|
if lipc then
|
||||||
|
lipc_handle = lipc.init("com.github.koreader.networkmgr")
|
||||||
|
end
|
||||||
|
if lipc_handle then
|
||||||
|
lipc_handle:set_int_property("com.lab126.cmd", "wirelessEnable", toggle)
|
||||||
|
lipc_handle:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function NetworkMgr:turnOnWifi()
|
||||||
|
if Device:isKindle() then
|
||||||
|
kindleEnableWifi(1)
|
||||||
|
elseif Device:isKobo() then
|
||||||
|
-- TODO: turn on wifi on kobo?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function NetworkMgr:turnOffWifi()
|
||||||
|
if Device:isKindle() then
|
||||||
|
kindleEnableWifi(0)
|
||||||
|
elseif Device:isKobo() then
|
||||||
|
-- TODO: turn off wifi on kobo?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function NetworkMgr:promptWifiOn()
|
||||||
|
UIManager:show(ConfirmBox:new{
|
||||||
|
text = _("Do you want to Turn on Wifi?"),
|
||||||
|
ok_callback = function()
|
||||||
|
self:turnOnWifi()
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
function NetworkMgr:promptWifiOff()
|
||||||
|
UIManager:show(ConfirmBox:new{
|
||||||
|
text = _("Do you want to Turn off Wifi?"),
|
||||||
|
ok_callback = function()
|
||||||
|
self:turnOffWifi()
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
return NetworkMgr
|
||||||
Submodule koreader-base updated: 66b1bcf4f8...43defcb8e0
@@ -2,6 +2,7 @@ local InputContainer = require("ui/widget/container/inputcontainer")
|
|||||||
local LoginDialog = require("ui/widget/logindialog")
|
local LoginDialog = require("ui/widget/logindialog")
|
||||||
local InfoMessage = require("ui/widget/infomessage")
|
local InfoMessage = require("ui/widget/infomessage")
|
||||||
local DocSettings = require("docsettings")
|
local DocSettings = require("docsettings")
|
||||||
|
local NetworkMgr = require("ui/networkmgr")
|
||||||
local UIManager = require("ui/uimanager")
|
local UIManager = require("ui/uimanager")
|
||||||
local Screen = require("ui/screen")
|
local Screen = require("ui/screen")
|
||||||
local Event = require("ui/event")
|
local Event = require("ui/event")
|
||||||
@@ -172,7 +173,11 @@ function EvernoteExporter:doLogin(username, password)
|
|||||||
}
|
}
|
||||||
self.evernote_username = username
|
self.evernote_username = username
|
||||||
local ok, token = pcall(oauth.getToken, oauth)
|
local ok, token = pcall(oauth.getToken, oauth)
|
||||||
if not ok or not token then
|
-- prompt users to turn on Wifi if network is unreachable
|
||||||
|
if not ok and token and token:find("Network is unreachable") then
|
||||||
|
NetworkMgr:promptWifiOn()
|
||||||
|
return
|
||||||
|
elseif not ok and token then
|
||||||
UIManager:show(InfoMessage:new{
|
UIManager:show(InfoMessage:new{
|
||||||
text = _("Error occurs when login:") .. "\n" .. token,
|
text = _("Error occurs when login:") .. "\n" .. token,
|
||||||
})
|
})
|
||||||
@@ -184,11 +189,14 @@ function EvernoteExporter:doLogin(username, password)
|
|||||||
authToken = token,
|
authToken = token,
|
||||||
}
|
}
|
||||||
local ok, guid = pcall(self.getExportNotebook, self, client)
|
local ok, guid = pcall(self.getExportNotebook, self, client)
|
||||||
if not ok or not guid then
|
if not ok and guid and guid:find("Transport not open") then
|
||||||
|
NetworkMgr:promptWifiOn()
|
||||||
|
return
|
||||||
|
elseif not ok and guid then
|
||||||
UIManager:show(InfoMessage:new{
|
UIManager:show(InfoMessage:new{
|
||||||
text = _("Error occurs when login:") .. "\n" .. guid,
|
text = _("Error occurs when login:") .. "\n" .. guid,
|
||||||
})
|
})
|
||||||
elseif guid then
|
elseif ok and guid then
|
||||||
self.evernote_token = token
|
self.evernote_token = token
|
||||||
self.notebook_guid = guid
|
self.notebook_guid = guid
|
||||||
UIManager:show(InfoMessage:new{
|
UIManager:show(InfoMessage:new{
|
||||||
@@ -300,11 +308,14 @@ function EvernoteExporter:exportClippings(client, clippings)
|
|||||||
local ok, err = pcall(self.exportBooknotes, self,
|
local ok, err = pcall(self.exportBooknotes, self,
|
||||||
client, title, booknotes)
|
client, title, booknotes)
|
||||||
-- error reporting
|
-- error reporting
|
||||||
if not ok then
|
if not ok and err and err:find("Transport not open") then
|
||||||
|
NetworkMgr:promptWifiOn()
|
||||||
|
return
|
||||||
|
elseif not ok and err then
|
||||||
DEBUG("Error occurs when exporting book:", title, err)
|
DEBUG("Error occurs when exporting book:", title, err)
|
||||||
error_count = error_count + 1
|
error_count = error_count + 1
|
||||||
error_title = title
|
error_title = title
|
||||||
else
|
elseif ok then
|
||||||
DEBUG("Exported notes in book:", title)
|
DEBUG("Exported notes in book:", title)
|
||||||
export_count = export_count + 1
|
export_count = export_count + 1
|
||||||
export_title = title
|
export_title = title
|
||||||
|
|||||||
Reference in New Issue
Block a user