Unofficial Paperbnd/Popfeed plugin for KOReader

improve menu state-awareness

Changed files
+47 -12
+47 -12
main.lua
··· 86 86 end 87 87 88 88 function Paperbnd:addToMainMenu(menu_items) 89 + -- Helper function to truncate long strings 90 + local function truncateString(str, max_length) 91 + if str and #str > max_length then 92 + return str:sub(1, max_length - 3) .. "..." 93 + end 94 + return str 95 + end 96 + 89 97 menu_items.paperbnd = { 90 98 text = _("Paperbnd"), 91 99 sub_item_table = { 100 + -- Authentication section 92 101 { 93 - text = _("Set credentials"), 102 + text_func = function() 103 + if self:isAuthenticated() then 104 + return T(_("Account: @%1"), self.handle) 105 + else 106 + return _("Set credentials") 107 + end 108 + end, 94 109 keep_menu_open = true, 95 110 callback = function() 96 111 self:setCredentials() 97 112 end, 113 + separator = true, 98 114 }, 115 + -- Book management section 99 116 { 100 - text = _("Link current book"), 117 + text_func = function() 118 + if self:isCurrentBookLinked() then 119 + local doc_path = self:getCurrentDocumentPath() 120 + if doc_path and self.document_mappings[doc_path] then 121 + local mapping = self.document_mappings[doc_path] 122 + local title = truncateString(mapping.title, 40) 123 + return T(_("Linked: %1 by %2"), title, mapping.author) 124 + end 125 + end 126 + return _("Link current book") 127 + end, 101 128 enabled_func = function() 102 129 return self:isAuthenticated() and self.ui.document ~= nil 103 130 end, ··· 106 133 end, 107 134 }, 108 135 { 136 + text = _("Unlink current book"), 137 + enabled_func = function() 138 + return self:isCurrentBookLinked() 139 + end, 140 + callback = function() 141 + self:unlinkCurrentBook() 142 + end, 143 + separator = true, 144 + }, 145 + -- Sync section 146 + { 109 147 text = _("Sync progress now"), 110 148 enabled_func = function() 111 149 return self:isAuthenticated() and self:isCurrentBookLinked() ··· 115 153 end, 116 154 }, 117 155 { 118 - text = _("Auto-sync on page turn"), 156 + text_func = function() 157 + if self.auto_sync_enabled then 158 + return _("Auto-sync: Enabled") 159 + else 160 + return _("Auto-sync: Disabled") 161 + end 162 + end, 119 163 checked_func = function() 120 164 return self.auto_sync_enabled 121 165 end, ··· 135 179 text = T(_("Auto-sync %1"), status), 136 180 timeout = 2, 137 181 })) 138 - end, 139 - }, 140 - { 141 - text = _("Unlink current book"), 142 - enabled_func = function() 143 - return self:isCurrentBookLinked() 144 - end, 145 - callback = function() 146 - self:unlinkCurrentBook() 147 182 end, 148 183 }, 149 184 },