move tor start finished message to bottom during merge from work on fixing onboarding

This commit is contained in:
Kevin Froman 2020-02-11 20:10:21 -06:00
commit 59a1ad1235
5 changed files with 46 additions and 14 deletions

View File

@ -73,6 +73,9 @@ Please note: endpoints that simply provide static web app files are not document
* /insertblock
- Methods: POST
- Accepts JSON data for creating a new block. 'message' contains the block data, 'to' specifies the peer's public key to encrypt the data to, 'sign' is a boolean for signing the message.
* /torready
- Methods: POST
- Returns boolean if Tor is started or not
# Public API

View File

@ -242,8 +242,12 @@ class OnionrCommunicatorDaemon:
'First run detected. Run openhome to get setup.',
terminal=True)
while not config.get('onboarding.done', True):
time.sleep(5)
while not config.get('onboarding.done', True) and \
not self.shutdown:
try:
time.sleep(2)
except KeyboardInterrupt:
self.shutdown = True
# Main daemon loop, mainly for calling timers,
# don't do any complex operations here to avoid locking

View File

@ -7,8 +7,8 @@ import subprocess
import platform
from flask import Response, Blueprint, request, send_from_directory, abort
from flask import g
from gevent import spawn
from gevent import sleep
import unpaddedbase32
from httpapi import apiutils
@ -126,7 +126,7 @@ class PrivateEndpoints:
@private_endpoints_bp.route('/gettorsocks')
def get_tor_socks():
return Response(str(client_api._too_many.get(NetController).socksPort))
return Response(str(g.too_many.get(NetController).socksPort))
@private_endpoints_bp.route('/setonboarding', methods=['POST'])
def set_onboarding():
@ -136,3 +136,7 @@ class PrivateEndpoints:
def get_os_system():
return Response(platform.system().lower())
@private_endpoints_bp.route('/torready')
def is_tor_ready():
"""If Tor is starting up, the web UI is not ready to be used."""
return Response(str(g.too_many.get(NetController).readyState).lower())

View File

@ -13,7 +13,6 @@ import platform # For windows sigkill workaround
from onionrtypes import BooleanSuccessState
import logger
import filepaths
from .. import getopenport
from .. import watchdog
from . import customtorrc
@ -114,11 +113,6 @@ class NetController:
logger.fatal('Got keyboard interrupt. Onionr will exit soon.', timestamp = False, terminal=True)
return False
logger.info('Finished starting Tor.', terminal=True)
logger.info('Connecting to Onionr soon', terminal=True)
self.readyState = True
try:
myID = open(self.dataDir + 'hs/hostname', 'r')
self.myID = myID.read().replace('\n', '')
@ -131,6 +125,10 @@ class NetController:
multiprocessing.Process(target=watchdog.watchdog,
args=[os.getpid(), tor.pid]).start()
logger.info('Finished starting Tor.', terminal=True)
self.readyState = True
return True
def killTor(self):

View File

@ -3,9 +3,12 @@
Open the web interface properly into a web browser
"""
import webbrowser
from time import sleep
import logger
from onionrutils import getclientapiserver
import config
from onionrutils.localcommand import local_command
"""
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
@ -22,8 +25,27 @@ import config
"""
def _tell_if_ui_not_ready():
if local_command('/torready') != 'true':
logger.warn('The UI is not ready yet, waiting on Tor to start.', terminal=True)
def _wait_for_ui_to_be_ready():
if config.get('general.offline_mode', False) or \
not config.get('transports.tor', True) or \
config.get('tor.use_existing_tor'):
return
_tell_if_ui_not_ready()
while local_command('/torready') != 'true':
sleep(0.5)
logger.info("Tor is ready, opening UI", terminal=True)
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:
@ -32,7 +54,7 @@ def get_url() -> str:
'Onionr seems to not be running (could not get api host)',
terminal=True)
else:
url = 'http://%s/#%s' % (url, config.get('client.webpassword'))
url = 'http://%s/%s#%s' % (url, onboarding, config.get('client.webpassword'))
logger.info('Onionr web interface URL: ' + url, terminal=True)
return url
@ -50,7 +72,8 @@ def open_home():
'Onionr seems to not be running (could not get api host)',
terminal=True)
else:
url = 'http://%s/#%s' % (url, config.get('client.webpassword'))
_wait_for_ui_to_be_ready()
url = get_url()
logger.info(
'If Onionr does not open automatically, use this URL: ' + url,
terminal=True)