Cloud-based sync for 2 plugins: reading statistics and vocabulary builder (#9709)

This commit adds cross-device sync ability for two plugins: reading statistics and vocabulary builder. It relies on user setting up a Cloud server (DropBox and WebDAV but not FTP though) and designating a path. Behind the curtains sqlite databases are being passed around and updated.

UI-wise, for the statistics plugin, two new menu items Synchronize now and Cloud sync to set it up (might not be the best wording) are added. As for vocabulary builder, a similar Cloud sync button is added to the menu and a shortcut icon button to Synchronize now is pinned at the bottom corner.

CloudStorage new features: WebDAV creating folders and uploading files. And a new widget-like sync server chooser. In the end I decided not to add automatic sync, as the SQL commands part seem a bit much.
This commit is contained in:
weijiuqiao
2022-11-11 22:53:06 +08:00
committed by GitHub
parent 4f3000e882
commit 8500fdd519
8 changed files with 727 additions and 19 deletions

View File

@@ -173,11 +173,11 @@ function CloudStorage:openCloudServer(url)
if NetworkMgr:willRerunWhenConnected(function() self:openCloudServer(url) end) then
return
end
tbl, e = WebDav:run(self.address, self.username, self.password, url)
tbl, e = WebDav:run(self.address, self.username, self.password, url, self.choose_folder_mode)
end
if tbl then
self:switchItemTable(url, tbl)
if self.type == "dropbox" then
if self.type == "dropbox" or self.type == "webdav" then
self.onLeftButtonTap = function()
self:showPlusMenu(url)
end
@@ -648,7 +648,11 @@ function CloudStorage:uploadFile(url)
end)
local url_base = url ~= "/" and url or ""
UIManager:tickAfterNext(function()
DropBox:uploadFile(url_base, self.password, file_path, callback_close)
if self.type == "dropbox" then
DropBox:uploadFile(url_base, self.password, file_path, callback_close)
elseif self.type == "webdav" then
WebDav:uploadFile(url_base, self.address, self.username, self.password, file_path, callback_close)
end
end)
end
end
@@ -686,7 +690,11 @@ function CloudStorage:createFolder(url)
end
self:openCloudServer(url)
end
DropBox:createFolder(url_base, self.password, folder_name, callback_close)
if self.type == "dropbox" then
DropBox:createFolder(url_base, self.password, folder_name, callback_close)
elseif self.type == "webdav" then
WebDav:createFolder(url_base, self.address, self.username, self.password, folder_name, callback_close)
end
end,
},
}