From 5f8a06443ca1ed8a53ac551fc85021bcd8b6d7da Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 3 Jan 2017 11:44:29 -0500 Subject: [PATCH 1/2] open the ui as soon as UIManager finishes setting itself up --- lbrynet/lbrynet_daemon/Daemon.py | 4 ++-- lbrynet/lbrynet_daemon/DaemonControl.py | 5 +---- lbrynet/lbrynet_daemon/DaemonServer.py | 4 ++-- lbrynet/lbrynet_daemon/UIManager.py | 7 ++++--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 0855ba334..e8e40c6cf 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -291,7 +291,7 @@ class Daemon(AuthJSONRPCServer): self.lbry_file_manager = None @defer.inlineCallbacks - def setup(self): + def setup(self, launch_ui): self._modify_loggly_formatter() def _announce_startup(): @@ -329,7 +329,7 @@ class Daemon(AuthJSONRPCServer): if conf.settings.host_ui: self.lbry_ui_manager.update_checker.start(1800, now=False) - yield self.lbry_ui_manager.setup() + yield self.lbry_ui_manager.setup(launch=launch_ui) yield self._initial_setup() yield threads.deferToThread(self._setup_data_directory) yield self._check_db_migration() diff --git a/lbrynet/lbrynet_daemon/DaemonControl.py b/lbrynet/lbrynet_daemon/DaemonControl.py index 33a8568b9..541880491 100644 --- a/lbrynet/lbrynet_daemon/DaemonControl.py +++ b/lbrynet/lbrynet_daemon/DaemonControl.py @@ -2,7 +2,6 @@ from lbrynet.core import log_support import argparse import logging.handlers -import webbrowser from twisted.internet import defer, reactor from jsonrpc.proxy import JSONRPCProxy @@ -129,9 +128,7 @@ def start_server_and_listen(launchui, use_auth, analytics_manager): log_support.configure_analytics_handler(analytics_manager) try: daemon_server = DaemonServer(analytics_manager) - yield daemon_server.start(use_auth) - if launchui: - yield webbrowser.open(conf.settings.UI_ADDRESS) + yield daemon_server.start(use_auth, launchui) analytics_manager.send_server_startup_success() except Exception as e: log.exception('Failed to startup') diff --git a/lbrynet/lbrynet_daemon/DaemonServer.py b/lbrynet/lbrynet_daemon/DaemonServer.py index 744563476..b58f9de17 100644 --- a/lbrynet/lbrynet_daemon/DaemonServer.py +++ b/lbrynet/lbrynet_daemon/DaemonServer.py @@ -43,9 +43,9 @@ class DaemonServer(object): return defer.succeed(True) @defer.inlineCallbacks - def start(self, use_auth): + def start(self, use_auth, launch_ui=False): yield self._setup_server(use_auth) - yield self._api.setup() + yield self._api.setup(launch_ui) def get_site_base(use_auth, root): diff --git a/lbrynet/lbrynet_daemon/UIManager.py b/lbrynet/lbrynet_daemon/UIManager.py index 2befcb856..2321ec2d3 100644 --- a/lbrynet/lbrynet_daemon/UIManager.py +++ b/lbrynet/lbrynet_daemon/UIManager.py @@ -2,6 +2,7 @@ import os import logging import shutil import json +import webbrowser from urllib2 import urlopen from StringIO import StringIO from zipfile import ZipFile @@ -15,8 +16,6 @@ from lbrynet.lbrynet_daemon.Resources import NoCacheStaticFile from lbrynet import __version__ as lbrynet_version from lbryum.version import LBRYUM_VERSION as lbryum_version - - log = logging.getLogger(__name__) @@ -60,7 +59,7 @@ class UIManager(object): self.loaded_branch = None self.loaded_requirements = None - def setup(self, branch=None, check_requirements=None, user_specified=None): + def setup(self, branch=None, check_requirements=None, user_specified=None, launch=False): local_ui_path = user_specified or conf.settings.local_ui_path self.branch = branch or conf.settings.ui_branch @@ -95,6 +94,8 @@ class UIManager(object): d = self._up_to_date() d.addCallback(lambda r: self._download_ui() if not r else self._load_ui()) + if launch: + d.addCallback(lambda _: webbrowser.open(conf.settings.UI_ADDRESS)) return d def _check_for_bundled_ui(self): From 3541625825302dc92113092994de3a5b3f4aa188 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 3 Jan 2017 15:51:42 -0500 Subject: [PATCH 2/2] move launch into own function --- lbrynet/lbrynet_daemon/Daemon.py | 4 +++- lbrynet/lbrynet_daemon/UIManager.py | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index e8e40c6cf..a533cde1b 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -329,7 +329,9 @@ class Daemon(AuthJSONRPCServer): if conf.settings.host_ui: self.lbry_ui_manager.update_checker.start(1800, now=False) - yield self.lbry_ui_manager.setup(launch=launch_ui) + yield self.lbry_ui_manager.setup() + if launch_ui: + self.lbry_ui_manager.launch() yield self._initial_setup() yield threads.deferToThread(self._setup_data_directory) yield self._check_db_migration() diff --git a/lbrynet/lbrynet_daemon/UIManager.py b/lbrynet/lbrynet_daemon/UIManager.py index 2321ec2d3..0624d513c 100644 --- a/lbrynet/lbrynet_daemon/UIManager.py +++ b/lbrynet/lbrynet_daemon/UIManager.py @@ -59,7 +59,7 @@ class UIManager(object): self.loaded_branch = None self.loaded_requirements = None - def setup(self, branch=None, check_requirements=None, user_specified=None, launch=False): + def setup(self, branch=None, check_requirements=None, user_specified=None): local_ui_path = user_specified or conf.settings.local_ui_path self.branch = branch or conf.settings.ui_branch @@ -94,8 +94,6 @@ class UIManager(object): d = self._up_to_date() d.addCallback(lambda r: self._download_ui() if not r else self._load_ui()) - if launch: - d.addCallback(lambda _: webbrowser.open(conf.settings.UI_ADDRESS)) return d def _check_for_bundled_ui(self): @@ -213,6 +211,9 @@ class UIManager(object): def _load_ui(self): return load_ui(self.root, self.active_dir) + def launch(self): + webbrowser.open(conf.settings.UI_ADDRESS) + class BundledUIManager(object): """Copies the UI bundled with lbrynet, if available.