koreader / kindlepdfviewer

(DEPRECATED, please use KOReader instead) A PDF (plus DJVU, ePub, TXT, CHM, FB2, HTML...) viewer made for e-ink framebuffer devices, using muPDF, djvulibre, crengine
GNU General Public License v3.0
498 stars 98 forks source link

Just another KPV launcher for KPW (Deprecated) #648

Closed chrox closed 11 years ago

chrox commented 11 years ago

I have implemented a prototype of KPV launcher for Kindle touch and Kindle Paperwhite. The launcher runs as a JBPatch which overrides native Kindle ReaderBooklet class on handling PDF documents in runtime. The source code can be found at https://gist.github.com/4193209

With this patch when opening certain types of documents in Kindle's home screen KPV is launched with the file path as the second parameter. And it will return to Kindle home screen when KPV is closed. In this way of launching KPV is treated more as a reader plugin than as a standalone reader app.

An obvious shortcoming of this launching method is that patches probably need to be compiled against almost every future firmware version thanks to Amazon's 'ever-more aggressive' obfuscation in the run-time libraries.

DO_NOT_INSTALL_THIS_LAUNCHER_IT_HAS_HIGH_PROBABILITY_TO_BRICK_YOUR_KPW

HOW_TO_INSTALL:

  1. copy jbpatch.jar to /opt/amazon/ebook/lib (You should compile the lattest version 3 from https://bitbucket.org/ixtab/jbpatcher/)
  2. add -istart jbpatch.jar before any other -istart line in /opt/amazon/ebook/bin/init.xargs
  3. compile com.mobileread.chrox.patch.kpw.kpvlauncher.530.jar from the gist mentioned above and copy it to /mnt/us/opt/jbpatch
  4. modify kpdf.sh in KPV dist according to the gist mentioned above
  5. run restart framework in your kindle

Binaries of jbpatch.jar and com.mobileread.chrox.patch.kpw.kpvlauncher.530.jar can be downloaded at https://github.com/chrox/misc/downloads if you don't want to compile them yourself. You need to select binaries according to your firmware version.

HOW_TO_ADD_MORE_TYPES: The SQLite database located at /var/local/appreg.db defines application association and document mime types. You can simply insert these records into appreg.db as follows to support EPUB type:

INSERT INTO "mimetypes" VALUES('epub','MT:application/epub+zip');
INSERT INTO "extenstions" VALUES('epub','MT:application/epub+zip');
INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','application/epub+zip','EPUB');
INSERT INTO "associations" VALUES('com.lab126.booklet.reader','application','MT:application/epub+zip','true');
INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.epub','true');

And in the gist https://gist.github.com/4193209 up to 15 mime types and app association records are predefined in mimes.sql. After running sqlite3 appreg.db < mimes.sql and restart scanner your kindle should be able to recognize "djvu","epub","cbz","chm","doc","fb2","htm","html","pdb","rtf","tcr","xps","zip" files in home screen. And opening these documents will launch KPV accordingly.

HOW_TO_DEBUG: When kindle framework is started jbpatch.jar is automatically loaded as configed in /opt/amazon/ebook/bin/init.xargs. You can watch the jbpatch log with the command of watch 'tail /tmp/jbpatch.log' and spot any bug of this patch.

KNOWN_BUGS:

Occasionally when returned from KPV to Kindle home screen there is an "Application Error" dialog showing that an application could not be started. So you should close the dialog before any other operation. I am thinking about how to eliminate this dialog.

SUGGESTED_FEATURES: Reading history and progress should be synchronizable between native ContentCatalog and KPV.

chrox commented 11 years ago

The "Application Error" bug has been fixed by bypassing the timeout checking code in another class. See the changes at gist https://gist.github.com/4193209 .

houqp commented 11 years ago

Wow, that's awesome! I will try it out tonight :)

Do you plan to include it into KPV tree or create a separate project for it?

chrox commented 11 years ago

Yes you can. I am informed that the 5.3 jailbreak is out just now.

chrox commented 11 years ago

Compiling jbpatch.jar relies on many proprietary libraries from Amazon such as Reader.jar and ReaderSDK.jar and so on. I'm afraid it's not proper to incorporate it into pure free KPV. If it's really desirable I will be glad to include it.

houqp commented 11 years ago

Yes you can. I am informed that the 5.3 jailbreak is out just now.

OMG.... Finally second life for my PW :)

