Attempt to fix CannotListenError
This commit is contained in:
parent
e67fa3cadc
commit
756427560c
2 changed files with 40 additions and 9 deletions
|
@ -1,8 +1,16 @@
|
|||
import _winreg as winreg
|
||||
import os
|
||||
import sys
|
||||
|
||||
import win32con
|
||||
import win32gui
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
install = 'remove' not in sys.argv[1]
|
||||
except:
|
||||
install = True
|
||||
lbry_path = os.path.join(os.environ["ProgramFiles"], "LBRY", "LBRY.exe")
|
||||
|
||||
key_url = 'lbry'
|
||||
|
@ -10,8 +18,12 @@ def main():
|
|||
key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, key_url, 0, winreg.KEY_ALL_ACCESS)
|
||||
except:
|
||||
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, key_url)
|
||||
winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "URL:LBRY Protocol")
|
||||
winreg.SetValueEx(key, "URL Protocol", 0, winreg.REG_SZ, "")
|
||||
if install:
|
||||
winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "URL:LBRY Protocol")
|
||||
winreg.SetValueEx(key, "URL Protocol", 0, winreg.REG_SZ, "")
|
||||
else:
|
||||
winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT, key_url)
|
||||
|
||||
winreg.CloseKey(key)
|
||||
|
||||
key_icon = os.path.join('lbry', 'DefaultIcon')
|
||||
|
@ -19,7 +31,10 @@ def main():
|
|||
key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, key_icon, 0, winreg.KEY_ALL_ACCESS)
|
||||
except:
|
||||
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, key_icon)
|
||||
winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "\"LBRY.exe,1\"")
|
||||
if install:
|
||||
winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "\"LBRY.exe,1\"")
|
||||
else:
|
||||
winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT, key_icon)
|
||||
winreg.CloseKey(key)
|
||||
|
||||
key_command = os.path.join('lbry', 'shell', 'open', 'command')
|
||||
|
@ -27,8 +42,13 @@ def main():
|
|||
key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, key_command, 0, winreg.KEY_ALL_ACCESS)
|
||||
except:
|
||||
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, key_command)
|
||||
winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "\"{0}\" \"%1\"".format(lbry_path))
|
||||
if install:
|
||||
winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "\"{0}\" \"%1\"".format(lbry_path))
|
||||
else:
|
||||
winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT, key_command)
|
||||
winreg.CloseKey(key)
|
||||
|
||||
win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -11,6 +11,7 @@ import win32gui_struct
|
|||
from jsonrpc.proxy import JSONRPCProxy
|
||||
from twisted.internet import reactor, error
|
||||
from twisted.web import server
|
||||
import twisted
|
||||
|
||||
try:
|
||||
import winxpgui as win32gui
|
||||
|
@ -19,15 +20,21 @@ 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, API_CONNECTION_STRING
|
||||
from lbrynet.conf import UI_ADDRESS, API_CONNECTION_STRING, LOG_FILE_NAME
|
||||
from packaging.uri_handler.LBRYURIHandler import LBRYURIHandler
|
||||
|
||||
|
||||
# TODO: omg, this code is essentially duplicated in LBRYDaemon
|
||||
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
if not os.path.isdir(data_dir):
|
||||
os.mkdir(data_dir)
|
||||
|
||||
lbrynet_log = os.path.join(data_dir, LOG_FILE_NAME)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
if getattr(sys, 'frozen', False) and os.name == "nt":
|
||||
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.path.dirname(sys.executable), "cacert.pem")
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
REMOTE_SERVER = "www.google.com"
|
||||
|
||||
|
||||
|
@ -282,7 +289,11 @@ def main(lbry_name=None):
|
|||
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)
|
||||
try:
|
||||
reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE)
|
||||
except error.CannotListenError:
|
||||
log.info('Daemon already running, exiting app')
|
||||
sys.exit(1)
|
||||
reactor.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -298,7 +309,7 @@ if __name__ == '__main__':
|
|||
lbry_name = LBRYURIHandler.parse_name(sys.argv[1])
|
||||
except IndexError:
|
||||
lbry_name = None
|
||||
|
||||
start_daemon = True
|
||||
if start_daemon:
|
||||
main(lbry_name)
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue