diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py index 42e1d91..c8630a7 100644 --- a/nomadnet/NomadNetworkApp.py +++ b/nomadnet/NomadNetworkApp.py @@ -1,8 +1,10 @@ import os +import io import sys import time import atexit import traceback +import contextlib import RNS import LXMF @@ -59,6 +61,7 @@ class NomadNetworkApp: self.configpath = self.configdir+"/config" self.logfilepath = self.configdir+"/logfile" + self.errorfilepath = self.configdir+"/errors" self.storagepath = self.configdir+"/storage" self.identitypath = self.configdir+"/storage/identity" self.cachepath = self.configdir+"/storage/cache" @@ -210,7 +213,26 @@ class NomadNetworkApp: atexit.register(self.exit_handler) sys.excepthook = self.exception_handler - nomadnet.ui.spawn(self.uimode) + # This stderr redirect is needed to stop urwid + # from spewing KeyErrors to the console and thus, + # messing up the UI. A pull request to fix the + # bug in urwid was submitted, but until it is + # merged, this hack will mitigate it. + strio = io.StringIO() + with contextlib.redirect_stderr(strio): + nomadnet.ui.spawn(self.uimode) + + if strio.tell() > 0: + try: + strio.seek(0) + err_file = open(self.errorfilepath, "w") + err_file.write(strio.read()) + err_file.close() + + except Exception as e: + RNS.log("Could not write stderr output to error log file at "+str(self.errorfilepath)+".", RNS.LOG_ERROR) + RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR) + def set_display_name(self, display_name): self.peer_settings["display_name"] = display_name diff --git a/nomadnet/nomadnet.py b/nomadnet/nomadnet.py index 2ee25de..5cc69a3 100644 --- a/nomadnet/nomadnet.py +++ b/nomadnet/nomadnet.py @@ -2,6 +2,7 @@ from ._version import __version__ +import io import argparse import nomadnet diff --git a/nomadnet/ui/textui/Main.py b/nomadnet/ui/textui/Main.py index 68e7235..22445da 100644 --- a/nomadnet/ui/textui/Main.py +++ b/nomadnet/ui/textui/Main.py @@ -125,7 +125,8 @@ class MainDisplay(): def update_active_sub_display(self): self.frame.contents["body"] = (self.sub_displays.active().widget, None) self.update_active_shortcuts() - self.app.ui.main_display.request_redraw(extra_delay=0.0) + # TODO: Remove when new mitigation has been tested + # self.app.ui.main_display.request_redraw(extra_delay=0.0) def update_active_shortcuts(self): self.frame.contents["footer"] = (self.sub_displays.active().shortcuts().widget, None) diff --git a/nomadnet/ui/textui/Network.py b/nomadnet/ui/textui/Network.py index 615cdf6..6073e1f 100644 --- a/nomadnet/ui/textui/Network.py +++ b/nomadnet/ui/textui/Network.py @@ -107,7 +107,8 @@ class AnnounceInfo(urwid.WidgetWrap): self.parent.left_pile.contents[0] = (self.parent.announce_stream_display, options) def connect(sender): - self.app.ui.main_display.request_redraw(extra_delay=0.15) + # TODO: Remove when new mitigation has been tested + # self.app.ui.main_display.request_redraw(extra_delay=0.75) self.parent.browser.retrieve_url(RNS.hexrep(source_hash, delimit=False)) show_announce_stream(None) @@ -434,7 +435,8 @@ class KnownNodeInfo(urwid.WidgetWrap): self.parent.left_pile.contents[0] = (self.parent.known_nodes_display, options) def connect(sender): - self.app.ui.main_display.request_redraw(extra_delay=0.15) + # TODO: Remove when new mitigation has been tested + # self.app.ui.main_display.request_redraw(extra_delay=0.75) self.parent.browser.retrieve_url(RNS.hexrep(source_hash, delimit=False)) show_known_nodes(None)