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 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

View File

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

View File

@ -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)

View File

@ -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)