Began making a TorConnectionDialog, which handles connecting to the Tor network

This commit is contained in:
Micah Lee 2017-04-17 20:26:35 -07:00
parent 1519f3693d
commit 71dc65edee
4 changed files with 85 additions and 5 deletions

View File

@ -131,7 +131,7 @@ class Onion(object):
# The tor process # The tor process
self.tor_proc = None self.tor_proc = None
def connect(self, settings=False, bundled_tor_func=None): def connect(self, settings=False, tor_status_update_func=None):
# Either use settings that are passed in, or load them from disk # Either use settings that are passed in, or load them from disk
if settings: if settings:
self.settings = settings self.settings = settings
@ -205,9 +205,8 @@ class Onion(object):
# "\033[K" clears the rest of the line # "\033[K" clears the rest of the line
print("{}: {}% - {}{}".format(strings._('connecting_to_tor'), progress, summary, "\033[K"), end="\r") print("{}: {}% - {}{}".format(strings._('connecting_to_tor'), progress, summary, "\033[K"), end="\r")
if callable(bundled_tor_func): if callable(tor_status_update_func):
status_string = "{}% - {}".format(progress, summary) tor_status_update_func(progress, summary)
bundled_tor_func(status_string)
if summary == 'Done': if summary == 'Done':
print("") print("")

View File

@ -22,9 +22,12 @@ import os, sys, platform, argparse
from PyQt5 import QtCore, QtWidgets from PyQt5 import QtCore, QtWidgets
from onionshare import strings, helpers, web from onionshare import strings, helpers, web
from onionshare.onion import *
from onionshare.onionshare import OnionShare from onionshare.onionshare import OnionShare
from onionshare.settings import Settings
from .onionshare_gui import OnionShareGui from .onionshare_gui import OnionShareGui
from .tor_connection_dialog import TorConnectionDialog
class Application(QtWidgets.QApplication): class Application(QtWidgets.QApplication):
""" """
@ -84,12 +87,21 @@ def main():
if not valid: if not valid:
sys.exit() sys.exit()
# Load settings
settings = Settings()
settings.load()
# Start the Onion
onion = Onion()
tor_con = TorConnectionDialog(settings, onion)
# Start the OnionShare app # Start the OnionShare app
web.set_stay_open(stay_open) web.set_stay_open(stay_open)
app = OnionShare(debug, local_only, stay_open) app = OnionShare(debug, local_only, stay_open)
# Clean up when app quits # Clean up when app quits
def shutdown(): def shutdown():
onion.cleanup()
app.cleanup() app.cleanup()
qtapp.aboutToQuit.connect(shutdown) qtapp.aboutToQuit.connect(shutdown)

View File

@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
"""
OnionShare | https://onionshare.org/
Copyright (C) 2017 Micah Lee <micah@micahflee.com>
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from PyQt5 import QtCore, QtWidgets, QtGui
from onionshare import strings, helpers
class TorConnectionDialog(QtWidgets.QProgressDialog):
"""
Connecting to Tor dialog.
"""
def __init__(self, settings, onion):
super(TorConnectionDialog, self).__init__(None)
self.settings = settings
self.setWindowTitle("OnionShare")
self.setWindowIcon(QtGui.QIcon(helpers.get_resource_path('images/logo.png')))
self.setModal(True)
# Label
self.setLabelText(strings._('connecting_to_tor', True))
self.setCancelButtonText(strings._('gui_tor_connection_exit', True))
# Progress bar ticks from 0 to 100
self.setRange(0, 100)
# Don't show if connection takes less than 200ms (for non-bundled tor)
self.setMinimumDuration(200)
# If bundled tor, prepare to display Tor connection status
if settings.get('connection_type') == 'bundled':
tor_status_update = self.tor_status_update
else:
tor_status_update = None
# Connect to the Onion
self.setValue(0)
try:
onion.connect(self.settings, tor_status_update)
except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported, BundledTorTimeout) as e:
print(e.args[0])
# TODO: Open settings to connect to Tor properly
sys.exit()
self.exec_()
def tor_status_update(self, progress, summary):
if summary == 'Done':
# All done
self.close()
else:
self.setValue(int(progress))
self.setLabelText("<strong>{}</strong><br>{}".format(strings._('connecting_to_tor', True), summary))

View File

@ -100,5 +100,6 @@
"update_error_tor": "Error checking for updates: Can't connect to Tor.\nCheck your Tor connection settings.", "update_error_tor": "Error checking for updates: Can't connect to Tor.\nCheck your Tor connection settings.",
"update_error_sockshttp": "Error checking for updates: Connected to Tor, but can't load the update HTTP request.", "update_error_sockshttp": "Error checking for updates: Connected to Tor, but can't load the update HTTP request.",
"update_error_invalid_latest_version": "Error checking for updates: The OnionShare website responded saying the latest version is '{}', but that doesn't appear to be a valid version string.", "update_error_invalid_latest_version": "Error checking for updates: The OnionShare website responded saying the latest version is '{}', but that doesn't appear to be a valid version string.",
"update_not_available": "You are running the latest version of OnionShare." "update_not_available": "You are running the latest version of OnionShare.",
"gui_tor_connection_exit": "Exit"
} }