Ajatt-Tools / anki.koplugin

KOReader plugin enabling Anki card generations for words looked up in the internal dictionary.
49 stars 6 forks source link

Crashing when creating a card #2

Closed it0na72 closed 1 year ago

it0na72 commented 1 year ago

Hello, thank you for this plugin! It's definitely something i've been looking for for a while. I managed to install this plugin accordingly and edited the fields to match my own deck on Anki. However, when I click on "Add to anki", this gives me an error posted below. I also have my wifi connected + ssh server on whilst adding.

PXL_20230329_160433557 PXL_20230329_174914456_2

Wondering if this is something I messed up during installation.

nairyosangha commented 1 year ago

Looks like it went wrong before it even got to sending your note to anki

attempt to index field 'deckName' (a nil value)

This should not be nil, it gets this deckName from id field for each config option in ankidefaults.lua:

    AnkiConfigOpt:new {
        id = "deckName",
        group = general_settings,
        name = "Anki Deckname",
        description = "The name of the deck the new notes should be added to.",
        default = "日本::3 - Mining Deck",
    },

did you edit the the id field as well as the default field?

it0na72 commented 1 year ago

did you edit the id field as well as the default field?

Yes, I did. You can see how I edited this below (hopefully this is edited correctly): Anki Default file xp34y87geM

yylOCCJp83

And my Anki fields D8Qr8Ll1dj

I also tried not changing these values, and only editing the fields inside Koreader, with no luck.

nairyosangha commented 1 year ago

the id field is used to refer to whatever your deck name is in the code, you shouldn't edit that, if you change those back, and just change default to your actual deck name, it should work (hopefully). Same for all the other options as well ofc

nairyosangha commented 1 year ago

Was a bit worried for a sec that it would fail on those options which you did not edit (since you don't care about them I guess), like notes and the pitch stuff, but it looks like ankiconnect just ignores these :relieved:

it0na72 commented 1 year ago

the id field is used to refer to whatever your deck name is in the code, you shouldn't edit that, if you change those back, and just change default to your actual deck name, it should work (hopefully). Same for all the other options as well ofc

This did wonders. Thank you for taking the time to reply. However now, I get a different error related with anki connect: "Synchronizing failed! Unable to reach AnkiConnect, timeout".

What I have tried:

My anki connect settings: B7fwRQYtMI

nairyosangha commented 1 year ago

both localhost and 127.0.0.1 are referring to the IP address of your e-reader itself. I'm assuming you're not running anki on the reader itself (is that even possible? :), so you probably want to put the IP address of your PC instead.

You'll also need to make sure your firewall actually allows connections through on port 8765

nairyosangha commented 1 year ago

By the way, there's a terminal emulator built-in in Koreader (under settings - page 2 - more tools) which is a pretty convenient way to troubleshoot

image You should see the AnkiConnect v6 thingy pop up

(localhost only works for me here because I'm actually running koreader on my pc where anki runs as well)

it0na72 commented 1 year ago

Got it solved. On windows, you'll need to change it to your ipv4 address. Therefore, just go on CMD, type ipconfig and just use your ip4address and it works with no problem at all. Just wish the handlebars were slightly better but this works wonders.

Thank you once again for your help!

nairyosangha commented 1 year ago

No worries man, I'm glad someone's actually using this. Feel free to reach out again if you have more questions

it0na72 commented 1 year ago

Hey, hope you're doing well. Instead of opening another issue I just wanted to ask here for clarity reasons. ls there any way to edit the script to change how the cards are displayed on anki? Eg: All cards I import have the layout aligned to the left and I was just wondering if there's a way to edit the script and change it to the center so it's easier to edit when on the computer.

I tried looking at the scripting and editing some lines but nothing ended up working.

EDIT: ignore this. found the other file called anki note 🤦

nairyosangha commented 1 year ago

You are referring to the hardcoded left align here I assume? https://github.com/Ajatt-Tools/anki.koplugin/blob/b1b19d3eda7de13707f3adeaa7f972d21f840d41/ankinote.lua#L25

The layout of the card should really be the responsibility of the note type, so instead of hardcoding this here, I could give it a class="definition" instead, and then you can style that on your card's CSS, would that be better?

it0na72 commented 1 year ago

That would be perfect. I found it strange that it wasn't recognizing my CSS styling but this would make it even better. Sorry for the delay replying

nairyosangha commented 1 year ago

That would be perfect. I found it strange that it wasn't recognizing my CSS styling but this would make it even better. Sorry for the delay replying

no worries, fixed in https://github.com/Ajatt-Tools/anki.koplugin/commit/eeb86e02eacd6c8e0109ac02ab23d738ebddf189