Make plugin
importable
Don't start the web server if imported not from inside Anki Make sure Anki Connect instance is not garbage collected. This kills the timer that's responsible for the web server.
This commit is contained in:
parent
d6061affad
commit
748310def4
@ -58,14 +58,19 @@ class AnkiConnect:
|
||||
|
||||
def __init__(self):
|
||||
self.log = None
|
||||
self.timer = None
|
||||
self.server = web.WebServer(self.handler)
|
||||
|
||||
def initLogging(self):
|
||||
logPath = util.setting('apiLogPath')
|
||||
if logPath is not None:
|
||||
self.log = open(logPath, 'w')
|
||||
|
||||
def startWebServer(self):
|
||||
try:
|
||||
self.server = web.WebServer(self.handler)
|
||||
self.server.listen()
|
||||
|
||||
# only keep reference to prevent garbage collection
|
||||
self.timer = QTimer()
|
||||
self.timer.timeout.connect(self.advance)
|
||||
self.timer.start(util.setting('apiPollInterval'))
|
||||
@ -1698,4 +1703,9 @@ class AnkiConnect:
|
||||
# Entry
|
||||
#
|
||||
|
||||
# when run inside Anki, `__name__` would be either numeric,
|
||||
# or, if installed via `link.sh`, `AnkiConnectDev`
|
||||
if __name__ != "plugin":
|
||||
ac = AnkiConnect()
|
||||
ac.initLogging()
|
||||
ac.startWebServer()
|
||||
|
Loading…
Reference in New Issue
Block a user