diff --git a/cli/onionshare_cli/settings.py b/cli/onionshare_cli/settings.py index 29b59c80..d3bb74e2 100644 --- a/cli/onionshare_cli/settings.py +++ b/cli/onionshare_cli/settings.py @@ -103,6 +103,7 @@ class Settings(object): "socket_file_path": "/var/run/tor/control", "auth_type": "no_auth", "auth_password": "", + "auto_connect": False, "use_autoupdate": True, "autoupdate_timestamp": None, "no_bridges": True, diff --git a/desktop/src/onionshare/auto_connect.py b/desktop/src/onionshare/auto_connect.py new file mode 100644 index 00000000..f7e0c00a --- /dev/null +++ b/desktop/src/onionshare/auto_connect.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +""" +OnionShare | https://onionshare.org/ + +Copyright (C) 2014-2021 Micah Lee, et al. + +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 . +""" + +from PySide2 import QtCore, QtWidgets, QtGui + +from onionshare_cli.settings import Settings + +from .gui_common import GuiCommon + + +class AutoConnect(QtWidgets.QWidget): + """ + GUI window that appears in the very beginning to ask user if + should auto connect. + """ + def __init__(self, common, parent=None): + super(AutoConnect, self).__init__(parent) + common.log("AutoConnect", "__init__") + + # Was auto connected? + self.curr_settings = Settings(common) + self.curr_settings.load() + self.auto_connect_enabled = self.curr_settings.get("auto_connect") + + if self.auto_connect_enabled: + self.parent().start_onionshare() + else: + # Onionshare logo + self.image_label = QtWidgets.QLabel() + self.image_label.setPixmap( + QtGui.QPixmap.fromImage( + QtGui.QImage( + GuiCommon.get_resource_path( + "images/{}_logo_text.png".format(common.gui.color_mode) + ) + ) + ) + ) + self.image_label.setFixedSize(180, 40) + image_layout = QtWidgets.QVBoxLayout() + image_layout.addWidget(self.image_label) + self.image = QtWidgets.QWidget() + self.image.setLayout(image_layout) + + # Description and checkbox + description_label = QtWidgets.QLabel("Some description about OnionShare and explain autoconnect stuff") + self.enable_autoconnect_checkbox = QtWidgets.QCheckBox() + self.enable_autoconnect_checkbox.clicked.connect(self.toggle_auto_connect) + self.enable_autoconnect_checkbox.setText( + "Enable automatically connecting to OnionShare" + ) + + # CTA buttons + self.connect_button = QtWidgets.QPushButton("Start OnionShare") + self.connect_button.setStyleSheet( + common.gui.css["server_status_button_stopped"] + ) + self.configure_button = QtWidgets.QPushButton("Configure") + cta_layout = QtWidgets.QHBoxLayout() + cta_layout.addWidget(self.connect_button) + cta_layout.addWidget(self.configure_button) + cta_widget = QtWidgets.QWidget() + cta_widget.setLayout(cta_layout) + + + # Layout + self.layout = QtWidgets.QVBoxLayout() + self.layout.setContentsMargins(0, 0, 0, 0) + self.layout.addStretch() + self.layout.addWidget(self.image) + self.layout.addWidget(description_label) + self.layout.addWidget(self.enable_autoconnect_checkbox) + self.layout.addStretch() + self.layout.addWidget(cta_widget) + self.layout.addStretch() + self.layout.setAlignment(QtCore.Qt.AlignCenter) + self.setLayout(self.layout) + + def toggle_auto_connect(self): + self.curr_settings.set( + "auto_connect", self.enable_autoconnect_checkbox.isChecked() + ) + self.curr_settings.save() diff --git a/desktop/src/onionshare/main_window.py b/desktop/src/onionshare/main_window.py index c125741c..22f813ad 100644 --- a/desktop/src/onionshare/main_window.py +++ b/desktop/src/onionshare/main_window.py @@ -23,6 +23,7 @@ import time from PySide2 import QtCore, QtWidgets, QtGui from . import strings +from .auto_connect import AutoConnect from .tor_connection_dialog import TorConnectionDialog from .tor_settings_dialog import TorSettingsDialog from .settings_dialog import SettingsDialog @@ -157,21 +158,17 @@ class MainWindow(QtWidgets.QMainWindow): layout = QtWidgets.QVBoxLayout() layout.addWidget(self.tabs) - central_widget = QtWidgets.QWidget() - central_widget.setLayout(layout) - self.setCentralWidget(central_widget) - self.show() + self.connected_central_widget = QtWidgets.QWidget() + self.connected_central_widget.setLayout(layout) + - # Start the "Connecting to Tor" dialog, which calls onion.connect() - tor_con = TorConnectionDialog(self.common) - tor_con.canceled.connect(self.tor_connection_canceled) - tor_con.open_tor_settings.connect(self.tor_connection_open_tor_settings) - if not self.common.gui.local_only: - tor_con.start() - self.settings_have_changed() - - # After connecting to Tor, check for updates - self.check_for_updates() + # Auto connect OnionShare? + auto_connect = AutoConnect(self.common, self) + if not auto_connect.auto_connect_enabled: + auto_connect.configure_button.clicked.connect(self.open_tor_settings) + auto_connect.connect_button.clicked.connect(self.start_onionshare) + self.setCentralWidget(auto_connect) + self.show() # Create the close warning dialog -- the dialog widget needs to be in the constructor # in order to test it @@ -187,6 +184,25 @@ class MainWindow(QtWidgets.QMainWindow): ) self.close_dialog.setDefaultButton(self.close_dialog.reject_button) + def start_onionshare(self): + """ + Once the user clicks on connect in the initial screen, start tor connection + and show new tab screen + """ + self.setCentralWidget(self.connected_central_widget) + self.show() + + # Start the "Connecting to Tor" dialog, which calls onion.connect() + tor_con = TorConnectionDialog(self.common) + tor_con.canceled.connect(self.tor_connection_canceled) + tor_con.open_tor_settings.connect(self.tor_connection_open_tor_settings) + if not self.common.gui.local_only: + tor_con.start() + self.settings_have_changed() + + # After connecting to Tor, check for updates + self.check_for_updates() + def tor_connection_canceled(self): """ If the user cancels before Tor finishes connecting, ask if they want to