diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py index 6f2b72ab..cb4f3e12 100644 --- a/onionshare_gui/__init__.py +++ b/onionshare_gui/__init__.py @@ -60,7 +60,6 @@ def main(): The main() function implements all of the logic that the GUI version of onionshare uses. """ common = Common() - common.gui = GuiCommon(common) # Display OnionShare banner print(f"OnionShare {common.version} | https://onionshare.org/") @@ -156,8 +155,11 @@ def main(): # TODO: open tab return + # Attach the GUI common parts to the common object + common.gui = GuiCommon(common, qtapp, local_only, config) + # Launch the gui - main_window = MainWindow(common, qtapp, filenames, config, local_only) + main_window = MainWindow(common, filenames) # Clean up when app quits def shutdown(): diff --git a/onionshare_gui/gui_common.py b/onionshare_gui/gui_common.py index 9964a322..940d813b 100644 --- a/onionshare_gui/gui_common.py +++ b/onionshare_gui/gui_common.py @@ -17,6 +17,7 @@ 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 onionshare import strings class GuiCommon: @@ -28,8 +29,20 @@ class GuiCommon: MODE_RECEIVE = "receive" MODE_WEBSITE = "website" - def __init__(self, common): + def __init__(self, common, qtapp, local_only, config): self.common = common + self.qtapp = qtapp + self.local_only = local_only + + # Load settings, if a custom config was passed in + self.config = config + if self.config: + self.common.load_settings(self.config) + else: + self.common.load_settings() + + # Load strings + strings.load_strings(self.common) self.css = { # OnionShareGui styles diff --git a/onionshare_gui/main_window.py b/onionshare_gui/main_window.py index 6db40473..1f800000 100644 --- a/onionshare_gui/main_window.py +++ b/onionshare_gui/main_window.py @@ -42,22 +42,19 @@ class MainWindow(QtWidgets.QMainWindow): MainWindow is the OnionShare main window, which contains the GUI elements, including all open tabs """ - def __init__(self, common, qtapp, filenames, config=False, local_only=False): + def __init__(self, common, filenames): super(MainWindow, self).__init__() self.common = common self.common.log("MainWindow", "__init__") - self.qtapp = qtapp - self.local_only = local_only - self.mode = self.common.gui.MODE_SHARE # Start the Onion self.onion = Onion(common) # Start the OnionShare app - self.app = OnionShare(common, self.onion, local_only) + self.app = OnionShare(common, self.onion, self.common.gui.local_only) # Initialize the window self.setMinimumWidth(820) @@ -68,15 +65,6 @@ class MainWindow(QtWidgets.QMainWindow): QtGui.QIcon(self.common.get_resource_path("images/logo.png")) ) - # Load settings, if a custom config was passed in - self.config = config - if self.config: - self.common.load_settings(self.config) - else: - self.common.load_settings() - - strings.load_strings(self.common) - # System tray menu = QtWidgets.QMenu() self.settings_action = menu.addAction(strings._("gui_settings_window_title")) @@ -87,6 +75,7 @@ class MainWindow(QtWidgets.QMainWindow): exit_action.triggered.connect(self.close) self.system_tray = QtWidgets.QSystemTrayIcon(self) + # The convention is Mac systray icons are always grayscale if self.common.platform == "Darwin": self.system_tray.setIcon( @@ -163,13 +152,13 @@ class MainWindow(QtWidgets.QMainWindow): # Share mode self.share_mode = ShareMode( self.common, - qtapp, + self.common.gui.qtapp, self.app, self.status_bar, self.server_status_label, self.system_tray, filenames, - self.local_only, + self.common.gui.local_only, ) self.share_mode.init() self.share_mode.server_status.server_started.connect( @@ -194,13 +183,13 @@ class MainWindow(QtWidgets.QMainWindow): # Receive mode self.receive_mode = ReceiveMode( self.common, - qtapp, + self.common.gui.qtapp, self.app, self.status_bar, self.server_status_label, self.system_tray, None, - self.local_only, + self.common.gui.local_only, ) self.receive_mode.init() self.receive_mode.server_status.server_started.connect( @@ -227,7 +216,7 @@ class MainWindow(QtWidgets.QMainWindow): # Website mode self.website_mode = WebsiteMode( self.common, - qtapp, + self.common.gui.qtapp, self.app, self.status_bar, self.server_status_label, @@ -284,10 +273,10 @@ class MainWindow(QtWidgets.QMainWindow): self.timer.timeout.connect(self.timer_callback) # Start the "Connecting to Tor" dialog, which calls onion.connect() - tor_con = TorConnectionDialog(self.common, self.qtapp, self.onion) + tor_con = TorConnectionDialog(self.common, self.common.gui.qtapp, self.onion) tor_con.canceled.connect(self._tor_connection_canceled) tor_con.open_settings.connect(self._tor_connection_open_settings) - if not self.local_only: + if not self.common.gui.local_only: tor_con.start() # Start the timer @@ -490,7 +479,7 @@ class MainWindow(QtWidgets.QMainWindow): ) # Wait 1ms for the event loop to finish, then quit - QtCore.QTimer.singleShot(1, self.qtapp.quit) + QtCore.QTimer.singleShot(1, self.common.gui.qtapp.quit) # Wait 100ms before asking QtCore.QTimer.singleShot(100, ask) @@ -519,7 +508,7 @@ class MainWindow(QtWidgets.QMainWindow): # We might've stopped the main requests timer if a Tor connection failed. # If we've reloaded settings, we probably succeeded in obtaining a new # connection. If so, restart the timer. - if not self.local_only: + if not self.common.gui.local_only: if self.onion.is_authenticated(): if not self.timer.isActive(): self.timer.start(500) @@ -543,7 +532,11 @@ class MainWindow(QtWidgets.QMainWindow): self.website_mode.server_status.autostart_timer_container.hide() d = SettingsDialog( - self.common, self.onion, self.qtapp, self.config, self.local_only + self.common, + self.onion, + self.common.gui.qtapp, + self.common.gui.config, + self.common.gui.local_only, ) d.settings_saved.connect(reload_settings) d.exec_() @@ -568,7 +561,9 @@ class MainWindow(QtWidgets.QMainWindow): ), ) - self.update_thread = UpdateThread(self.common, self.onion, self.config) + self.update_thread = UpdateThread( + self.common, self.onion, self.common.gui.config + ) self.update_thread.update_available.connect(update_available) self.update_thread.start() @@ -579,7 +574,7 @@ class MainWindow(QtWidgets.QMainWindow): """ self.update() - if not self.local_only: + if not self.common.gui.local_only: # Have we lost connection to Tor somehow? if not self.onion.is_authenticated(): self.timer.stop()