From 94398071eb389b150e6c2e372c0370865cd94425 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 23 Mar 2016 19:49:14 -0400 Subject: [PATCH] have uri handler check if app is running MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -checks if LBRY.app is running, starts it if it isn’t -delete unused function in LBRYDaemon --- lbrynet/lbrynet_daemon/Apps/LBRYURIHandler.py | 50 +++++++++++++------ lbrynet/lbrynet_daemon/LBRYDaemon.py | 4 -- setup_uri_handler.py | 2 +- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/lbrynet/lbrynet_daemon/Apps/LBRYURIHandler.py b/lbrynet/lbrynet_daemon/Apps/LBRYURIHandler.py index 1bc8c3399..ba62a78a4 100644 --- a/lbrynet/lbrynet_daemon/Apps/LBRYURIHandler.py +++ b/lbrynet/lbrynet_daemon/Apps/LBRYURIHandler.py @@ -3,9 +3,12 @@ import json import webbrowser import sys from time import sleep +import subprocess from jsonrpc.proxy import JSONRPCProxy -from lbrynet.conf import API_CONNECTION_STRING, UI_ADDRESS + +API_CONNECTION_STRING = "http://localhost:5279/lbryapi" +UI_ADDRESS = "http://localhost:5279" class LBRYURIHandler(object): @@ -15,27 +18,42 @@ class LBRYURIHandler(object): self.daemon = JSONRPCProxy.from_url(API_CONNECTION_STRING) def check_status(self): + status = None try: - self.daemon.is_running() - - except: - if self.started_daemon: - if self.start_timeout < 30: - sleep(1) - self.start_timeout += 1 - self.check_status() - else: - exit(1) - else: - os.system("open /Applications/LBRY.app") - self.started_daemon = True + status = json.loads(self.daemon.is_running())['result'] + if self.start_timeout < 30 and not status: + sleep(1) self.start_timeout += 1 self.check_status() + elif status: + return True + else: + exit(1) + except: + if self.start_timeout < 30: + sleep(1) + self.start_timeout += 1 + self.check_status() + else: + exit(1) def handle(self, lbry_name): - self.check_status() + lbry_process = [d for d in subprocess.Popen(['ps','aux'], stdout=subprocess.PIPE).stdout.readlines() + if 'LBRY.app' in d] + try: + status = json.loads(self.daemon.is_running())['result'] + except: + pass - if lbry_name == "lbry": + if lbry_process: + self.check_status() + started = False + else: + os.system("open /Applications/LBRY.app") + self.check_status() + started = True + + if lbry_name == "lbry" or lbry_name == "" and not started: webbrowser.get('safari').open(UI_ADDRESS) else: r = json.loads(self.daemon.get({'name': lbry_name})) diff --git a/lbrynet/lbrynet_daemon/LBRYDaemon.py b/lbrynet/lbrynet_daemon/LBRYDaemon.py index b3e37a1f7..3391e0dcb 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemon.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemon.py @@ -1136,10 +1136,6 @@ class LBRYindex(resource.Resource): return resource.Resource.getChild(self, name, request) def render_GET(self, request): - def _disp(r): - log.info(r) - return "" + ''.join(r) + "" - return static.File(os.path.join(self.ui_dir, "index.html")).render_GET(request) diff --git a/setup_uri_handler.py b/setup_uri_handler.py index 02f437e64..1a3c68700 100644 --- a/setup_uri_handler.py +++ b/setup_uri_handler.py @@ -4,7 +4,7 @@ import os APP = [os.path.join('lbrynet', 'lbrynet_daemon', 'Apps', 'LBRYURIHandler.py')] DATA_FILES = [] OPTIONS = {'argv_emulation': True, - 'packages': ['lbrynet', 'jsonrpc'], + 'packages': ['jsonrpc'], 'plist': { 'LSUIElement': True, 'CFBundleURLTypes': [