From 090a0f80352ee5c1184bf19d20f8debdc3d67023 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Tue, 5 Mar 2019 13:00:49 +0100 Subject: [PATCH] [feat] plugins/wallabag: Allow calling Wallabag retrieval with event --- plugins/wallabag.koplugin/main.lua | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/plugins/wallabag.koplugin/main.lua b/plugins/wallabag.koplugin/main.lua index f872f1357..2b48e67fc 100644 --- a/plugins/wallabag.koplugin/main.lua +++ b/plugins/wallabag.koplugin/main.lua @@ -1,5 +1,6 @@ local DataStorage = require("datastorage") -local DocSettings = require("frontend/docsettings") +local DocSettings = require("docsettings") +local Event = require("ui/event") local FFIUtil = require("ffi/util") local FileManager = require("apps/filemanager/filemanager") local InfoMessage = require("ui/widget/infomessage") @@ -85,12 +86,7 @@ function Wallabag:addToMainMenu(menu_items) { text = _("Retrieve new articles from server"), callback = function() - if not NetworkMgr:isOnline() then - NetworkMgr:promptWifiOn() - return - end - self:synchronise() - self:refreshCurrentDirIfNeeded() + self.ui:handleEvent(Event:new("SynchronizeWallabag")) end, }, { @@ -188,7 +184,7 @@ function Wallabag:addToMainMenu(menu_items) end, }, { - text = _("Synchronise remotely deleted files"), + text = _("Synchronize remotely deleted files"), checked_func = function() return self.is_sync_remote_delete end, callback = function() self.is_sync_remote_delete = not self.is_sync_remote_delete @@ -204,7 +200,7 @@ function Wallabag:addToMainMenu(menu_items) Articles marked as finished or 100% read can be deleted from the server. Those articles can also be deleted automatically when downloading new articles if the 'Process deletions during download' option is enabled. -The 'Synchronise remotely deleted files' option will remove local files that no longer exist on the server.]]) +The 'Synchronize remotely deleted files' option will remove local files that no longer exist on the server.]]) }) end, } @@ -215,7 +211,7 @@ The 'Synchronise remotely deleted files' option will remove local files that no keep_menu_open = true, callback = function() UIManager:show(InfoMessage:new{ - text = T(_([[Wallabag is an open source read-it-later service. This plugin synchronises with a Wallabag server. + text = T(_([[Wallabag is an open source read-it-later service. This plugin synchronizes with a Wallabag server. More details: https://wallabag.org @@ -403,7 +399,7 @@ function Wallabag:callAPI( method, apiurl, headers, body, filepath ) end end -function Wallabag:synchronise() +function Wallabag:synchronize() local info = InfoMessage:new{ text = _("Connecting…") } UIManager:show(info) UIManager:forceRePaint() @@ -442,7 +438,7 @@ function Wallabag:synchronise() failed_count = failed_count + 1 end end - -- synchronise remote deletions + -- synchronize remote deletions deleted_count = deleted_count + self:processRemoteDeletes( remote_article_ids ) local msg @@ -730,4 +726,13 @@ function Wallabag:saveWBSettings(setting) self.wb_settings:flush() end +function Wallabag:onSynchronizeWallabag() + if not NetworkMgr:isOnline() then + NetworkMgr:promptWifiOn() + return + end + self:synchronize() + self:refreshCurrentDirIfNeeded() +end + return Wallabag