diff --git a/README.md b/README.md index cd86d2b..9b15eea 100644 --- a/README.md +++ b/README.md @@ -1230,6 +1230,26 @@ corresponding to when the API was available for use. } ``` +* **guiCheckDatabase** + + Requests a database check, but returns immediately without waiting for the check to complete. Therefore, the action will always return `true` even if errors are detected during the database check. + + *Sample request*: + ```json + { + "action": "guiCheckDatabase", + "version": 6 + } + ``` + + *Sample result*: + ```json + { + "result": true, + "error": null + } + ``` + #### Media Actions * **storeMediaFile** diff --git a/plugin/__init__.py b/plugin/__init__.py index 5c37f65..36ce781 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -363,7 +363,7 @@ class AnkiConnect: return { "permission": "denied", } - + msg = QMessageBox(None) msg.setWindowTitle("A website want to access to Anki") msg.setText(origin + " request permission to use Anki through AnkiConnect.\nDo you want to give it access ?") @@ -550,12 +550,13 @@ class AnkiConnect: config['id'] = str(config['id']) config['mod'] = anki.utils.intTime() config['usn'] = collection.usn() - - if config['id'] not in collection.decks.dconf: + if int(config['id']) not in [c['id'] for c in collection.decks.all_config()]: + return False + try: + collection.decks.save(config) + collection.decks.updateConf(config) + except: return False - - collection.decks.dconf[config['id']] = config - collection.decks.changed = True return True @@ -1088,14 +1089,14 @@ class AnkiConnect: checkForText = False if css and findText in model['css']: checkForText = True - model['css'] = model['css'].replace(findText, replaceText) + model['css'] = model['css'].replace(findText, replaceText) for tmpls in model.get('tmpls'): if front and findText in tmpls['qfmt']: checkForText = True tmpls['qfmt'] = tmpls['qfmt'].replace(findText, replaceText) if back and findText in tmpls['afmt']: checkForText = True - tmpls['afmt'] = tmpls['afmt'].replace(findText, replaceText) + tmpls['afmt'] = tmpls['afmt'].replace(findText, replaceText) self.collection().models.save(model, True) self.collection().models.flush() if checkForText: @@ -1188,7 +1189,7 @@ class AnkiConnect: scids = anki.utils.ids2str(cards) self.collection().db.execute('update cards set type=3, queue=1 where id in ' + scids) self.stopEditing() - + @util.api() def cardReviews(self, deck, startID): @@ -1595,6 +1596,12 @@ class AnkiConnect: timer.start(1000) # 1s should be enough to allow the response to be sent. + @util.api() + def guiCheckDatabase(self): + self.window().onCheckDB() + return True + + @util.api() def addNotes(self, notes): results = [] diff --git a/tests/test_graphical.py b/tests/test_graphical.py index e95a9a8..033e920 100755 --- a/tests/test_graphical.py +++ b/tests/test_graphical.py @@ -62,6 +62,9 @@ class TestGui(unittest.TestCase): # guiDeckBrowser util.invoke('guiDeckBrowser') + # guiDatabaseCheck + util.invoke('guiDatabaseCheck') + # guiExitAnki # util.invoke('guiExitAnki')