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:
parent
32a81dc028
commit
360b2d08ed
@ -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
|
create a file named `__init__.py` containing the code below and put it in
|
||||||
`~/Anki/addons21/ankisyncd`.
|
`~/Anki/addons21/ankisyncd`.
|
||||||
|
|
||||||
import anki.sync
|
import anki.sync, anki.hooks, aqt
|
||||||
|
|
||||||
addr = "http://127.0.0.1:27701/" # put your server address here
|
addr = "http://127.0.0.1:27701/" # put your server address here
|
||||||
anki.sync.SYNC_BASE = addr + "%s"
|
anki.sync.SYNC_BASE = addr + "%s"
|
||||||
|
def resetHostNum():
|
||||||
|
aqt.mw.pm.profile['hostNum'] = None
|
||||||
|
anki.hooks.addHook("profileLoaded", resetHostNum)
|
||||||
|
|
||||||
### Anki 2.0
|
### Anki 2.0
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
from PyQt5.Qt import Qt, QCheckBox, QLabel, QHBoxLayout, QLineEdit
|
from PyQt5.Qt import Qt, QCheckBox, QLabel, QHBoxLayout, QLineEdit
|
||||||
from aqt.forms import preferences
|
from aqt.forms import preferences
|
||||||
from anki.hooks import wrap
|
from anki.hooks import wrap, addHook
|
||||||
import aqt
|
import aqt
|
||||||
import anki.consts
|
import anki.consts
|
||||||
import anki.sync
|
import anki.sync
|
||||||
@ -8,6 +8,8 @@ import anki.sync
|
|||||||
DEFAULT_ADDR = "http://localhost:27701/"
|
DEFAULT_ADDR = "http://localhost:27701/"
|
||||||
config = aqt.mw.addonManager.getConfig(__name__)
|
config = aqt.mw.addonManager.getConfig(__name__)
|
||||||
|
|
||||||
|
# TODO: force the user to log out before changing any of the settings
|
||||||
|
|
||||||
def addui(self, _):
|
def addui(self, _):
|
||||||
self = self.form
|
self = self.form
|
||||||
parent_w = self.tab_2
|
parent_w = self.tab_2
|
||||||
@ -43,7 +45,7 @@ def updateserver(self, text):
|
|||||||
if config['enabled']:
|
if config['enabled']:
|
||||||
addr = text or self.customServerAddr.placeholderText()
|
addr = text or self.customServerAddr.placeholderText()
|
||||||
config['addr'] = addr
|
config['addr'] = addr
|
||||||
anki.sync.SYNC_BASE = addr + "%s"
|
setserver()
|
||||||
else:
|
else:
|
||||||
anki.sync.SYNC_BASE = anki.consts.SYNC_BASE
|
anki.sync.SYNC_BASE = anki.consts.SYNC_BASE
|
||||||
aqt.mw.addonManager.writeConfig(__name__, config)
|
aqt.mw.addonManager.writeConfig(__name__, config)
|
||||||
@ -52,6 +54,9 @@ def updateui(self, state):
|
|||||||
self.serverAddrLabel.setEnabled(state == Qt.Checked)
|
self.serverAddrLabel.setEnabled(state == Qt.Checked)
|
||||||
self.customServerAddr.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"
|
anki.sync.SYNC_BASE = config['addr'] + "%s"
|
||||||
|
|
||||||
|
addHook("profileLoaded", setserver)
|
||||||
aqt.preferences.Preferences.__init__ = wrap(aqt.preferences.Preferences.__init__, addui, "after")
|
aqt.preferences.Preferences.__init__ = wrap(aqt.preferences.Preferences.__init__, addui, "after")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user