Move kosync plugin settings into a separate file (#15591)

This commit is contained in:
Grigorii Ioffe authored and GitHub committed 2026-06-26 17:07:59 +02:00
1 parent 27a8f635d6
commit 5549f8ac6c
2 files changed
+50 -4

No files matched your search

+14 -1
View File
@@ -12,7 +12,7 @@ local util = require("util")
local _ = require("gettext")
-- Date at which the last migration snippet was added
local CURRENT_MIGRATION_DATE = 20260517
local CURRENT_MIGRATION_DATE = 20260623
-- Retrieve the date of the previous migration, if any
local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0)
@@ -1012,5 +1012,18 @@ if last_migration_date < 20260517 then
end
end
-- 20260623, Move Kosync plugin settings into a separate file
-- https://github.com/koreader/koreader/pull/15591
if last_migration_date < 20260623 then
logger.info("Performing one-time migration for 20260623")
local kosync_setting = G_reader_settings:readSetting("kosync")
if kosync_setting then
local settings = LuaSettings:open(DataStorage:getSettingsDir() .. "/kosync.lua")
settings:saveSetting("settings" , kosync_setting)
settings:flush()
G_reader_settings:delSetting("kosync")
end
end
-- We're done, store the current migration date
G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE)
+36 -3
View File
@@ -1,9 +1,11 @@
local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage")
local Device = require("device")
local Dispatcher = require("dispatcher")
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 MultiInputDialog = require("ui/widget/multiinputdialog")
local NetworkMgr = require("ui/network/manager")
@@ -21,7 +23,8 @@ local KOSync = WidgetContainer:extend{
name = "kosync",
is_doc_only = true,
title = _("Register/login to KOReader server"),
settings_key = "kosync",
settings_file = DataStorage:getSettingsDir() .. "/kosync.lua",
updated = nil,
push_timestamp = nil,
pull_timestamp = nil,
@@ -63,6 +66,20 @@ KOSync.default_settings = {
send_metadata = false,
}
function KOSync:loadSettings()
if not KOSync.settings_obj then
KOSync.settings_obj = LuaSettings:open(self.settings_file)
end
self.settings = KOSync.settings_obj:readSetting("settings", KOSync.default_settings)
end
function KOSync:onFlushSettings()
if self.updated then
KOSync.settings_obj:flush()
self.updated = nil
end
end
function KOSync:init()
self.push_timestamp = 0
self.pull_timestamp = 0
@@ -78,8 +95,7 @@ function KOSync:init()
-- We do *NOT* want to make sure networking is up here, as the nagging would be extremely annoying; we're leaving that to the network activity check...
self:updateProgress(false, false)
end
self.settings = G_reader_settings:readSetting(self.settings_key, self.default_settings)
self:loadSettings()
self.device_id = G_reader_settings:readSetting("device_id")
-- Disable auto-sync if beforeWifiAction was reset to "prompt" behind our back...
@@ -200,6 +216,7 @@ function KOSync:addToMainMenu(menu_items)
input = self.settings.custom_server or "https://",
callback = function(input)
self:setCustomServer(input)
self.updated = true
end,
}
end,
@@ -230,6 +247,7 @@ function KOSync:addToMainMenu(menu_items)
local hostname = dialog:getInputText()
logger.dbg("KOSync: Setting custom hostname to:", hostname)
self.settings.kosync_hostname = hostname ~= "" and hostname or nil
self.updated = true
UIManager:close(dialog)
end,
},
@@ -250,6 +268,7 @@ function KOSync:addToMainMenu(menu_items)
if self.settings.userkey then
return function(menu)
self:logout(menu)
self.updated = true
end
else
return function(menu)
@@ -265,6 +284,7 @@ function KOSync:addToMainMenu(menu_items)
help_text = _([[This may lead to nagging about toggling WiFi on document close and suspend/resume, depending on the device's connectivity.]]),
callback = function()
self:onKOSyncToggleAutoSync(nil, true)
self.updated = true
end,
},
{
@@ -291,6 +311,7 @@ If set to 0, updating progress based on page turns will be disabled.]]),
callback = function(spin)
self:setPagesBeforeUpdate(spin.value)
if touchmenu_instance then touchmenu_instance:updateItems() end
self.updated = true
end
}
UIManager:show(items)
@@ -313,6 +334,7 @@ If set to 0, updating progress based on page turns will be disabled.]]),
end,
callback = function()
self:setSyncForward(SYNC_STRATEGY.SILENT)
self.updated = true
end,
},
{
@@ -322,6 +344,7 @@ If set to 0, updating progress based on page turns will be disabled.]]),
end,
callback = function()
self:setSyncForward(SYNC_STRATEGY.PROMPT)
self.updated = true
end,
},
{
@@ -331,6 +354,7 @@ If set to 0, updating progress based on page turns will be disabled.]]),
end,
callback = function()
self:setSyncForward(SYNC_STRATEGY.DISABLE)
self.updated = true
end,
},
}
@@ -347,6 +371,7 @@ If set to 0, updating progress based on page turns will be disabled.]]),
end,
callback = function()
self:setSyncBackward(SYNC_STRATEGY.SILENT)
self.updated = true
end,
},
{
@@ -356,6 +381,7 @@ If set to 0, updating progress based on page turns will be disabled.]]),
end,
callback = function()
self:setSyncBackward(SYNC_STRATEGY.PROMPT)
self.updated = true
end,
},
{
@@ -365,6 +391,7 @@ If set to 0, updating progress based on page turns will be disabled.]]),
end,
callback = function()
self:setSyncBackward(SYNC_STRATEGY.DISABLE)
self.updated = true
end,
},
}
@@ -401,6 +428,7 @@ If set to 0, updating progress based on page turns will be disabled.]]),
end,
callback = function()
self:setChecksumMethod(CHECKSUM_METHOD.BINARY)
self.updated = true
end,
},
{
@@ -410,6 +438,7 @@ If set to 0, updating progress based on page turns will be disabled.]]),
end,
callback = function()
self:setChecksumMethod(CHECKSUM_METHOD.FILENAME)
self.updated = true
end,
},
}
@@ -420,6 +449,7 @@ If set to 0, updating progress based on page turns will be disabled.]]),
help_text = _([[When enabled, document metadata (filename, title, and authors) will be sent along with progress sync requests. This data is ignored by the official sync server but may be used by custom sync servers.]]),
callback = function()
self.settings.send_metadata = not self.settings.send_metadata
self.updated = true
end,
},
}
@@ -554,6 +584,7 @@ function KOSync:doRegister(username, password, menu)
if menu then
menu:updateItems()
end
self.updated = true
UIManager:show(InfoMessage:new{
text = _("Registered to KOReader server."),
})
@@ -590,6 +621,7 @@ function KOSync:doLogin(username, password, menu)
elseif status then
self.settings.username = username
self.settings.userkey = userkey
self.updated = true
if menu then
menu:updateItems()
end
@@ -983,6 +1015,7 @@ function KOSync:onKOSyncToggleAutoSync(toggle, from_menu)
return true
end
self.settings.auto_sync = not self.settings.auto_sync
self.updated = true
self:registerEvents()
if self.settings.auto_sync then