summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/commands.py6
-rw-r--r--src/core/core.py19
-rw-r--r--src/core/handlers.py4
3 files changed, 17 insertions, 12 deletions
diff --git a/src/core/commands.py b/src/core/commands.py
index 1713c0f1..c7d900c3 100644
--- a/src/core/commands.py
+++ b/src/core/commands.py
@@ -807,6 +807,9 @@ def command_quit(self, arg=''):
"""
/quit
"""
+ if not self.xmpp.is_connected():
+ self.exit()
+ return
if len(arg.strip()) != 0:
msg = arg
else:
@@ -820,8 +823,7 @@ def command_quit(self, arg=''):
self.save_config()
self.plugin_manager.disable_plugins()
self.disconnect(msg)
- self.running = False
- self.reset_curses()
+ self.xmpp.add_event_handler("disconnected", self.exit, disposable=True)
def command_destroy_room(self, arg=''):
"""
diff --git a/src/core/core.py b/src/core/core.py
index 42d8df31..feccd01c 100644
--- a/src/core/core.py
+++ b/src/core/core.py
@@ -9,6 +9,7 @@ import logging
log = logging.getLogger(__name__)
+import asyncio
import collections
import curses
import os
@@ -189,6 +190,7 @@ class Core(object):
# Add handlers
self.xmpp.add_event_handler('connected', self.on_connected)
+ self.xmpp.add_event_handler('connection_failed', self.on_failed_connection)
self.xmpp.add_event_handler('disconnected', self.on_disconnected)
self.xmpp.add_event_handler('failed_auth', self.on_failed_auth)
self.xmpp.add_event_handler('no_auth', self.on_no_auth)
@@ -427,13 +429,8 @@ class Core(object):
if config.get('enable_user_gaming', True):
self.xmpp.plugin['xep_0196'].stop(block=False)
self.plugin_manager.disable_plugins()
- self.disconnect('')
- self.running = False
- try:
- self.reset_curses()
- except: # too bad
- pass
- sys.exit()
+ self.disconnect('%s received' % signals.get(sig))
+ self.xmpp.add_event_handler("disconnected", self.exit, disposable=True)
def autoload_plugins(self):
"""
@@ -470,6 +467,10 @@ class Core(object):
self.refresh_window()
self.xmpp.plugin['xep_0012'].begin_idle(jid=self.xmpp.boundjid)
+ def exit(self, event=None):
+ log.debug("exit(%s)" % (event,))
+ asyncio.get_event_loop().stop()
+
def on_exception(self, typ, value, trace):
"""
When an exception is raised, just reset curses and call
@@ -786,7 +787,9 @@ class Core(object):
tab.command_part(msg)
self.xmpp.disconnect()
if reconnect:
- self.xmpp.start()
+ # Add a one-time event to reconnect as soon as we are
+ # effectively disconnected
+ self.xmpp.add_event_handler('disconnected', lambda event: self.xmpp.connect(), disposable=True)
def send_message(self, msg):
"""
diff --git a/src/core/handlers.py b/src/core/handlers.py
index 92533d63..94a0614b 100644
--- a/src/core/handlers.py
+++ b/src/core/handlers.py
@@ -812,11 +812,11 @@ def on_groupchat_presence(self, presence):
### Connection-related handlers ###
-def on_failed_connection(self):
+def on_failed_connection(self, error):
"""
We cannot contact the remote server
"""
- self.information(_("Connection to remote server failed"), _('Error'))
+ self.information(_("Connection to remote server failed: %s" % (error,)), _('Error'))
def on_disconnected(self, event):
"""