koreader icon indicating copy to clipboard operation
koreader copied to clipboard

FR: option to show battery percentage in compact mode statusbar

Open KraXen72 opened this issue 1 year ago • 7 comments

Does your feature request involve difficulty completing a task? Please describe. i can's see the battery percentage when using the wonderful compact status bar mode, which i consider crucial information.

Describe the solution you'd like add a toggle that would show the battery percentage after the icon, like this: 🔋70 (no percentage sign necessary)

Describe alternatives you've considered

  • always checking the battery in the top menu, which is annoying and cumbersome.
  • using a different status bar display option, which takes up a lot more space

Additional context none

KraXen72 avatar Jul 31 '24 15:07 KraXen72

There is a user patch for this.

jonnyl2 avatar Jul 31 '24 15:07 jonnyl2

while it would be a good workaround if this doesen't get implemented, it just shows that more people requested it, it would be good to have this feature built-in

KraXen72 avatar Jul 31 '24 15:07 KraXen72

Wtf ?! :/ I forgot I already hacked something :( I spent the last 20mn rewritting one from scratch...

Anyway, if one wants to change functions or even symbols/texts/icons, it can indeed be done via user patches. There's so much different tastes and expectations that we can't fill them all with added toggles/options. So, manual hacking is the way to go.

local ReaderFooter = require("apps/reader/modules/readerfooter")
local userpatch = require("userpatch")

local orig_ReaderFooter_init = ReaderFooter.init
ReaderFooter.init = function(self)
    self.textGeneratorMap.battery = function(footer)
        -- Copy paste code from readerfooter, you can remove all the crap/tests you don't need
        return "ZZZ"
    end

    local symbol_prefix = userpatch.getUpValue(self.textGeneratorMap.frontlight, "symbol_prefix")
    symbol_prefix.icons.time = "XYZ"

    ReaderFooter.init = orig_ReaderFooter_init
    ReaderFooter.init(self)
end

poire-z avatar Jul 31 '24 16:07 poire-z

will this snippet work, or do i have to do further modifications to it? it looks unfinished with the xyz... sorry, i don't know lua, so that's why i'm asking

KraXen72 avatar Jul 31 '24 16:07 KraXen72

XYZ is what you want it to say.

Frenzie avatar Jul 31 '24 16:07 Frenzie

You need to learn Lua a little bit, at least understand these bits of code, so be ready for trial and errors and learning. It may be painful, but I assure you the satisfaction at the end will be enormous :)

You need to look at our original code: https://github.com/koreader/koreader/blob/dbebf3f9961a5fdc43fe797939cd66e461c9ed45/frontend/apps/reader/modules/readerfooter.lua#L178-L220

You cut and paste all this (except the first and the last line) into your userpatch file section

    self.textGeneratorMap.battery = function(footer)
        -- here
    end

And you would remove, in the parts you pasted from lines 211 to 219 the checks you don't need/want. I figure that you'd want to remove the lines I highlighted in red:

        if symbol_type == "icons" or symbol_type == "compact_items" then
--            if symbol_type == "compact_items" then
--                return BD.wrap(prefix)
--            else
                return BD.wrap(prefix) .. batt_lvl .. "%"
--            end
        else
            return BD.wrap(prefix) .. " " .. (is_charging and "+" or "") .. batt_lvl .. "%"
        end

so that in icons or compat modes, it uses what it uses originally in icon mode.

From https://github.com/koreader/koreader/pull/12249#issuecomment-2260777689

ideally two. i really like the icon for the 'icons' option, but i don't use that since i dislike the unnecessary clock icon.

If you find another Unicode symbol you like, you could just cut & paste it instead of my XYZ: symbol_prefix.icons.time = "🤯" or if you don't want any (like in compat mode), you would just do symbol_prefix.icons.time = nil (nil is Lua for null/unset/empty).

You also need to put at the top of my sample userpatch: local BD = require("ui/bidi") that I forgot - as well as any such thing I may have forgot.

poire-z avatar Jul 31 '24 16:07 poire-z

+1 I would use compact mode if it had battery percentage. Although not a big deal for me, icon mode is nice too.

Battery level might be useful in this case: On Android phones, probably users would like to use compact mode because of small screens. And on these phones, it is easier to detect if some background app is draining your battery when you can see the exact battery level instead of an icon. Just saying it as a reminder.

offset-torque avatar Jul 31 '24 22:07 offset-torque