Browse Source

kivy: make backups optional

hard-fail-on-bad-server-string
ThomasV 5 years ago
parent
commit
e3ccfe6449
  1. 6
      electrum/gui/kivy/main_window.py
  2. 7
      electrum/gui/kivy/uix/dialogs/settings.py
  3. 6
      electrum/util.py
  4. 7
      electrum/wallet.py

6
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():

7
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

6
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.

7
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

Loading…
Cancel
Save