diff --git a/frontend/ui/widget/container/inputcontainer.lua b/frontend/ui/widget/container/inputcontainer.lua index 95aa9727d..bde01dd09 100644 --- a/frontend/ui/widget/container/inputcontainer.lua +++ b/frontend/ui/widget/container/inputcontainer.lua @@ -99,6 +99,7 @@ function InputContainer:onInput(input) local InputDialog = require("ui/widget/inputdialog") self.input_dialog = InputDialog:new{ title = input.title or "", + input = input.input, input_hint = input.hint_func and input.hint_func() or input.hint or "", input_type = input.type or "number", buttons = { diff --git a/plugins/kosync.koplugin/KOSyncClient.lua b/plugins/kosync.koplugin/KOSyncClient.lua index 1789e7ae0..5b6afc93d 100644 --- a/plugins/kosync.koplugin/KOSyncClient.lua +++ b/plugins/kosync.koplugin/KOSyncClient.lua @@ -3,6 +3,7 @@ local DEBUG = require("dbg") local KOSyncClient = { service_spec = nil, + custom_url = nil, } function KOSyncClient:new(o) @@ -15,7 +16,9 @@ end function KOSyncClient:init() local Spore = require("Spore") - self.client = Spore.new_from_spec(self.service_spec) + self.client = Spore.new_from_spec(self.service_spec, { + base_url = self.custom_url, + }) package.loaded['Spore.Middleware.GinClient'] = {} require('Spore.Middleware.GinClient').call = function(self, req) req.headers['accept'] = "application/vnd.koreader.v1+json" diff --git a/plugins/kosync.koplugin/main.lua b/plugins/kosync.koplugin/main.lua index 8d40f051d..0d6093e92 100644 --- a/plugins/kosync.koplugin/main.lua +++ b/plugins/kosync.koplugin/main.lua @@ -27,6 +27,7 @@ local KOSync = InputContainer:new{ function KOSync:init() local settings = G_reader_settings:readSetting("kosync") or {} + self.kosync_custom_server = settings.custom_server self.kosync_username = settings.username self.kosync_userkey = settings.userkey self.kosync_auto_sync = not (settings.auto_sync == false) @@ -69,11 +70,28 @@ function KOSync:addToMainMenu(tab_item_table) self:updateProgress() self:getProgress(true) end, - } + }, + { + text = _("Custom sync server"), + tap_input = { + title = _("Custom progress sync server address"), + input = self.kosync_custom_server or "https://", + type = "text", + callback = function(input) + self:setCustomServer(input) + end, + }, + }, } }) end +function KOSync:setCustomServer(server) + DEBUG("set custom server", server) + self.kosync_custom_server = server ~= "" and server or nil + self:onSaveSettings() +end + function KOSync:login() if NetworkMgr:getWifiStatus() == false then NetworkMgr:promptWifiOn() @@ -144,6 +162,7 @@ end function KOSync:doRegister(username, password) local KOSyncClient = require("KOSyncClient") local client = KOSyncClient:new{ + custom_url = self.kosync_custom_server, service_spec = self.path .. "/api.json" } local userkey = md5:sum(password) @@ -173,6 +192,7 @@ end function KOSync:doLogin(username, password) local KOSyncClient = require("KOSyncClient") local client = KOSyncClient:new{ + custom_url = self.kosync_custom_server, service_spec = self.path .. "/api.json" } local userkey = md5:sum(password) @@ -234,6 +254,7 @@ function KOSync:updateProgress() if self.kosync_username and self.kosync_userkey then local KOSyncClient = require("KOSyncClient") local client = KOSyncClient:new{ + custom_url = self.kosync_custom_server, service_spec = self.path .. "/api.json" } local doc_digest = self.view.document:fastDigest() @@ -255,6 +276,7 @@ function KOSync:getProgress(manual) if self.kosync_username and self.kosync_userkey then local KOSyncClient = require("KOSyncClient") local client = KOSyncClient:new{ + custom_url = self.kosync_custom_server, service_spec = self.path .. "/api.json" } local doc_digest = self.view.document:fastDigest() @@ -291,6 +313,7 @@ end function KOSync:onSaveSettings() local settings = { + custom_server = self.kosync_custom_server, username = self.kosync_username, userkey = self.kosync_userkey, auto_sync = self.kosync_auto_sync,