KOSync plugin should respect onNetworkConnected and onFlushSettings events

pull/2307/head
Zijie He 8 years ago committed by Qingping Hou
parent 42b705f47d
commit f36f8cb464

@ -80,11 +80,20 @@ function NetworkMgr:getWifiMenuTable()
enabled_func = function() return Device:isKindle() or Device:isKobo() end,
checked_func = function() return NetworkMgr:getWifiStatus() end,
callback = function(menu)
local wifi_status = NetworkMgr:getWifiStatus()
local complete_callback = function()
-- notify touch menu to update item check state
menu:updateItems()
local Event = require("ui/event")
-- if wifi was on, this callback will only be executed when the network has been
-- disconnected.
if wifi_status then
UIManager:broadcastEvent(Event:new("NetworkDisconnected"))
else
UIManager:broadcastEvent(Event:new("NetworkConnected"))
end
end
if NetworkMgr:getWifiStatus() then
if wifi_status then
NetworkMgr:promptWifiOff(complete_callback)
else
NetworkMgr:promptWifiOn(complete_callback)

@ -36,7 +36,7 @@ function UIManager:init()
self:sendEvent(input_event)
end,
SaveState = function()
self:sendEvent(Event:new("FlushSettings"))
self:broadcastEvent(Event:new("FlushSettings"))
end,
Power = function(input_event)
Device:onPowerEvent(input_event)

@ -601,13 +601,25 @@ function KOSync:_onResume()
UIManager:scheduleIn(1, function() self:getProgress() end)
end
function KOSync:_onFlushSettings()
self:updateProgress()
end
function KOSync:_onNetworkConnected()
self:_onResume()
end
function KOSync:registerEvents()
if self.kosync_auto_sync then
self.onPageUpdate = self._onPageUpdate
self.onResume = self._onResume
self.onFlushSettings = self._onFlushSettings
self.onNetworkConnected = self._onNetworkConnected
else
self.onPageUpdate = nil
self.onResume = nil
self.onFlushSettings = nil
self.onNetworkConnected = nil
end
end

Loading…
Cancel
Save