Make hostNum empty when changing sync server

Should fix an error encountered when the user used AnkiWeb in the
past and receives a JSON decode error because an unrecognized
endpoint (/[somenumber]sync instead of /sync) doesn't return what
the client expects.

Closes #10, fixes #8.
This commit is contained in:
flan 2018-12-24 16:04:26 +01:00
parent 32a81dc028
commit 360b2d08ed
2 changed files with 12 additions and 4 deletions

View File

@ -58,10 +58,13 @@ Create a new directory in `~/Anki/addons21` (name it something like ankisyncd),
create a file named `__init__.py` containing the code below and put it in
`~/Anki/addons21/ankisyncd`.
import anki.sync
import anki.sync, anki.hooks, aqt
addr = "http://127.0.0.1:27701/" # put your server address here
anki.sync.SYNC_BASE = addr + "%s"
def resetHostNum():
aqt.mw.pm.profile['hostNum'] = None
anki.hooks.addHook("profileLoaded", resetHostNum)
### Anki 2.0

View File

@ -1,6 +1,6 @@
from PyQt5.Qt import Qt, QCheckBox, QLabel, QHBoxLayout, QLineEdit
from aqt.forms import preferences
from anki.hooks import wrap
from anki.hooks import wrap, addHook
import aqt
import anki.consts
import anki.sync
@ -8,6 +8,8 @@ import anki.sync
DEFAULT_ADDR = "http://localhost:27701/"
config = aqt.mw.addonManager.getConfig(__name__)
# TODO: force the user to log out before changing any of the settings
def addui(self, _):
self = self.form
parent_w = self.tab_2
@ -43,7 +45,7 @@ def updateserver(self, text):
if config['enabled']:
addr = text or self.customServerAddr.placeholderText()
config['addr'] = addr
anki.sync.SYNC_BASE = addr + "%s"
setserver()
else:
anki.sync.SYNC_BASE = anki.consts.SYNC_BASE
aqt.mw.addonManager.writeConfig(__name__, config)
@ -52,6 +54,9 @@ def updateui(self, state):
self.serverAddrLabel.setEnabled(state == Qt.Checked)
self.customServerAddr.setEnabled(state == Qt.Checked)
if config['enabled']:
def setserver():
aqt.mw.pm.profile['hostNum'] = None
anki.sync.SYNC_BASE = config['addr'] + "%s"
addHook("profileLoaded", setserver)
aqt.preferences.Preferences.__init__ = wrap(aqt.preferences.Preferences.__init__, addui, "after")