Compiling jbpatch.jar relies on many proprietary libraries from Amazon such as Reader.jar and ReaderSDK.jar and so on. I'm afraid it's not proper to incorporate it into pure free KPV. If it's really desirable I will be glad to include it.

Yep, good point. We need to find a good way to deliver it to users, they are going to like it.

chrox commented 11 years ago

And I am waiting for the downloading of 5.3 update now. :)

tigran123 commented 11 years ago

Hmmm, with all these exciting events happening I might be tempted to buy a paperwhite myself :)

houqp commented 11 years ago

@tigran123 join us and free more kindle devices :)

chrox commented 11 years ago

@tigran123 Yes. You could give it a try. The resulting display turns out to be pretty good especially in low light condition.

chrox commented 11 years ago

Now this KPVLauncher supports opening up to 15 types of documents in kindle native framework. Complete support list is as follows: "pdf',"djvu","epub","cbz","chm","doc","fb2","htm","html","pdb","prc","rtf","tcr","xps","zip".

houqp commented 11 years ago

LOL, now my PW is bricked after installed JBPatch.

chrox commented 11 years ago

Oh, That's so bad. Is the JBPatch from ixtab's binary or from your building? I only use the jbpatch.jar from ixtab's dist as other patches are not fully tested in PW. But it seems pretty safe to only use the jbpatch.jar for it does extensive md5 check of the class object before performing any patch.

houqp commented 11 years ago

I used the binary from your repo. It turns out that it's caused by my typo in init.xargs. I modified the usbnetwork script to patch that file back on start up but it still gives me "Repair Needed" screen. (given from the output, init.xargs has been correctly patched). So I can now execute command on start up by modifying usbnetwork script, but I have no idea what else can I do to get rid of that screen. I cannot ssh into the device because it automatically turn off the usb device in 3 seconds after the repair screen show up.

Probably I need to look into the debrick method thread from mobileread ;p

chrox commented 11 years ago

Probably it's my fault. I checked the md5sum of jbpatch.jar and found it's different from the one I am using. But I don't understand why it should change as I didn't change a single line of code in jbpatch.jar. The one I unloaded yesterday runs well on 5.2.0 firmware. I thought it would not change at all so I didn't update the binary in my repo. But it turns out that the binary indeed is changed by some environment variable or something else. So I uploaded a copy of jbpatch.jar from the one I am using in firmware 5.3.0. You could overwrite the previous binary with the new one. And see if it boot up properly.

chrox commented 11 years ago

Wait a minute. Oh SHOT! One just cannot download binary file from the URL https://github.com/chrox/misc/blob/master/kindleviewerpatch/jbpatch.jar no matter with the browser downloader or wget. The downloaded file is not intact. But using https://github.com/chrox/misc/raw/master/kindleviewerpatch/jbpatch.jar will be OK.

chrox commented 11 years ago

I re-upload the two files in https://github.com/chrox/misc/downloads and I will delete the bins in repo right now as it's so misleading. I'm so sorry for the trouble.

houqp commented 11 years ago

Yeah, will try it later, no worry, I will get that fixed :)

houqp commented 11 years ago

OK, PW debricked ;P Trying to test your launcher again

houqp commented 11 years ago

Cool, it works now ! But sometimes I still get "application Error", is it fixed in your latest binary?

chrox commented 11 years ago

Thank god you fixed your bricked pw. I seldom meet the "application error" after using the current Kpvlauncher binary in the https://github.com/chrox/misc/downloads. Probably it's another bug. I will look into this later. And I found it's possible to change the last_access time and complete_percentage for the opened book in Kindle ContentCatalog so that KPV could share these info with Kindle home browser.

tigran123 commented 11 years ago

@houqp Out of curiosity, did you have to do soldering or messing with the serial port pins directly or was debricking a "pure software level" operation?

bhaak commented 11 years ago

@chrox Have you seen this booklet I did for HackedUpReader? https://github.com/bhaak/HackedUpReaderBooklet

It starts HUR as an external process similar to kpv without any jbpatch trickeries.

chrox commented 11 years ago

@bhaak No. It seems a much cleaner and cleverer solution. So can HackedUpReaderBooklet be associated with Epub docs the way like

