From e3ccfe64492cbbb5abf488797248bd54984d687d Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 15 Feb 2020 17:26:03 +0100 Subject: [PATCH] kivy: make backups optional --- electrum/gui/kivy/main_window.py | 6 +++++- electrum/gui/kivy/uix/dialogs/settings.py | 7 +++++++ electrum/util.py | 6 ++++-- electrum/wallet.py | 7 ++++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py index e4611a32b..109d01089 100644 --- a/electrum/gui/kivy/main_window.py +++ b/electrum/gui/kivy/main_window.py @@ -164,6 +164,10 @@ class ElectrumWindow(App): def on_use_rbf(self, instance, x): self.electrum_config.set_key('use_rbf', self.use_rbf, True) + android_backups = BooleanProperty(False) + def on_android_backups(self, instance, x): + self.electrum_config.set_key('android_backups', self.android_backups, True) + use_change = BooleanProperty(False) def on_use_change(self, instance, x): if self.wallet: @@ -1252,7 +1256,7 @@ class ElectrumWindow(App): if new_path: self.show_info(_("Backup saved:") + f"\n{new_path}") else: - self.show_error(_("Backup NOT saved. Backup directory or password not configured.")) + self.show_error(_("Backup NOT saved. Backup directory not configured.")) def export_private_keys(self, pk_label, addr): if self.wallet.is_watching_only(): diff --git a/electrum/gui/kivy/uix/dialogs/settings.py b/electrum/gui/kivy/uix/dialogs/settings.py index 2f58e7e64..b7fc3aa58 100644 --- a/electrum/gui/kivy/uix/dialogs/settings.py +++ b/electrum/gui/kivy/uix/dialogs/settings.py @@ -89,6 +89,13 @@ Builder.load_string(''' title: _('Password') description: _("Change wallet password.") action: root.change_password + CardSeparator + SettingsItem: + status: _('Yes') if app.android_backups else _('No') + title: _('Backups') + ': ' + self.status + description: _("Backup wallet to external storage.") + message: _("If this option is checked, a backup of your wallet will be written to external storage everytime you create a new channel. Make sure your wallet is protected with a strong password before you enable this option.") + action: partial(root.boolean_dialog, 'android_backups', _('Backups'), self.message) # disabled: there is currently only one coin selection policy #CardSeparator diff --git a/electrum/util.py b/electrum/util.py index 932602ac8..8051909fc 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -441,8 +441,10 @@ def android_data_dir(): return PythonActivity.mActivity.getFilesDir().getPath() + '/data' def get_backup_dir(config): - return android_backup_dir() if 'ANDROID_DATA' in os.environ else config.get('backup_dir') - + if 'ANDROID_DATA' in os.environ: + return android_backup_dir() if config.get('android_backups') else None + else: + return config.get('backup_dir') def ensure_sparse_file(filename): # On modern Linux, no need to do anything. diff --git a/electrum/wallet.py b/electrum/wallet.py index c6d42958e..199b3e4d8 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -264,11 +264,12 @@ class Abstract_Wallet(AddressSynchronizer, ABC): self.db.write(self.storage) def save_backup(self): + backup_dir = get_backup_dir(self.config) + if backup_dir is None: + return new_db = WalletDB(self.db.dump(), manual_upgrades=False) new_db.put('is_backup', True) - new_path = os.path.join(get_backup_dir(self.config), self.basename() + '.backup') - if new_path is None: - return + new_path = os.path.join(backup_dir, self.basename() + '.backup') new_storage = WalletStorage(new_path) new_storage._encryption_version = self.storage._encryption_version new_storage.pubkey = self.storage.pubkey