koreader / contrib

Collection of non-official plugins designed for KOReader
GNU Affero General Public License v3.0
36 stars 8 forks source link

Flashcard plugin #12

Closed EyalGol closed 2 years ago

EyalGol commented 2 years ago

This change is Reviewable

EyalGol commented 2 years ago

@Frenzie @offset-torque

EyalGol commented 2 years ago

There is currently a bug I don't understand, it corrupts books. After viewing highlights from a book the book becomes unreadable.

Not sure how something like this can happen I'm not touching books at all, I'm only reading metadata. I'll look into the Parser, maybe it does something.

Also, I guess I can save my data as part of the book's metadata my database is very redundant altho it makes my life easy.

Frenzie commented 2 years ago

I don't have time to look into that right now. Corrupts the book in which way? Are you accidentally overwriting them with your own metadata or something?

EyalGol commented 2 years ago

I don't have time to look into that right now. Corrupts the book in which way? Are you accidentally overwriting them with your own metadata or something?

Well the book opens, it shows 1/0 pages and the screen is black, that's it. After a bit of testing its either in the FlashcardDB or the Parser as it happens within the init of the plugin. Imma try to narrow it down to either one and go from there. Do you have an idea what could cause this type of corruption?

Frenzie commented 2 years ago

Did you write this on Windows by any chance?

01/28/22-18:24:04 WARN  Error when loading plugins/flashcard.koplugin/main.lua plugins/flashcard.koplugin/main.lua:5: module 'flashcardwidget' not found:
        no field package.preload['flashcardwidget']
        no file 'plugins/flashcard.koplugin/flashcardwidget.lua'
        no file 'common/flashcardwidget.lua'
        no file 'rocks/share/lua/5.1/flashcardwidget.lua'
        no file 'frontend/flashcardwidget.lua'
        no file './flashcardwidget.lua'
        no file '/usr/local/share/luajit-2.1.0-beta3/flashcardwidget.lua'
        no file '/usr/local/share/lua/5.1/flashcardwidget.lua'
        no file '/usr/local/share/lua/5.1/flashcardwidget/init.lua'
        no file 'plugins/flashcard.koplugin/lib/flashcardwidget.so'
        no file 'common/flashcardwidget.so'
        no file 'common/flashcardwidget.dll'
        no file '/usr/lib/lua/flashcardwidget.so'
        no file 'rocks/lib/lua/5.1/flashcardwidget.so'
        no file './flashcardwidget.so'
        no file '/usr/local/lib/lua/5.1/flashcardwidget.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'

Fixing the filename by making them lowercase makes it load a little further:

01/28/22-18:26:32 WARN  Error when loading plugins/flashcard.koplugin/main.lua ./datastorage.lua:49: attempt to index local 'self' (a nil value)
EyalGol commented 2 years ago

Did you write this on Windows by any chance?

01/28/22-18:24:04 WARN  Error when loading plugins/flashcard.koplugin/main.lua plugins/flashcard.koplugin/main.lua:5: module 'flashcardwidget' not found:
        no field package.preload['flashcardwidget']
        no file 'plugins/flashcard.koplugin/flashcardwidget.lua'
        no file 'common/flashcardwidget.lua'
        no file 'rocks/share/lua/5.1/flashcardwidget.lua'
        no file 'frontend/flashcardwidget.lua'
        no file './flashcardwidget.lua'
        no file '/usr/local/share/luajit-2.1.0-beta3/flashcardwidget.lua'
        no file '/usr/local/share/lua/5.1/flashcardwidget.lua'
        no file '/usr/local/share/lua/5.1/flashcardwidget/init.lua'
        no file 'plugins/flashcard.koplugin/lib/flashcardwidget.so'
        no file 'common/flashcardwidget.so'
        no file 'common/flashcardwidget.dll'
        no file '/usr/lib/lua/flashcardwidget.so'
        no file 'rocks/lib/lua/5.1/flashcardwidget.so'
        no file './flashcardwidget.so'
        no file '/usr/local/lib/lua/5.1/flashcardwidget.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'

Fixing the filename by making them lowercase makes it load a little further:

01/28/22-18:26:32 WARN  Error when loading plugins/flashcard.koplugin/main.lua ./datastorage.lua:49: attempt to index local 'self' (a nil value)

I did write it on windows, but it loads just fine for me. but it does load on my ereader, is there a known issue with development on windows?

Frenzie commented 2 years ago

I did write it on windows, but it loads just fine for me. but it does load on my ereader, is there a known issue with development on windows?

Filenames are case sensitive on *nix. I think DOS/Windows takes a more sensible approach really, but in any case that's how it is.

The ereader in question probably uses a FAT32 partition so it can be mounted via USB on any system.

EyalGol commented 2 years ago
01/28/22-18:26:32 WARN  Error when loading plugins/flashcard.koplugin/main.lua ./datastorage.lua:49: attempt to index local 'self' (a nil value)

Okay I think I fixed it, really weird it works for me, hmmm edit: Really sorry for all of the bugs, I'm really confused how it works on my ereader :/

EyalGol commented 2 years ago

I don't have time to look into that right now. Corrupts the book in which way? Are you accidentally overwriting them with your own metadata or something?

Well the book opens, it shows 1/0 pages and the screen is black, that's it. After a bit of testing its either in the FlashcardDB or the Parser as it happens within the init of the plugin. Imma try to narrow it down to either one and go from there. Do you have an idea what could cause this type of corruption?

Just opening and closing a book with my plugin loaded it was corrupt, not running it, no restart, just like that. edit: looking at the log I think I know what's going on, does the init function run every time I enter or exit a book? edit: now I know it's the highlightparser.lua, specifically somewhere along the flow of Parser:parseHistory, after commenting it out books stopped getting corrupted.... well that sucks didn't write that code, and now it's time to rewrite it...

EyalGol commented 2 years ago

So with my new knowledge, I made a few changes xD Now it's just one file and I like it a lot more, I use the docsettings of every book to store my metadata, I store it under flashcard_data on each highlight. and I'm using TextView now.

The only thing I would like to change is:

edit: Thanks for the help along the way, really amazing

pazos commented 2 years ago

@EyalGol

is there a known issue with development on windows?

Not at all!. But it is recommended to use the emulator. It promotes mental health :)

You can run it on Windows 10/11 using WSL. See https://github.com/koreader/koreader/blob/master/doc/Building.md

EyalGol commented 2 years ago

Not at all!. But it is recommended to use the emulator. It promotes mental health :)

You can run it on Windows 10/11 using WSL. See https://github.com/koreader/koreader/blob/master/doc/Building.md

Cool 😊 Well, I wanted to use the emulator but honestly, I just got lazy. The fact that you have a docker is amazing tho

It was a nice experience developing this plugin, getting to know and hate lua, and getting into koreader's framework a bit. if I'll ever contribute something to the main repo I feel that I'll be somewhat competent now hahaha

Frenzie commented 2 years ago

@EyalGol If you let me know when you're done I'll squash & merge through the GH web interface. It looks done to me, but I think the question of which menu to put it in is perhaps still open.

EyalGol commented 2 years ago

@Frenzie You can merge it. Squish it, 80% of the commits are irrelevant anyway and one commit that I made from my phone has a typo :D