INSERT INTO "associations" VALUES('com.lab126.booklet.HackedUpReaderBooklet','application','MT:application/epub+zip','true');

in the appreg.db?

bhaak commented 11 years ago

@chrox No, it's not quite as easy. If you read the mobileread thread that is linked from the HackedUpReaderBooklet, you see that you also have to add some data to the properties table:

INSERT INTO "properties" VALUES('com.lab126.booklet.hackedupreaderbooklet','lipcId','com.lab126.booklet.HackedUpReaderBooklet');
INSERT INTO "properties" VALUES('com.lab126.booklet.hackedupreaderbooklet','jar','/opt/amazon/ebook/booklet/hackedupreaderbooklet.jar');
[...]

Then it should work AFAIK. But I haven't tried this yet as I just used the testbooklet that is already defined.

Everything on the KT is already in place for a jar at /opt/amazon/ebook/booklet/testBook.jar with lipc id "com.lab126.booklet.testbooklet" and that was what I used for testing.

chrox commented 11 years ago

@bhaak Yes. I will try it that way so that KPV plugin could be integrated with native kindle framework as much as possible.

houqp commented 11 years ago

@tigran123 pure software operations. Just remove the corrupted file that I created before ;p

dracodoc commented 11 years ago

Sorry I've to ask here because I didn't find the information in other place: How do you use KPV in touch screen? Is it based on the new UI, or there is some keyboard simulation method?

houqp commented 11 years ago

@dracodoc , it's based on the new UI, an experimental demo can be found in here: https://github.com/hwhw/kindlepdfviewer/blob/new_ui_code/frontend/ui/reader/readerpaging.lua

I am very interested in how @bhaak implemented the touch support for HUR. Don' t have time to look into their code yet ;p

dracodoc commented 11 years ago

Thanks, it looks like KPV in KPW can be used in a experimental stage now, it's really good news.

Though I do like the convenience of keyboard shortcut. I think to implement all the features in touch UI in a convenient way could be not so easy....

chrox commented 11 years ago

@houqp I have tested @bhaak's implementation and it works. But sadly I bricked my kindle as I removed the jbpatch.jar but I forgot to modify /opt/amazon/ebook/bin/init.xargs and remove the -istart jbpatch.jar line. Now the screen just displays "Repair Needed" shortly after each reboot. I tried to add a "ENABLE_DIAGS" file but without luck.

bhaak commented 11 years ago

@houqp The Kindle Touch and PW are running an X11 server as UI framework. The HUR UI is just a X11 window and so it gets the UI events for free. I just mapped the touch and click events to the internal coolreader engine keys.

bhaak commented 11 years ago

@chrox I guess you have ssh enabled? Then you probably can already login while it is starting up and fix the file.

houqp commented 11 years ago

@bhaak cool, that makes life much easier :)

@chrox no worry, you got the same error as I did (corrupted init.xargs). Probably, you now can mount your kindle as USB mode for 3-4 seconds before you see the YKNP screen. Upon that time frame, you can put usbnetwork into auto start mode, then you can add commands in "usbnetwork/bin/usbnetwork" script and do the recovery. But even though you recovered the file, the YKNP screen will not disappear.

To get rid of the YKNP screen, you need to run following command first: echo 0 > /var/local/upstart/lab126_gui.restarts

