From 1bca467ce36654dd5abebfc53f4902c06391d756 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 2 Nov 2019 23:06:26 -0700 Subject: [PATCH] When disabling persistence, or closing a persistent tab, delete the mode settings file for that tab --- onionshare/mode_settings.py | 8 +++++--- onionshare_gui/tab/mode/mode_settings_widget.py | 4 ++++ onionshare_gui/tab_widget.py | 7 +++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/onionshare/mode_settings.py b/onionshare/mode_settings.py index 3b14dbe8..5728bbc1 100644 --- a/onionshare/mode_settings.py +++ b/onionshare/mode_settings.py @@ -130,11 +130,13 @@ class ModeSettings: def save(self): # Save persistent setting to disk if not self.get("persistent", "enabled"): - self.common.log( - "ModeSettings", "save", f"{self.id}: not persistent, so not saving" - ) return if self.filename: with open(self.filename, "w") as file: file.write(json.dumps(self._settings, indent=2)) + + def delete(self): + # Delete the file from disk + if os.path.exists(self.filename): + os.remove(self.filename) diff --git a/onionshare_gui/tab/mode/mode_settings_widget.py b/onionshare_gui/tab/mode/mode_settings_widget.py index 462fe728..a6a43df6 100644 --- a/onionshare_gui/tab/mode/mode_settings_widget.py +++ b/onionshare_gui/tab/mode/mode_settings_widget.py @@ -202,6 +202,10 @@ class ModeSettingsWidget(QtWidgets.QWidget): self.tab.tab_id, self.persistent_checkbox.isChecked() ) + # If disabling persistence, delete the file from disk + if not self.persistent_checkbox.isChecked(): + self.settings.delete() + def public_checkbox_clicked(self): self.settings.set("general", "public", self.public_checkbox.isChecked()) diff --git a/onionshare_gui/tab_widget.py b/onionshare_gui/tab_widget.py index 70ebfb66..09407600 100644 --- a/onionshare_gui/tab_widget.py +++ b/onionshare_gui/tab_widget.py @@ -150,6 +150,11 @@ class TabWidget(QtWidgets.QTabWidget): self.common.log("TabWidget", "close_tab", f"{index}") tab = self.widget(index) if tab.close_tab(): + # If the tab is persistent, delete the settings file from disk + if tab.settings.get("persistent", "enabled"): + tab.settings.delete() + + # Remove the tab self.removeTab(index) del self.tabs[tab.tab_id] @@ -157,6 +162,8 @@ class TabWidget(QtWidgets.QTabWidget): if self.count() == 0: self.new_tab_clicked() + self.save_persistent_tabs() + def are_tabs_active(self): """ See if there are active servers in any open tabs