Reorder menu: push/pull at top, remove Sync now, auto-position in tools menu
This commit is contained in:
@@ -16,6 +16,7 @@ local logger = require("logger")
|
||||
local sha2 = require("ffi/sha2")
|
||||
local time = require("ui/time")
|
||||
local util = require("util")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local T = require("ffi/util").template
|
||||
local _ = require("gettext")
|
||||
|
||||
@@ -94,6 +95,7 @@ function Bookhoard:init()
|
||||
end
|
||||
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
self:setupMenuOrder()
|
||||
end
|
||||
|
||||
function Bookhoard:onReaderReady()
|
||||
@@ -173,6 +175,19 @@ function Bookhoard:buildMainMenu()
|
||||
})
|
||||
|
||||
if self:isConfigured() then
|
||||
table.insert(items, {
|
||||
text = _("Push progress from this device"),
|
||||
callback = function()
|
||||
self:updateProgress(true, true)
|
||||
end,
|
||||
})
|
||||
table.insert(items, {
|
||||
text = _("Pull progress from server"),
|
||||
callback = function()
|
||||
self:getProgress(true, true)
|
||||
end,
|
||||
separator = true,
|
||||
})
|
||||
table.insert(items, {
|
||||
text = _("Device info"),
|
||||
keep_menu_open = true,
|
||||
@@ -403,32 +418,6 @@ function Bookhoard:buildMainMenu()
|
||||
separator = true,
|
||||
})
|
||||
|
||||
table.insert(items, {
|
||||
text = _("Sync now"),
|
||||
enabled_func = function() return self:isConfigured() end,
|
||||
callback = function()
|
||||
self:updateProgress(true, true)
|
||||
self:getProgress(true, true)
|
||||
end,
|
||||
})
|
||||
|
||||
table.insert(items, {
|
||||
text = _("Push progress from this device"),
|
||||
enabled_func = function() return self:isConfigured() end,
|
||||
callback = function()
|
||||
self:updateProgress(true, true)
|
||||
end,
|
||||
})
|
||||
|
||||
table.insert(items, {
|
||||
text = _("Pull progress from server"),
|
||||
enabled_func = function() return self:isConfigured() end,
|
||||
callback = function()
|
||||
self:getProgress(true, true)
|
||||
end,
|
||||
separator = true,
|
||||
})
|
||||
|
||||
table.insert(items, {
|
||||
text = _("Setup OPDS catalog"),
|
||||
keep_menu_open = true,
|
||||
@@ -479,6 +468,85 @@ function Bookhoard:toggleAutoSync()
|
||||
end
|
||||
end
|
||||
|
||||
function Bookhoard:setupMenuOrder()
|
||||
local settings_dir = DataStorage:getSettingsDir()
|
||||
self:patchMenuOrderFile(settings_dir .. "/reader_menu_order.lua")
|
||||
self:patchMenuOrderFile(settings_dir .. "/filemanager_menu_order.lua")
|
||||
end
|
||||
|
||||
function Bookhoard:patchMenuOrderFile(filepath)
|
||||
local default_tools = {
|
||||
"read_timer",
|
||||
"calibre",
|
||||
"bookhoard",
|
||||
"exporter",
|
||||
"statistics",
|
||||
"progress_sync",
|
||||
"move_to_archive",
|
||||
"wallabag",
|
||||
"news_downloader",
|
||||
"text_editor",
|
||||
"profiles",
|
||||
"qrclipboard",
|
||||
"----------------------------",
|
||||
"more_tools",
|
||||
}
|
||||
|
||||
local attr = lfs.attributes(filepath)
|
||||
if not attr then
|
||||
local f = io.open(filepath, "w")
|
||||
if not f then return end
|
||||
f:write("return {\n tools = {\n")
|
||||
for _, id in ipairs(default_tools) do
|
||||
f:write(' "' .. id .. '",\n')
|
||||
end
|
||||
f:write(" },\n}\n")
|
||||
f:close()
|
||||
logger.dbg("Bookhoard: created menu order file", filepath)
|
||||
return
|
||||
end
|
||||
|
||||
local existing = dofile(filepath)
|
||||
if not existing or type(existing) ~= "table" then return end
|
||||
|
||||
local tools = existing.tools
|
||||
if not tools or type(tools) ~= "table" then return end
|
||||
|
||||
for _, id in ipairs(tools) do
|
||||
if id == "bookhoard" then return end
|
||||
end
|
||||
|
||||
local insert_pos = nil
|
||||
for i, id in ipairs(tools) do
|
||||
if id == "calibre" then
|
||||
insert_pos = i + 1
|
||||
break
|
||||
end
|
||||
end
|
||||
if not insert_pos then
|
||||
insert_pos = 2
|
||||
end
|
||||
|
||||
table.insert(tools, insert_pos, "bookhoard")
|
||||
existing.tools = tools
|
||||
|
||||
local f = io.open(filepath, "w")
|
||||
if not f then return end
|
||||
f:write("return {\n")
|
||||
for key, val in pairs(existing) do
|
||||
if type(val) == "table" then
|
||||
f:write(" " .. key .. " = {\n")
|
||||
for _, id in ipairs(val) do
|
||||
f:write(' "' .. id .. '",\n')
|
||||
end
|
||||
f:write(" },\n")
|
||||
end
|
||||
end
|
||||
f:write("}\n")
|
||||
f:close()
|
||||
logger.dbg("Bookhoard: patched menu order file", filepath)
|
||||
end
|
||||
|
||||
function Bookhoard:startRegistration()
|
||||
if not self.settings.server_url or self.settings.server_url == "" then
|
||||
UIManager:show(InfoMessage:new{
|
||||
|
||||
Reference in New Issue
Block a user