If it does not work, try this: rm -f /var/local/upstart/*.restarts

I cannot remember which works for me. The discussion is here: http://www.mobileread.com/forums/showthread.php?t=157047&page=53

But I dont understand why ENABLE_DIAGS does not work for you. It works for me...

chrox commented 11 years ago

@bhaak Yes I tried. And put a auto file in the usbnet directory. But I cannot login. BTW I installed the kindle-usbnet-0.6.N version from NiLuJe's thread http://www.mobileread.com/forums/showthread.php?t=186645 . I installed ixtab's jailbreak for 5.2.0 and 5.3.0 when my kindle was on firmware 5.2.0. Then I updated my kindle to 5.3.0. But I forgot to install the jailbreak again. Probably it's why ENABLE_DIAGS does not work. Do you have any advice?

houqp commented 11 years ago

@chrox , yes, you will not be able to login because usbnetwork script will not be able to setup the ip. But the script will be executed, so you can still execute any commands

chrox commented 11 years ago

@houqp I will try it right now. thx.

houqp commented 11 years ago

If you did not install the new JB from ixtab, then you won't get ENABLE_DIAGS by default

houqp commented 11 years ago

Good luck, create files in /mnt/us to make sure your command runs successfully.

chrox commented 11 years ago

@houqp I remember the -istart jbpatch.jar line was on line 10. I just want to make sure of that in case that I mess up more. So how did you fix the init.xargs file?

houqp commented 11 years ago

safest way is to copy it to your /mnt/us and modify it on your os, then copy it back

houqp commented 11 years ago

@dracodoc, shortcuts are still supported. The new KPV will detect the model of the kindle device and enable/disable the shortcut/touch feature according to the model

chrox commented 11 years ago

Finally it's alive again. Thank you @houqp @bhaak.

houqp commented 11 years ago

cool, that's fast. remember to install Rescue Pack this time ;p

chrox commented 11 years ago

@houqp Yes. I won't make this mistake twice. This issue will be closed as I will open a new issue with a better solution provided by @bhaak .

dracodoc commented 11 years ago

@houqp I was mention the speed of launch certain functions in KPV in KPW. Using a keyboard shortcut can do lots of things in one step. While in touch UI, some most used operations can be implemented easily, but to squeeze more recognizable actions into touch UI could be not easy.

One method is to use menu, like sony T1. But I think all kinds of pop up menu in eink is slow and not efficient. Gesture could be better, then user may need to remember many arbitrate gestures.

This reminds me a launcher I used to use in palm pda, which could recognize your writings of one letter (it's built-in function of palm) and launch certain app. You can associate some letter in the app name to the letter gesture, so it's really easy to remember. I'm using some gesture action in firefox extensions but they don't support letters.

hwhw commented 11 years ago

I now own a KPW as well and hope to get back into action pretty soon. The holiday season is coming and I expect to have some spare time for the viewer again.

As for the UI concept, I envisioned something like a mixed gesture/menu thing. E-Ink is in fact quite fast when we use full black and white only (see e.g. my gnuboy implementation). I think I like to have something like an "action bar" appearing/disappearing on single tap where certain "actions" can be chosen. Like e.g. a bar of buttons.

Also, I'd like to somehow integrate this with the K4 controls.

K3/K2/KDX should certainly keep the convenience of keyboard shortcuts. I find them very useful.

Both concepts can coexist. I think the touch experience will also need some refinement when it comes to panning - and the K3 could profit, too. I think I like to make screen updates two-stage for these cases and start by blitting a b/w dithered image which is after a short wait (say 250msecs) overlaid by the grayscale rendering. This could allow for fast panning in a page. But that is just theory, need to test it (and add the blitDithered method for blitbuffers).

Oh, I eager for starting again.

dracodoc commented 11 years ago

I should be more specific about the menu. I think one step menu is fast enough, i.e. call menu(either by press and hold, or click certain area, or a gesture), then select one button to click. Some operations in Sony T1 involved multiple level menu which could be rather slow.

The letter gesture in palm probably will not fit in kindle, I'm thinking certain gesture + certain menus. For example, use one gesture to bring out a button bar of all kinds of zoom functions, another gesture for bookmark functions etc. The UI could be very flexible to be customized. I used to suggest a menu system for Foxit eslick and it was partly adpoted, see here

https://picasaweb.google.com/dracodoc/Eslick?authuser=0&authkey=Gv1sRgCIvC79_al9We3AE&feat=directlink

It was designed for the five way button of eslick, which is the only operation method available. I'm not saying this kind of design to be incorporated directly, but I think the 4 way button bar is easy to organize different operations in one screen.

houqp commented 11 years ago

@dracodoc , gesture will definitely make selection faster and I would really like to have that feature. It is not easy to recognize gesture accurately and efficiently though.

as for blitDithered, yo, I remembered that @hwhw mentioned it in mobileread before, it should be a killing feature :)

dracodoc commented 11 years ago

Firefox have lots of gesture extensions, I'd guess they will not be too complex if you limit the gesture to certain stroke combinations, i.e. only UP, Down, Left, Right are available, thus the gesture recognition should be relatively easy and it will be more tolerant of errors.

Of course the possible short stroke combinations of Left Right UP Down is limited, though combined with menu it should cover all the shortcuts KPV need.

houqp commented 11 years ago

Yeah, I think eventually we will make it. just not sure when ;p