From 531fa81bba940354be317c9023c7904a194bd3d0 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 25 Aug 2018 13:31:43 +0300 Subject: [PATCH] fixed bugs with plugin reloading and toxav_kill --- toxygen/app.py | 3 ++- toxygen/av/calls.py | 8 +++----- toxygen/av/calls_manager.py | 4 ++-- toxygen/common/tox_save.py | 9 +++++++++ toxygen/middleware/threads.py | 15 ++++++++++----- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/toxygen/app.py b/toxygen/app.py index a370a91..497a460 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -107,6 +107,7 @@ class App: self._tray.hide() self._save_profile() self._settings.close() + self._calls_manager.set_toxav(None) del self._tox # ----------------------------------------------------------------------------------------------------------------- @@ -202,7 +203,7 @@ class App: def _start_threads(self, initial_start=True): # init thread - self._init = threads.InitThread(self._tox, self._plugin_loader, self._settings) + self._init = threads.InitThread(self._tox, self._plugin_loader, self._settings, initial_start) self._init.start() # starting threads for tox iterate and toxav iterate diff --git a/toxygen/av/calls.py b/toxygen/av/calls.py index 2673f1a..d5f2fe7 100644 --- a/toxygen/av/calls.py +++ b/toxygen/av/calls.py @@ -7,12 +7,13 @@ import itertools import numpy as np from av import screen_sharing from av.call import Call +import common.tox_save -class AV: +class AV(common.tox_save.ToxAvSave): def __init__(self, toxav, settings): - self._toxav = toxav + super().__init__(toxav) self._settings = settings self._running = True @@ -36,9 +37,6 @@ class AV: self._video_width = 640 self._video_height = 480 - def set_toxav(self, toxav): - self._toxav = toxav - def stop(self): self._running = False self.stop_audio_thread() diff --git a/toxygen/av/calls_manager.py b/toxygen/av/calls_manager.py index eefd03a..5a48672 100644 --- a/toxygen/av/calls_manager.py +++ b/toxygen/av/calls_manager.py @@ -8,8 +8,8 @@ import common.event as event class CallsManager: - def __init__(self, toxAV, settings, screen, contacts_manager): - self._call = av.calls.AV(toxAV, settings) # object with data about calls + def __init__(self, toxav, settings, screen, contacts_manager): + self._call = av.calls.AV(toxav, settings) # object with data about calls self._call_widgets = {} # dict of incoming call widgets self._incoming_calls = set() self._settings = settings diff --git a/toxygen/common/tox_save.py b/toxygen/common/tox_save.py index 5d4cee0..09c159b 100644 --- a/toxygen/common/tox_save.py +++ b/toxygen/common/tox_save.py @@ -7,3 +7,12 @@ class ToxSave: def set_tox(self, tox): self._tox = tox + + +class ToxAvSave: + + def __init__(self, toxav): + self._toxav = toxav + + def set_toxav(self, toxav): + self._toxav = toxav diff --git a/toxygen/middleware/threads.py b/toxygen/middleware/threads.py index 192f723..15e9665 100644 --- a/toxygen/middleware/threads.py +++ b/toxygen/middleware/threads.py @@ -38,15 +38,18 @@ class BaseQThread(QtCore.QThread): class InitThread(BaseThread): - def __init__(self, tox, plugin_loader, settings): + def __init__(self, tox, plugin_loader, settings, is_first_start): super().__init__() self._tox, self._plugin_loader, self._settings = tox, plugin_loader, settings + self._is_first_start = is_first_start def run(self): - # download list of nodes if needed - download_nodes_list(self._settings) - # start plugins - self._plugin_loader.load() + if self._is_first_start: + # download list of nodes if needed + download_nodes_list(self._settings) + # start plugins + self._plugin_loader.load() + # bootstrap try: for data in generate_nodes(): @@ -56,10 +59,12 @@ class InitThread(BaseThread): self._tox.add_tcp_relay(*data) except: pass + for _ in range(10): if self._stop_thread: return time.sleep(1) + while not self._tox.self_get_connection_status(): try: for data in generate_nodes(None):