Added guiCheckDatabase action and fix #202 in saveDeckConfig (#271)

* Added guiCheckDatabase action

This action initiates a check database action in Anki but doesn’t wait for the action to complete before returning.

* Fixed #202 no dconf attribute in saveDeckConfig

Anki manages access to deck configuration differently now. This adapts saveDeckConfig to new style of access.
This commit is contained in:
NSBum 2021-07-13 20:55:22 -04:00 committed by GitHub
parent 2150940c7e
commit 8404bd782d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 9 deletions

View File

@ -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**

View File

@ -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
@ -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 = []

View File

@ -62,6 +62,9 @@ class TestGui(unittest.TestCase):
# guiDeckBrowser
util.invoke('guiDeckBrowser')
# guiDatabaseCheck
util.invoke('guiDatabaseCheck')
# guiExitAnki
# util.invoke('guiExitAnki')