Auto-add OPDS catalog to KOReader after device registration

Writes directly to KOReader's opds.lua settings so the user
doesn't have to type the long URL. Also updates the manual
menu item to auto-configure instead of showing the URL.
This commit is contained in:
2026-05-29 22:42:26 -04:00
parent 517a8d3473
commit 89bdcc50f3
+36 -7
View File
@@ -1,8 +1,10 @@
local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage")
local Device = require("device")
local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage")
local InputDialog = require("ui/widget/inputdialog")
local LuaSettings = require("luasettings")
local Math = require("optmath")
local NetworkMgr = require("ui/network/manager")
local SpinWidget = require("ui/widget/spinwidget")
@@ -429,19 +431,19 @@ function Bookhoard:buildMainMenu()
table.insert(items, {
text = _("Setup OPDS catalog"),
keep_menu_open = true,
enabled_func = function() return self:isConfigured() end,
callback = function()
if not self.settings.server_url or not self.settings.device_id then
if self:setupOPDS() then
UIManager:show(InfoMessage:new{
text = _("Bookhoard OPDS catalog added! Find it in Home → OPDS Catalog."),
timeout = 3,
})
else
UIManager:show(InfoMessage:new{
text = _("Please configure and register your device first."),
timeout = 3,
})
return
end
local opds_url = self.settings.server_url
.. "/opds/devices/" .. self.settings.device_id .. "/catalog"
UIManager:show(InfoMessage:new{
text = T(_("Add this URL as an OPDS catalog in KOReader:\n\n%1\n\nGo to Home → + → OPDS Catalog to add it."), opds_url),
})
end,
})
@@ -552,6 +554,7 @@ function Bookhoard:startRegistrationPoll()
self.settings.sync_endpoints = result.sync_endpoints
G_reader_settings:saveSetting(self.settings_key, self.settings)
self:registerEvents()
self:setupOPDS()
if self.waiting_dialog then
UIManager:close(self.waiting_dialog)
self.waiting_dialog = nil
@@ -574,6 +577,32 @@ function Bookhoard:startRegistrationPoll()
UIManager:scheduleIn(3, poll)
end
function Bookhoard:setupOPDS()
if not self.settings.server_url or not self.settings.device_id then
return false
end
local opds_url = self.settings.server_url
.. "/opds/devices/" .. self.settings.device_id .. "/catalog"
local opds_settings_file = DataStorage:getSettingsDir() .. "/opds.lua"
local opds_settings = LuaSettings:open(opds_settings_file)
local servers = opds_settings:readSetting("servers", {})
for _, server in ipairs(servers) do
if server.url == opds_url then
return true
end
end
table.insert(servers, {
title = "Bookhoard",
url = opds_url,
})
opds_settings:saveSetting("servers", servers)
opds_settings:flush()
return true
end
function Bookhoard:getLastPercent()
if self.ui.document.info.has_pages then
return Math.roundPercent(self.ui.paging:getLastPercent())