Verified Commit 3c46d497 authored by mathieui's avatar mathieui

Minor fixes to the certificate warning prompt (#2949)

- slightly lower the CPU usage (callback instead of active waiting w/ sleep)
- make the terminal beep so the user knows something happened
- prevent the user “escaping” the prompt by pressing /, s, or S
parent 0a7b4360
......@@ -1196,20 +1196,7 @@ def validate_ssl(self, pem):
self.information('New certificate found (sha-2 hash:'
' %s)\nPlease validate or abort' % sha2_found_cert,
'Warning')
input = windows.YesNoInput(text="WARNING! Server certificate has changed, accept? (y/n)")
self.current_tab().input = input
input.resize(1, self.current_tab().width, self.current_tab().height-1, 0)
input.refresh()
self.doupdate()
old_loop = asyncio.get_event_loop()
new_loop = asyncio.new_event_loop()
asyncio.set_event_loop(new_loop)
new_loop.add_reader(sys.stdin, self.on_input_readable)
future = asyncio.Future()
@asyncio.coroutine
def check_input(future):
while input.value is None:
yield from asyncio.sleep(0.01)
def check_input():
self.current_tab().input = saved_input
self.paused = False
if input.value:
......@@ -1222,10 +1209,17 @@ def validate_ssl(self, pem):
self.disconnect()
new_loop.stop()
asyncio.set_event_loop(old_loop)
asyncio.async(check_input(future))
input = windows.YesNoInput(text="WARNING! Server certificate has changed, accept? (y/n)", callback=check_input)
self.current_tab().input = input
input.resize(1, self.current_tab().width, self.current_tab().height-1, 0)
input.refresh()
self.doupdate()
old_loop = asyncio.get_event_loop()
new_loop = asyncio.new_event_loop()
asyncio.set_event_loop(new_loop)
new_loop.add_reader(sys.stdin, self.on_input_readable)
curses.beep()
new_loop.run_forever()
else:
log.debug('First time. Setting certificate to %s', sha2_found_cert)
if not config.silent_set('certificate', sha2_found_cert):
......
......@@ -1012,6 +1012,8 @@ class RosterInfoTab(Tab):
"""
'/' is pressed, we enter "input mode"
"""
if isinstance(self.input, windows.YesNoInput):
return
curses.curs_set(1)
self.input = windows.CommandInput("", self.reset_help_message, self.execute_slash_command)
self.input.resize(1, self.width, self.height-1, 0)
......@@ -1187,6 +1189,8 @@ class RosterInfoTab(Tab):
Start the search. The input should appear with a short instruction
in it.
"""
if isinstance(self.input, windows.YesNoInput):
return
curses.curs_set(1)
self.input = windows.CommandInput("[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter)
self.input.resize(1, self.width, self.height-1, 0)
......@@ -1197,6 +1201,8 @@ class RosterInfoTab(Tab):
@refresh_wrapper.always
def start_search_slow(self):
if isinstance(self.input, windows.YesNoInput):
return
curses.curs_set(1)
self.input = windows.CommandInput("[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter_slow)
self.input.resize(1, self.width, self.height-1, 0)
......
......@@ -41,7 +41,7 @@ class YesNoInput(Win):
A Window just displaying a Yes/No input
Used to ask a confirmation
"""
def __init__(self, text=''):
def __init__(self, text='', callback=None):
Win.__init__(self)
self.key_func = {
'y' : self.on_yes,
......@@ -49,6 +49,7 @@ class YesNoInput(Win):
}
self.txt = text
self.value = None
self.callback = callback
def on_yes(self):
self.value = True
......@@ -68,6 +69,8 @@ class YesNoInput(Win):
def do_command(self, key, raw=False):
if key.lower() in self.key_func:
self.key_func[key]()
if self.value is not None and self.callback is not None:
return self.callback()
def on_delete(self):
return
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment