Properly set bootlogo on pocketbook#14985
Conversation
After the cover image file is written or reset, invoke PocketBook's iv2sh WriteStartupLogo command so the device's boot logo is actually updated. The command runs in the background to avoid blocking KOReader.
For PocketBook devices, Screen:getWidth/getHeight returns dimensions that iv2sh will not accept. In that case, we should call Screen:getScreenWidth and Screen:getScreenHeight instead so the generated boot logo has the correct size.
| local s_w, s_h = Screen:getWidth(), Screen:getHeight() | ||
| local s_w, s_h | ||
| if Device.isPocketBook() then | ||
| s_w, s_h = Screen:getScreenWidth(), Screen:getScreenHeight() |
There was a problem hiding this comment.
Please add that info in the commit message as a comment.
There was a problem hiding this comment.
Thank you for your incredibly quick review! I made the changes you requested in 5355e71.
|
Hey @floriansnow I have a slightly different use-case for the boot logo: show the last displayed page so that one can start reading a few seconds after pressing the power button instead of waiting 15 seconds for KOReader to start and load the book. I opened #15124 — may I ask you to clarify whether there's a conflict with what's implemented by this PR, or if this PR is just a fix for newer PocketBook firmwares and doesn't interact with the "Current Page" boot logo setting at all? |
|
@liskin For full disclosure: I'm by no means an expert on KOReader nor on Lua; I just dug around the code to find what I needed. That being said, I don't have your use case, but this shouldn't affect it at all from what I can tell. My change affects what calls KOReader makes when setting a boot logo and it determines the size differently. My change does not touch what gets set in the first place. The settings inside the PocketBook firmware is yet another thing. |
Hm, well, that didn't tell me much. 🙁 So I went and did my own research (on my InkPad 3). It's bad news all over. It seems that regardless of what's set in the system settings (Personalize → Logos), both Additionally, it seems that the (I think I need to file 2 separate issue reports for this as both of these problems are seriously affecting the latest KOReader release on PocketBook devices.) |
|
Perhaps I'm missing something, but this whole behavior is in a plugin for setting a cover image. So of course, this behavior overrules what the PocketBook firmware itself does. I mean the PocketBook firmware also doesn't necessarily know what books KOReader opens, so the two are separate. AFAICT, the behavior is intentional. However, this is all optional: From how I understand your use case, you don't want to set a cover image, so you simply don't need this plugin. In regards to the sync: I tested this on two different PocketBook devices and noticed no slowdown. The iv2sh is slow which is why it runs in the background. If I leave out either one, the boot logo does not get set. I don't understand what it has to do with rotation changes. |
|
Digging through your contributions, I figured out that you use https://github.com/ckilb/pocketbooksync.koplugin to sync progress to the PocketBook firmware and also to get the current page as a boot logo. Now I understand why the PocketBook firmware setting and the KOReader behavior are linked to you. From what I can tell, you benefited from the bug that bothered me: KOReader was unable to properly set the boot logo so your other plugin worked as you want it. Now, the boot logo gets set properly and that overwrites what the other plugin does. What I said before about disabling the Cover Image plugin is still what I think your use case needs. |
What you're missing is that both your and my use-cases are just one of many. The cover plugin worked perfectly fine for setting the power-off logo, and then the boot logo could be set to something else. Perhaps the last page (my use-case), perhaps the PocketBook logo, perhaps some other image. With your changes, the cover plugin always sets the boot logo. If someone wants to only have the book cover as the power-off logo, they're stuck — your suggestion of disabling the cover plugin conflicts with needing to enable that plugin to generate the power-off logo. Also, the following code suggests that the power-off logo use-case is the primary one: koreader/frontend/device/pocketbook/device.lua Lines 421 to 423 in 6b6ecb5 Thus I believe the "fix" will need to be a bit more elaborate than this PR. We need some way to tell whether the user wishes to use the cover for the power-off logo, the boot logo, or both. Some ideas:
Interesting! What devices? Would you perhaps be able to upload Anyway, rotation: regardless of whether "Rotate image" is enabled in the cover plugin settings, every rotation change triggers the cover update, which generates the image (this might be cached), saves it to the cover file (always, so even if cached, this takes like half a second), then triggers The solution here is to either:
|
|
Btw, some extra info I discovered while debugging — the reason why the power-off logo works fine but the boot logo needed your fix is this: When PocketBook shuts down, it executes the The boot logo, however, is handled differently. My guess is that the IPC req mentioned previously uploads the boot logo from the tmp file to nvram so that it can be displayed early in the boot process. The (But that's all just extra context so that others don't need to rediscover it. Doesn't change anything I said in the previous comment.) |
|
Thanks for the deep dive into the firmware internals! That's really helpful context and I appreciate you documenting it for future contributors. I want to step back a bit because I think we may have been talking past each other, and I don't want to come across as defensive about this PR. As I mentioned at the start, I'm not an expert on KOReader or Lua. I found a problem, dug around the code, and submitted what I thought was a straightforward fix. So I want to be upfront that I may be wrong about some of my assumptions. My interpretation of the cover image plugin is that it's meant to set the book cover as the device's logo wherever possible, and that it simply couldn't set the boot logo before because the WriteStartupLogo call was missing. Your firmware analysis actually confirms that the boot logo needs to be uploaded to nvram. So from my perspective this was completing existing functionality, not adding new scope. That said, I can see your point that users might want the cover as their power-off logo without also setting the boot logo. I didn't consider that use case, partly because I had a hard time understanding your scenario until I realized you were using the pocketbooksync plugin. But you're right that it's not just about that plugin; the PocketBook firmware itself offers independent settings for boot logo and power-off logo, so users could have reasons to want them set differently regardless of what plugins they're running. I think this might be a question for the maintainers: what is the intended scope of the cover image plugin on PocketBook? Should it set both logos, only the power-off logo, or should it be user-configurable? I don't think the code as it existed before my PR gives a clear answer either way, and I'd rather not guess. On the sync: my devices are a PocketBook Verse Pro Color and an InkPad Color 3, both on relatively recent firmware. Without the sync, the boot logo simply doesn't get set on either device. I agree it's weird given what you found in the decompiled code, but that was my experience. It's possible there's some additional weirdness at play, but I didn't mess with my devices in any meaningful way besides installing KOReader. I'm not sure about the legal implications of uploading parts of the firmware binaries, so I'd rather not do that without checking first, but I'm happy to run tests on my devices if that helps narrow things down. Regarding the rotation slowdown: I hadn't considered that code path, and I can see how a synchronous sync would cause problems there. Your suggestion of combining both into a single backgrounded command makes sense to me as an immediate improvement regardless of how the broader design question is resolved. I think I remember that not working for the use case of this PR, though, but perhaps I'm misremembering. I'm happy to work on a follow-up PR once there's some consensus on the direction, or to help test if someone else wants to take the lead on this. |
I think I took this PR as saying that the functionality already existed but that it happened to be broken on some devices. I'd probably just make it a checkbox to also set the boot logo or something? |
|
Okay, glad to hear we're on the same page now. I took a stab at implementing the reading of PocketBook's settings and acting accordingly — both in pocketbooksync plugin (ckilb/pocketbooksync.koplugin@01b66a9) and also as a userpatch for the cover plugin: local Device = require("device")
local ffi = require("ffi")
local inkview = ffi.load("inkview")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local userpatch = require("userpatch")
local util = require("util")
ffi.cdef[[
struct iconfig_s * GetGlobalConfig();
const char *ReadString(struct iconfig_s *cfg, const char *name, const char *deflt);
]]
userpatch.registerPatchPluginFunc("coverimage", function(CoverImage)
function CoverImage:updatePocketBookBootLogo()
if Device.isPocketBook() then
-- enable PocketBook's Personalize → Logos → Power-off Logo → Book Cover
os.remove("/mnt/ext1/system/logo/bookcover")
lfs.link(self.cover_image_path, "/mnt/ext1/system/logo/bookcover", true)
-- enable PocketBook's Personalize → Logos → Boot Logo → Book Cover
local bootlogo = ffi.string(inkview.ReadString(inkview.GetGlobalConfig(), "bootlogo", "@default_boot_logo"))
if bootlogo == "@cover_logo" then
logger.dbg("CoverImage: updating PocketBook boot logo from", self.cover_image_path)
-- run iv2sh in the background to avoid blocking KOReader
os.execute("iv2sh WriteStartupLogo " .. util.shell_escape({self.cover_image_path}) .. " &")
end
end
end
-- if Rotate image is disabled, we don't need to bother recreating the cover image
-- (this speeds up rotation changes by about half a second on PocketBook InkPad 3)
function CoverImage:onSetRotationMode(rotation)
logger.dbg("CoverImage: onSetRotationMode", rotation)
if self.cover_image_rotate then
self:createCoverImage(self.ui.doc_settings)
end
end
end)(place into With these two changes in place, everything works perfectly on my InkPad 3:
Would you perhaps be willing to test the patch? No need to bother with the pocketbooksync plugin — you just won't be able to use Boot Logo → Current Page. Although… that's rather trivial to add to the patch as well — let me know if you're interested 🙂
Fair enough. I can download the firmware packages and extract the files from there if need be, although it's a rather complicated procedure that I last did like 2 years ago. It's entirely possible that different firmware versions really do this stuff differently. Looking at the release notes for the 6.10 firmware for InkPad Color 3, it seems the logo personalisation is a new feature, whereas the InkPad 3 has had it basically forever… |
I don't mind guessing as much as as Florian, and my guess is that the functionality didn't exist. One could try to manually set the cover image path to /mnt/ext1/system/logo/bootlogo/cover.bmp, and then set that as the Boot Logo in the device settings, but I suspect the logo wouldn't get updated when the file changed. There was some discussion of power-off and boot logos in #6597 (look for "decal"). Some of those comments suggest that setting bootlogo was implemented, but I can't find it anywhere in the git history. Perhaps those comments actually suggest that it all happens automatically (in old firmwares where there were no settings for the logos)? Anyway, yeah, I can now see why guessing is silly 😆 |
|
Wow, that was quick! I went to sleep and now you prepared a patch! Thank you very much! I am absolutely up for testing the patch. Perhaps we should continue this discussion to a PR for your changes or an issue? |
Co-authored-by: liskin <300342+liskin@users.noreply.github.com> Agent-Logs-Url: https://github.com/liskin/koreader/sessions/40d4581f-4f82-4a99-b9a0-d711dea13f0f
I will also open a quick PR to not update the cover image on rotation changes if "Rotate image" is disabled |
Creating the cover image delays rotation a little bit (half a second, even if cached), although it could be several seconds on some PocketBook devices since koreader#14985 which synchronously invokes `sync` after creating the cover. To work around this, skip creating the image in the onSetRotationMode event hook if "Rotate image" is disabled as the resulting image would be exactly the same. The speedup is noticeable even if the cover cache gets hit. (The issue with synchronous `sync` taking several seconds will be fixed later once we figure out whether any PocketBook devices actually need the `sync` or not.) Related: koreader#15177 Related: koreader#14985
Creating the cover image delays rotation a little bit (half a second, even if cached), although it could be several seconds on some PocketBook devices since #14985 which synchronously invokes `sync` after creating the cover. To work around this, skip creating the image in the onSetRotationMode event hook if "Rotate image" is disabled as the resulting image would be exactly the same. The speedup is noticeable even if the cover cache gets hit. (The issue with synchronous `sync` taking several seconds will be fixed later once we figure out whether any PocketBook devices actually need the `sync` or not.) Related: #15177 Related: #14985
* CoverImage: call iv2sh to update PocketBook startup logo on cover change After the cover image file is written or reset, invoke PocketBook's iv2sh WriteStartupLogo command so the device's boot logo is actually updated. The command runs in the background to avoid blocking KOReader. * CoverImage: use correct screen dimensions on PocketBook for boot logo For PocketBook devices, Screen:getWidth/getHeight returns dimensions that iv2sh will not accept. In that case, we should call Screen:getScreenWidth and Screen:getScreenHeight instead so the generated boot logo has the correct size.
…#15179) Creating the cover image delays rotation a little bit (half a second, even if cached), although it could be several seconds on some PocketBook devices since koreader#14985 which synchronously invokes `sync` after creating the cover. To work around this, skip creating the image in the onSetRotationMode event hook if "Rotate image" is disabled as the resulting image would be exactly the same. The speedup is noticeable even if the cover cache gets hit. (The issue with synchronous `sync` taking several seconds will be fixed later once we figure out whether any PocketBook devices actually need the `sync` or not.) Related: koreader#15177 Related: koreader#14985
On several Pocketbook devices, the boot logo never gets updated. These changes fix that behavior by calling iv2sh and by creating an image with the correct dimensions so iv2sh accepts it.
This change is