forked from LBRYCommunity/lbry-sdk
Add URI handling as an arg
This commit is contained in:
parent
18310632eb
commit
25437602d7
5 changed files with 143 additions and 19 deletions
90
lbrynet/packaging/LBRYURIHandler.py
Normal file
90
lbrynet/packaging/LBRYURIHandler.py
Normal file
|
@ -0,0 +1,90 @@
|
|||
import os
|
||||
import webbrowser
|
||||
import subprocess
|
||||
import sys
|
||||
from time import sleep
|
||||
|
||||
from jsonrpc.proxy import JSONRPCProxy
|
||||
|
||||
from lbrynet.conf import UI_ADDRESS, API_CONNECTION_STRING
|
||||
|
||||
|
||||
class LBRYURIHandler(object):
|
||||
def __init__(self):
|
||||
self.started_daemon = False
|
||||
self.daemon = JSONRPCProxy.from_url(API_CONNECTION_STRING)
|
||||
|
||||
def handle_osx(self, lbry_name):
|
||||
self.check_daemon()
|
||||
if not self.started_daemon:
|
||||
os.system("open /Applications/LBRY.app")
|
||||
sleep(3)
|
||||
|
||||
lbry_name = self.parse_name(lbry_name)
|
||||
self.open_address(lbry_name)
|
||||
|
||||
def handle_linux(self, lbry_name):
|
||||
self.check_daemon()
|
||||
if not self.started_daemon:
|
||||
cmd = r'DIR = "$( cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"' \
|
||||
r'if [-z "$(pgrep lbrynet-daemon)"]; then' \
|
||||
r'echo "running lbrynet-daemon..."' \
|
||||
r'$DIR / lbrynet - daemon &' \
|
||||
r'sleep 3 # let the daemon load before connecting' \
|
||||
r'fi'
|
||||
subprocess.Popen(cmd, shell=True)
|
||||
|
||||
lbry_name = self.parse_name(lbry_name)
|
||||
self.open_address(lbry_name)
|
||||
|
||||
def handle_win32(self, lbry_name):
|
||||
# Opening LBRY.exe with lbry_name as arg prevents the need to
|
||||
# make a separate call to open_address()
|
||||
self.check_daemon()
|
||||
lbry_name = self.parse_name(lbry_name)
|
||||
if self.started_daemon:
|
||||
self.open_address(lbry_name)
|
||||
else:
|
||||
lbry_path = os.path.join(os.environ["PROGRAMFILES"], "LBRY", "LBRY.exe ")
|
||||
subprocess.call(lbry_path + lbry_name)
|
||||
|
||||
def check_daemon(self):
|
||||
try:
|
||||
self.started_daemon = self.daemon.is_running()
|
||||
except:
|
||||
self.started_daemon = False
|
||||
|
||||
@staticmethod
|
||||
def parse_name(lbry_name):
|
||||
if lbry_name[:7].lower() == "lbry://":
|
||||
if lbry_name[-1] == "/":
|
||||
return lbry_name[7:-1]
|
||||
else:
|
||||
return lbry_name[7:]
|
||||
else:
|
||||
if lbry_name[-1] == "/":
|
||||
return lbry_name[:-1]
|
||||
else:
|
||||
return lbry_name[:]
|
||||
|
||||
@staticmethod
|
||||
def open_address(lbry_name):
|
||||
if lbry_name == "lbry" or lbry_name == "" or lbry_name is None:
|
||||
webbrowser.open(UI_ADDRESS)
|
||||
else:
|
||||
webbrowser.open(UI_ADDRESS + "/?show=" + lbry_name)
|
||||
|
||||
|
||||
def main(args):
|
||||
if len(args) != 1:
|
||||
args = ["lbry://lbry"]
|
||||
name = args[0][7:]
|
||||
if sys.platform == "darwin":
|
||||
LBRYURIHandler().handle_osx(lbry_name=name)
|
||||
elif os.name == "nt":
|
||||
LBRYURIHandler().handle_win32(lbry_name=name)
|
||||
else:
|
||||
LBRYURIHandler().handle_linux(lbry_name=name)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
0
lbrynet/packaging/__init__.py
Normal file
0
lbrynet/packaging/__init__.py
Normal file
15
packaging/windows/lbry-win32-app/LBRY-URI.reg
Normal file
15
packaging/windows/lbry-win32-app/LBRY-URI.reg
Normal file
|
@ -0,0 +1,15 @@
|
|||
Windows Registry Editor Version 5.00
|
||||
|
||||
[HKEY_CLASSES_ROOT\lbry]
|
||||
@="URL:LBRY Protocol"
|
||||
"URL Protocol"=""
|
||||
|
||||
[HKEY_CLASSES_ROOT\lbry\DefaultIcon]
|
||||
@="LBRY.exe,1"
|
||||
|
||||
[HKEY_CLASSES_ROOT\lbry\shell]
|
||||
|
||||
[HKEY_CLASSES_ROOT\lbry\shell\open]
|
||||
|
||||
[HKEY_CLASSES_ROOT\lbry\shell\open\command]
|
||||
@="\"C:\\Program Files (x86)\\LBRY\\LBRY.exe\" \"%1\""
|
|
@ -4,12 +4,13 @@ import socket
|
|||
import sys
|
||||
import threading
|
||||
import webbrowser
|
||||
|
||||
from twisted.internet import reactor, error
|
||||
from twisted.web import server
|
||||
import win32api
|
||||
|
||||
import win32con
|
||||
import win32gui_struct
|
||||
from jsonrpc.proxy import JSONRPCProxy
|
||||
from twisted.internet import reactor, error
|
||||
from twisted.web import server
|
||||
|
||||
try:
|
||||
import winxpgui as win32gui
|
||||
|
@ -18,7 +19,8 @@ except ImportError:
|
|||
|
||||
from lbrynet.lbrynet_daemon.LBRYDaemonServer import LBRYDaemonServer, LBRYDaemonRequest
|
||||
from lbrynet.conf import API_PORT, API_INTERFACE, ICON_PATH, APP_NAME
|
||||
from lbrynet.conf import UI_ADDRESS
|
||||
from lbrynet.conf import UI_ADDRESS, API_CONNECTION_STRING
|
||||
from lbrynet.packaging.LBRYURIHandler import LBRYURIHandler
|
||||
|
||||
|
||||
if getattr(sys, 'frozen', False) and os.name == "nt":
|
||||
|
@ -243,7 +245,7 @@ class SysTrayIcon(object):
|
|||
win32gui.DestroyWindow(self.hwnd)
|
||||
|
||||
|
||||
def main():
|
||||
def main(lbry_name=None):
|
||||
def LBRYApp():
|
||||
return SysTrayIcon(icon, hover_text, menu_options, on_quit=stop)
|
||||
|
||||
|
@ -277,11 +279,26 @@ def main():
|
|||
|
||||
lbry = LBRYDaemonServer()
|
||||
d = lbry.start()
|
||||
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS))
|
||||
d.addCallback(lambda _: LBRYURIHandler.open_address(lbry_name))
|
||||
lbrynet_server = server.Site(lbry.root)
|
||||
lbrynet_server.requestFactory = LBRYDaemonRequest
|
||||
reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE)
|
||||
reactor.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
lbry_daemon = JSONRPCProxy.from_url(API_CONNECTION_STRING)
|
||||
|
||||
try:
|
||||
started_daemon = lbry_daemon.is_running()
|
||||
except:
|
||||
started_daemon = False
|
||||
|
||||
try:
|
||||
lbry_name = LBRYURIHandler.parse_name(sys.argv[1])
|
||||
except IndexError:
|
||||
lbry_name = None
|
||||
|
||||
if started_daemon:
|
||||
LBRYURIHandler.open_address(lbry_name)
|
||||
else:
|
||||
main(lbry_name)
|
||||
|
|
|
@ -13,6 +13,8 @@ import requests.certs
|
|||
|
||||
from lbrynet import __version__
|
||||
|
||||
name = 'LBRY'
|
||||
description = 'A decentralized media library and marketplace'
|
||||
win_icon = os.path.join('packaging', 'windows', 'lbry-win32-app', 'icons', 'lbry256.ico')
|
||||
wordlist_path = pkg_resources.resource_filename('lbryum', 'wordlist')
|
||||
|
||||
|
@ -47,27 +49,27 @@ console_scripts = ['lbrynet-stdin-uploader = lbrynet.lbrynet_console.LBRYStdinUp
|
|||
# shortcut_table = [
|
||||
# ('DesktopShortcut', # Shortcut
|
||||
# 'DesktopFolder', # Directory
|
||||
# 'LBRY 1', # Name
|
||||
# name, # Name
|
||||
# 'TARGETDIR', # Component
|
||||
# '[TARGETDIR]\LBRY.exe', # Target
|
||||
# '[TARGETDIR]\{0}.exe'.format(name), # Target
|
||||
# None, # Arguments
|
||||
# None, # Description
|
||||
# description, # Description
|
||||
# None, # Hotkey
|
||||
# win_icon, # Icon
|
||||
# win_icon, # Icon (doesn't work for some reason?)
|
||||
# None, # IconIndex
|
||||
# None, # ShowCmd
|
||||
# 'TARGETDIR', # WkDir
|
||||
# ),
|
||||
# ]
|
||||
#
|
||||
# # Now create the table dictionary
|
||||
# msi_data = {'Shortcut': shortcut_table}
|
||||
|
||||
bdist_msi_options = {
|
||||
# 'upgrade_code': '{66620F3A-DC3A-11E2-B341-002219E9B01F}',
|
||||
'upgrade_code': '{18c0e933-ad08-44e8-a413-1d0ed624c100}',
|
||||
'add_to_path': False,
|
||||
'initial_target_dir': r'[LocalAppDataFolder]\LBRY',
|
||||
# 'data': msi_data,
|
||||
# Default install path is 'C:\Program Files\' for 32-bit or 'C:\Program Files (x86)\' for 64-bit
|
||||
# 'initial_target_dir': r'[LocalAppDataFolder]\{0}'.format(name),
|
||||
# 'data': msi_data
|
||||
}
|
||||
|
||||
build_exe_options = {
|
||||
|
@ -129,16 +131,16 @@ exe = Executable(
|
|||
base='Win32GUI',
|
||||
icon=win_icon,
|
||||
compress=True,
|
||||
shortcutName='LBRY',
|
||||
shortcutName=name,
|
||||
shortcutDir='DesktopFolder',
|
||||
targetName='LBRY.exe'
|
||||
targetName='{0}.exe'.format(name)
|
||||
# targetDir="LocalAppDataFolder"
|
||||
)
|
||||
|
||||
setup(
|
||||
name='LBRY',
|
||||
name=name,
|
||||
version=__version__,
|
||||
description='A decentralized media library and marketplace',
|
||||
description=name + ": " + description,
|
||||
url='lbry.io',
|
||||
author='LBRY, Inc.',
|
||||
keywords='LBRY',
|
||||
|
|
Loading…
Reference in a new issue