Skip to content
Snippets Groups Projects
Commit a15aa17a authored by Nico's avatar Nico
Browse files

Switch to http polling for startup detection

Reading Briar's output isn't much reliable.
parent 9d8dbb88
No related branches found
No related tags found
Loading
......@@ -4,15 +4,17 @@
from subprocess import Popen, PIPE, STDOUT
from threading import Thread
from time import sleep
from urllib.error import HTTPError, URLError
from urllib.request import urlopen
class Api:
_process = None
def __init__(self, headless_jar, debug=False):
self._command = ['java', '-jar', headless_jar, '-v']
self._debug = debug
def __init__(self, headless_jar):
self._command = ['java', '-jar', headless_jar]
def has_account(self):
from pathlib import Path
......@@ -52,13 +54,17 @@ class Api:
watch_thread.start()
def _watch_thread(self, callback):
for line in self._process.stdout:
if self._debug:
print(line.decode("utf-8"), end='', flush=True)
# TODO: Sometimes we miss this line (or Briar doesn't send it?)
if "Listening on http://localhost:7000/" in line.decode("utf-8"):
callback(True)
return
while self.is_running():
try:
sleep(0.1)
print(urlopen("http://localhost:7000/").getcode())
except HTTPError as e:
if(e.code == 404):
callback(True)
return
except URLError as e:
if not isinstance(e.reason, ConnectionRefusedError):
raise e
callback(False)
def _login(self, password):
......
......@@ -35,8 +35,7 @@ class Application(Gtk.Application):
styleContext.add_provider_for_screen(screen, cssProvider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
self.debug = True # TODO: Change this in production
self.api = Api('/app/briar/briar-headless.jar', self.debug)
self.api = Api('/app/briar/briar-headless.jar')
def do_activate(self):
if self.window is None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment