krmanik / genanki-js

A JavaScript implementation for generating Anki decks in browser client side
https://genanki.js.org
Other
55 stars 6 forks source link

Bug on importing Deck name contain `::` on AnkiDroid #4

Closed drquochoai closed 3 years ago

drquochoai commented 3 years ago

I want to create a subdeck so I create Deck name "Language::English" On Desktop every thing go well But on Ankidroid, the error appear Attempt to invoke virtual method 'java.lang.String com.ichi2.utils.JSON Object.getString(java.lang.Stringy on a null object reference Process stop at this step Image of error

krmanik commented 3 years ago

I have created an issue in AnkiDroid. I will inspect it for the possible cause. In next update it will be resolved.

krmanik commented 3 years ago

The name is inserted here package.js #L62 package.js #L77 package.js #L83

krmanik commented 3 years ago

This is bug of AnkiDroid and it will be fixed soon. So, in meantime use deck only avoid creating subdeck. I will update this issues when the bug fixed in AnkiDroid.

drquochoai commented 3 years ago

The name is inserted here package.js #L62 package.js #L77 package.js #L83

Do we have any temp solution now, when I create decks with multiple subdecks on genanki (python), the AnkiDroid works well without any error.

krmanik commented 3 years ago

I have extracted collection.anki2 sqlite db to text file compared the both file. It is need to inspect more.

This is collection.anki2 dump db to text for genanki python module py.txt

This is collection.anki2 dump db to text for genanki-js js.txt

The diffchecker.com can be used to find the errors. I will update it, when it is solved.

image

drquochoai commented 3 years ago

Yes, there is a default deck insert automatically by genanki.py on collection.anki2

{
    "1": {
        "collapsed": false,
        "conf": 1,
        "desc": "",
        "dyn": 0,
        "extendNew": 10,
        "extendRev": 50,
        "id": 1,
        "lrnToday": [
            0,
            0
        ],
        "mod": 1425279151,
        "name": "Default",
        "newToday": [
            0,
            0
        ],
        "revToday": [
            0,
            0
        ],
        "timeToday": [
            0,
            0
        ],
        "usn": 0
    },
    "456890768484394556": {
        "collapsed": false,
        "conf": 1,
        "desc": "T\u1ea1o b\u1edfi Tr\u1ea7n Qu\u1ed1c Ho\u00e0i with love",
        "dyn": 0,
        "extendNew": 0,
        "extendRev": 50,
        "id": 456890768484394556,
        "lrnToday": [
            163,
            2
        ],
        "mod": 1425278051,
        "name": "Book1 Test B\u00e1 \u0111\u1ea1o::A0. B\u00e0i 2 test ba \u0111\u1ea1o 2  (2)",
        "newToday": [
            163,
            2
        ],
        "revToday": [
            163,
            0
        ],
        "timeToday": [
            163,
            23598
        ],
        "usn": -1
    }
}

But with genanki-js does not

{
    "7278913211541732": {
        "newToday": [
            0,
            0
        ],
        "revToday": [
            0,
            0
        ],
        "lrnToday": [
            0,
            0
        ],
        "timeToday": [
            0,
            0
        ],
        "conf": 1,
        "usn": 0,
        "desc": "",
        "dyn": 0,
        "collapsed": false,
        "extendNew": 10,
        "extendRev": 50,
        "id": "7278913211541732",
        "name": "decknam::e"
    }
}

The different is at table col, and column decks Open with SQLiteDatabaseBrowserPortable.exe collection by genanki.js.anki2.zip collection by genanki.py.anki2.zip

Image from genanki.py collection.anki2

python

drquochoai commented 3 years ago

I have tested on AnkiMobile (iOs), apkg generated from genki-js work well. The only problem come from AnkiDroid

krmanik commented 3 years ago

Thansk for more insight. I will update it. It is helpful.

krmanik commented 3 years ago

It is fixed. I have added a default deck. Alternatively It can also be fixed by adding a deck (in previous version).

var d = new Deck(1276438724672, "Test::Deck")
var defaultDeck = new Deck(1, "Default")   // <---

d.addNote(m.note(['this is front', 'this is back']))

var p = new Package()
p.addDeck(defaultDeck)    // <---
p.addDeck(d)

p.writeToFile('deck.apkg') 

But I have added fix in current version. genanki.js#L370

drquochoai commented 3 years ago

Thank you, it work like a charm 🥰🥰