Urwid bug mitigation

This commit is contained in:
Mark Qvist 2021-11-05 10:59:51 +01:00
parent fe0a3b6a3e
commit 1c1ddab28f
4 changed files with 30 additions and 4 deletions

View File

@ -1,8 +1,10 @@
import os import os
import io
import sys import sys
import time import time
import atexit import atexit
import traceback import traceback
import contextlib
import RNS import RNS
import LXMF import LXMF
@ -59,6 +61,7 @@ class NomadNetworkApp:
self.configpath = self.configdir+"/config" self.configpath = self.configdir+"/config"
self.logfilepath = self.configdir+"/logfile" self.logfilepath = self.configdir+"/logfile"
self.errorfilepath = self.configdir+"/errors"
self.storagepath = self.configdir+"/storage" self.storagepath = self.configdir+"/storage"
self.identitypath = self.configdir+"/storage/identity" self.identitypath = self.configdir+"/storage/identity"
self.cachepath = self.configdir+"/storage/cache" self.cachepath = self.configdir+"/storage/cache"
@ -210,7 +213,26 @@ class NomadNetworkApp:
atexit.register(self.exit_handler) atexit.register(self.exit_handler)
sys.excepthook = self.exception_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): def set_display_name(self, display_name):
self.peer_settings["display_name"] = display_name self.peer_settings["display_name"] = display_name

View File

@ -2,6 +2,7 @@
from ._version import __version__ from ._version import __version__
import io
import argparse import argparse
import nomadnet import nomadnet

View File

@ -125,7 +125,8 @@ class MainDisplay():
def update_active_sub_display(self): def update_active_sub_display(self):
self.frame.contents["body"] = (self.sub_displays.active().widget, None) self.frame.contents["body"] = (self.sub_displays.active().widget, None)
self.update_active_shortcuts() 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): def update_active_shortcuts(self):
self.frame.contents["footer"] = (self.sub_displays.active().shortcuts().widget, None) self.frame.contents["footer"] = (self.sub_displays.active().shortcuts().widget, None)

View File

@ -107,7 +107,8 @@ class AnnounceInfo(urwid.WidgetWrap):
self.parent.left_pile.contents[0] = (self.parent.announce_stream_display, options) self.parent.left_pile.contents[0] = (self.parent.announce_stream_display, options)
def connect(sender): 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)) self.parent.browser.retrieve_url(RNS.hexrep(source_hash, delimit=False))
show_announce_stream(None) show_announce_stream(None)
@ -434,7 +435,8 @@ class KnownNodeInfo(urwid.WidgetWrap):
self.parent.left_pile.contents[0] = (self.parent.known_nodes_display, options) self.parent.left_pile.contents[0] = (self.parent.known_nodes_display, options)
def connect(sender): 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)) self.parent.browser.retrieve_url(RNS.hexrep(source_hash, delimit=False))
show_known_nodes(None) show_known_nodes(None)