Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Reload library while syncing if new books are added. #12

Open
PinkMusen opened this issue Aug 5, 2024 · 7 comments
Open

Comments

@PinkMusen
Copy link

Most of us add our books with calibre, it's less inserts/removal's of the USB port and allows for use of magnetic attachment as data is not needed.

The drawback here is, that to get the built in library of the pocketbook to update to add the new books to it you need to either reboot the device or connect it to the PC with a USB cable.

I'd like to request adding a reload of the library when new books are added, this would make this addon as complete as can be for pocketbook integration to koreader.

@liskin
Copy link
Collaborator

liskin commented Aug 5, 2024

This would also be useful when books are removed. :-)

Personally, I use PocketBook's DropBox integration and then I mount the DropBox folder using rclone mount --vfs-cache-mode=full dropbox: ~/mnt/dropbox and then connect that folder in Calibre. This is probably because I've been using this long before I switched to KOReader. This has the additional advantage that I can tell the PocketBook to Sync and that also reloads the library.

So I'm guessing I might take a look at how the DropBox app for PocketBook makes the library reload and see if we can replicate that. But in the meantime, can you perhaps try if there's a Sync button on your PocketBook somewhere and whether it reloads the library perhaps?

@liskin
Copy link
Collaborator

liskin commented Sep 8, 2024

Okay, I've done the research:

We need to do roughly the following:

int task = FindTaskByAppName("scanner.app")
if (task != -1) {
  const char *params = "-scan:<directory to reload>"
  SendRequestTo(task, REQ_OPENBOOK, params, strlen(params) + 1, 0, 2000)
}

I haven't written any Lua yet, I've only been doing openbook -1 /ebrmain/bin/scanner.app -scan:/mnt/ext1/something via ssh. OpenBook runs the above code as well (more or less) but it also makes scanner.app the foreground task, and we don't want that.

@liskin
Copy link
Collaborator

liskin commented Sep 8, 2024

Unfortunately KOReader doesn't seem to have hooks for refreshing the library. There's just hacks like this to refresh KOReader's file browser if it happens to be open. But we'd need to hook into other places as well, like when you finish a book and get the option to delete it. That might need some refactoring in KOReader itself :-/

liskin added a commit to liskin/pocketbooksync.koplugin that referenced this issue Sep 9, 2024
When we make changes to the file system — either by moving/copying in
the file manager, by deleting a book that's just been finished, or by
adding books using the Calibre plugin — the user expects PocketBook's
library and home screen to be updated.

This commit implements a function that asks the scanner task to rescan
the home directory (as set in KOReader's file manager). Unfortunately,
KOReader currently doesn't expose any hooks/events for the file system
being changed, so this function is only made available as a menu item.

The full functionality of automatically rescanning whenever necessary
shall be implemented later, when hooks/events in KOReader are available.

Related: ckilb#12
@liskin
Copy link
Collaborator

liskin commented Sep 9, 2024

I've implemented this as a menu entry for the time being: main...liskin:pocketbooksync.koplugin:reload-library
If you've been rebooting the device to reload the library, this should be a significant upgrade for you.

Next step is to hook this into KOReader, but that will require some way to hook into all the places where the rescan needs to happen. I don't honestly expect to get to that any time soon, so if you could open an issue at https://github.com/koreader/koreader/issues that would be immensely helpful.

@ckilb
Copy link
Owner

ckilb commented Dec 13, 2024

@liskin Is it OK for you, if I add your code into this repository?

Also, I'd be interested if you could quickly tell me how you found out how to do this. Especially, how did you know about scanner.app and it's params?

@liskin
Copy link
Collaborator

liskin commented Dec 13, 2024

Yeah absolutely, if you think some of the code in my fork is ready, feel free to use it.

How I found this - it was a mix of reverse engineering the Dropbox binary and scanner.app using Ghidra and a lot of trial and error. 🙂

@liskin
Copy link
Collaborator

liskin commented Dec 13, 2024

Happy to elaborate later but am on my mobile at a party now

liskin added a commit to liskin/pocketbooksync.koplugin that referenced this issue Jan 26, 2025
When we make changes to the file system — either by moving/copying in
the file manager, by deleting a book that's just been finished, or by
adding books using the Calibre plugin — the user expects PocketBook's
library and home screen to be updated.

This commit implements a function that asks the scanner task to rescan
the home directory (as set in KOReader's file manager). Unfortunately,
KOReader currently doesn't expose any hooks/events for the file system
being changed, so this function is only made available as a menu item.

The full functionality of automatically rescanning whenever necessary
shall be implemented later, when hooks/events in KOReader are available.

Related: ckilb#12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants