diff --git a/frontend/ui/networkmgr.lua b/frontend/ui/networkmgr.lua new file mode 100644 index 000000000..7fa9115d3 --- /dev/null +++ b/frontend/ui/networkmgr.lua @@ -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 diff --git a/koreader-base b/koreader-base index 66b1bcf4f..43defcb8e 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit 66b1bcf4f87f16598806445e6b437310411ffefc +Subproject commit 43defcb8e00db8f78fed747a697e77983ba33819 diff --git a/plugins/evernote.koplugin/main.lua b/plugins/evernote.koplugin/main.lua index aa95d49ff..c8a6ec9f6 100644 --- a/plugins/evernote.koplugin/main.lua +++ b/plugins/evernote.koplugin/main.lua @@ -2,6 +2,7 @@ local InputContainer = require("ui/widget/container/inputcontainer") local LoginDialog = require("ui/widget/logindialog") local InfoMessage = require("ui/widget/infomessage") local DocSettings = require("docsettings") +local NetworkMgr = require("ui/networkmgr") local UIManager = require("ui/uimanager") local Screen = require("ui/screen") local Event = require("ui/event") @@ -172,7 +173,11 @@ function EvernoteExporter:doLogin(username, password) } self.evernote_username = username 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{ text = _("Error occurs when login:") .. "\n" .. token, }) @@ -184,11 +189,14 @@ function EvernoteExporter:doLogin(username, password) authToken = token, } 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{ text = _("Error occurs when login:") .. "\n" .. guid, }) - elseif guid then + elseif ok and guid then self.evernote_token = token self.notebook_guid = guid UIManager:show(InfoMessage:new{ @@ -300,11 +308,14 @@ function EvernoteExporter:exportClippings(client, clippings) local ok, err = pcall(self.exportBooknotes, self, client, title, booknotes) -- 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) error_count = error_count + 1 error_title = title - else + elseif ok then DEBUG("Exported notes in book:", title) export_count = export_count + 1 export_title = title