From 2aefe0ff4ef68f856cdcd24f4346438bbd905be2 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Fri, 27 Nov 2020 12:15:49 -0800 Subject: [PATCH] Make GUI pass the mode type into start_onion_service --- desktop/src/onionshare/tab/mode/__init__.py | 6 ++++++ desktop/src/onionshare/tab/mode/chat_mode/__init__.py | 6 ++++++ desktop/src/onionshare/tab/mode/receive_mode/__init__.py | 6 ++++++ desktop/src/onionshare/tab/mode/share_mode/__init__.py | 6 ++++++ desktop/src/onionshare/tab/mode/website_mode/__init__.py | 6 ++++++ desktop/src/onionshare/threads.py | 6 +++--- 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/desktop/src/onionshare/tab/mode/__init__.py b/desktop/src/onionshare/tab/mode/__init__.py index f92632f0..7738f567 100644 --- a/desktop/src/onionshare/tab/mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/__init__.py @@ -107,6 +107,12 @@ class Mode(QtWidgets.QWidget): """ pass + def get_type(self): + """ + Returns the type of mode as a string (e.g. "share", "receive", etc.) + """ + pass + def human_friendly_time(self, secs): """ Returns a human-friendly time delta from given seconds. diff --git a/desktop/src/onionshare/tab/mode/chat_mode/__init__.py b/desktop/src/onionshare/tab/mode/chat_mode/__init__.py index 25a02969..a7c2929b 100644 --- a/desktop/src/onionshare/tab/mode/chat_mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/chat_mode/__init__.py @@ -101,6 +101,12 @@ class ChatMode(Mode): self.wrapper_layout.addLayout(self.column_layout) self.setLayout(self.wrapper_layout) + def get_type(self): + """ + Returns the type of mode as a string (e.g. "share", "receive", etc.) + """ + return "chat" + def get_stop_server_autostop_timer_text(self): """ Return the string to put on the stop server button, if there's an auto-stop timer diff --git a/desktop/src/onionshare/tab/mode/receive_mode/__init__.py b/desktop/src/onionshare/tab/mode/receive_mode/__init__.py index 95d1ecbe..95a68dcb 100644 --- a/desktop/src/onionshare/tab/mode/receive_mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/receive_mode/__init__.py @@ -149,6 +149,12 @@ class ReceiveMode(Mode): self.wrapper_layout.addLayout(self.column_layout) self.setLayout(self.wrapper_layout) + def get_type(self): + """ + Returns the type of mode as a string (e.g. "share", "receive", etc.) + """ + return "receive" + def data_dir_button_clicked(self): """ Browse for a new OnionShare data directory, and save to tab settings diff --git a/desktop/src/onionshare/tab/mode/share_mode/__init__.py b/desktop/src/onionshare/tab/mode/share_mode/__init__.py index ccf85dbd..bf1498d5 100644 --- a/desktop/src/onionshare/tab/mode/share_mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/share_mode/__init__.py @@ -173,6 +173,12 @@ class ShareMode(Mode): # Always start with focus on file selection self.file_selection.setFocus() + def get_type(self): + """ + Returns the type of mode as a string (e.g. "share", "receive", etc.) + """ + return "share" + def autostop_sharing_checkbox_clicked(self): """ Save autostop sharing setting to the tab settings diff --git a/desktop/src/onionshare/tab/mode/website_mode/__init__.py b/desktop/src/onionshare/tab/mode/website_mode/__init__.py index 325b22f1..6df6ff02 100644 --- a/desktop/src/onionshare/tab/mode/website_mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/website_mode/__init__.py @@ -173,6 +173,12 @@ class WebsiteMode(Mode): # Always start with focus on file selection self.file_selection.setFocus() + def get_type(self): + """ + Returns the type of mode as a string (e.g. "share", "receive", etc.) + """ + return "website" + def disable_csp_checkbox_clicked(self): """ Save disable CSP setting to the tab settings diff --git a/desktop/src/onionshare/threads.py b/desktop/src/onionshare/threads.py index 338bbf27..d5e2dc6c 100644 --- a/desktop/src/onionshare/threads.py +++ b/desktop/src/onionshare/threads.py @@ -74,7 +74,7 @@ class OnionThread(QtCore.QThread): try: if self.mode.obtain_onion_early: self.mode.app.start_onion_service( - self.mode.settings, await_publication=False + self.mode.get_type(), self.mode.settings, await_publication=False ) # wait for modules in thread to load, preventing a thread-related cx_Freeze crash time.sleep(0.2) @@ -83,7 +83,7 @@ class OnionThread(QtCore.QThread): self.mode.app.stop_onion_service(self.mode.settings) else: self.mode.app.start_onion_service( - self.mode.settings, await_publication=True + self.mode.get_type(), self.mode.settings, await_publication=True ) # wait for modules in thread to load, preventing a thread-related cx_Freeze crash time.sleep(0.2) @@ -174,7 +174,7 @@ class AutoStartTimer(QtCore.QThread): class EventHandlerThread(QtCore.QThread): """ - To trigger an event, write a JSON line to the events file. When that file changes, + To trigger an event, write a JSON line to the events file. When that file changes, each line will be handled as an event. Valid events are: {"type": "new_tab"} {"type": "new_share_tab", "filenames": ["file1", "file2"]}