From ad91a3222f9a10b1fb36dd1914c3eddee6b3fc7a Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 16 Jan 2021 02:08:36 +0000 Subject: [PATCH] show web url every time onionr daemon starts --- src/communicator/__init__.py | 2 +- src/onionrcommands/daemonlaunch/geturl.py | 24 +++++++++++++++++++++++ src/onionrcommands/openwebinterface.py | 17 +++------------- 3 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 src/onionrcommands/daemonlaunch/geturl.py diff --git a/src/communicator/__init__.py b/src/communicator/__init__.py index 50c7edc6..9a84cc8b 100755 --- a/src/communicator/__init__.py +++ b/src/communicator/__init__.py @@ -141,11 +141,11 @@ class OnionrCommunicatorDaemon: daemoneventhooks.daemon_event_handlers(shared_state) + get_url() if not config.get('onboarding.done', True): logger.info( 'First run detected. Run openhome to get setup.', terminal=True) - get_url() while not config.get('onboarding.done', True) and \ not self.shared_state.get_by_string( diff --git a/src/onionrcommands/daemonlaunch/geturl.py b/src/onionrcommands/daemonlaunch/geturl.py new file mode 100644 index 00000000..fbbd2000 --- /dev/null +++ b/src/onionrcommands/daemonlaunch/geturl.py @@ -0,0 +1,24 @@ +"""Onionr - Private P2P Communication. + +Open the web interface properly into a web browser, and return it +""" +import logger +from onionrutils import getclientapiserver + + +def get_url(config) -> str: + """Build UI URL string and return it.""" + onboarding = "" + if not config.get('onboarding.done', False): + onboarding = "onboarding/" + try: + url = getclientapiserver.get_client_API_server() + except FileNotFoundError: + url = "" + logger.error( + 'Onionr seems to not be running (could not get api host)', + terminal=True) + else: + url = 'http://%s/%s#%s' % (url, onboarding, config.get('client.webpassword')) + logger.info('Onionr web interface URL: ' + url, terminal=True) + return url diff --git a/src/onionrcommands/openwebinterface.py b/src/onionrcommands/openwebinterface.py index 7f55bb73..94978f15 100755 --- a/src/onionrcommands/openwebinterface.py +++ b/src/onionrcommands/openwebinterface.py @@ -9,6 +9,8 @@ import logger from onionrutils import getclientapiserver import config from onionrutils.localcommand import local_command + +from .daemonlaunch import geturl """ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -43,20 +45,7 @@ def _wait_for_ui_to_be_ready(): def get_url() -> str: """Build UI URL string and return it.""" - onboarding = "" - if not config.get('onboarding.done', False): - onboarding = "onboarding/" - try: - url = getclientapiserver.get_client_API_server() - except FileNotFoundError: - url = "" - logger.error( - 'Onionr seems to not be running (could not get api host)', - terminal=True) - else: - url = 'http://%s/%s#%s' % (url, onboarding, config.get('client.webpassword')) - logger.info('Onionr web interface URL: ' + url, terminal=True) - return url + geturl.get_url(config) get_url.onionr_help = "Shows the Onionr " # type: ignore