Browse Source

follow-up prev: some clean-up and added clarifications

re https://github.com/spesmilo/electrum/pull/7464
patch-4
SomberNight 3 years ago
parent
commit
67f14cdfa8
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 42
      electrum/gui/kivy/main_window.py
  2. 8
      electrum/gui/kivy/uix/ui_screens/first_screen.kv
  3. 4
      electrum/gui/kivy/uix/ui_screens/initial_network_setup.kv

42
electrum/gui/kivy/main_window.py

@ -123,24 +123,28 @@ class ElectrumWindow(App, Logger):
auto_connect = BooleanProperty(False) auto_connect = BooleanProperty(False)
def on_auto_connect(self, instance, x): def on_auto_connect(self, instance, x):
if not self._init_finished:
return
net_params = self.network.get_parameters() net_params = self.network.get_parameters()
if net_params.auto_connect != self.auto_connect: net_params = net_params._replace(auto_connect=self.auto_connect)
net_params = net_params._replace(auto_connect=self.auto_connect) self.network.run_from_another_thread(self.network.set_parameters(net_params))
self.network.run_from_another_thread(self.network.set_parameters(net_params))
def set_auto_connect(self, x: bool): def set_auto_connect(self, b: bool):
self.electrum_config.set_key('auto_connect',x) # This method makes sure we persist x into the config even if self.auto_connect == b.
self.auto_connect = x # Note: on_auto_connect() only gets called if the value of the self.auto_connect property *changes*.
self.electrum_config.set_key('auto_connect', b)
self.auto_connect = b
def toggle_auto_connect(self, x): def toggle_auto_connect(self, x):
self.auto_connect = not self.auto_connect self.auto_connect = not self.auto_connect
oneserver = BooleanProperty(False) oneserver = BooleanProperty(False)
def on_oneserver(self, instance, x): def on_oneserver(self, instance, x):
if not self._init_finished:
return
net_params = self.network.get_parameters() net_params = self.network.get_parameters()
if net_params.oneserver != self.oneserver: net_params = net_params._replace(oneserver=self.oneserver)
net_params = net_params._replace(oneserver=self.oneserver) self.network.run_from_another_thread(self.network.set_parameters(net_params))
self.network.run_from_another_thread(self.network.set_parameters(net_params))
def toggle_oneserver(self, x): def toggle_oneserver(self, x):
self.oneserver = not self.oneserver self.oneserver = not self.oneserver
@ -378,6 +382,8 @@ class ElectrumWindow(App, Logger):
:data:`ui_mode` is a read only `AliasProperty` Defaults to 'phone' :data:`ui_mode` is a read only `AliasProperty` Defaults to 'phone'
''' '''
_init_finished = False
def __init__(self, **kwargs): def __init__(self, **kwargs):
# initialize variables # initialize variables
self._clipboard = Clipboard self._clipboard = Clipboard
@ -433,6 +439,8 @@ class ElectrumWindow(App, Logger):
self.invoice_popup = None self.invoice_popup = None
self.request_popup = None self.request_popup = None
self._init_finished = True
def on_pr(self, pr: 'PaymentRequest'): def on_pr(self, pr: 'PaymentRequest'):
if not self.wallet: if not self.wallet:
self.show_error(_('No wallet loaded.')) self.show_error(_('No wallet loaded.'))
@ -648,15 +656,15 @@ class ElectrumWindow(App, Logger):
util.register_callback(self.set_unknown_channels, ['unknown_channels']) util.register_callback(self.set_unknown_channels, ['unknown_channels'])
if self.electrum_config.get('auto_connect') is None: if self.electrum_config.get('auto_connect') is None:
# load_wallet will be called in this code-path too at a later stage, after initial network setup is completed.
self.popup_dialog("first_screen") self.popup_dialog("first_screen")
# load_wallet_on_start will be called later, after initial network setup is completed
else: else:
# load wallet # load wallet
self.load_wallet_by_name(self.electrum_config.get_wallet_path(use_gui_last_wallet=True)) self.load_wallet_on_start()
# URI passed in config # URI passed in config
uri = self.electrum_config.get('url') uri = self.electrum_config.get('url')
if uri: if uri:
self.set_URI(uri) self.set_URI(uri)
def on_channel_db(self, event, num_nodes, num_channels, num_policies): def on_channel_db(self, event, num_nodes, num_channels, num_policies):
self.lightning_gossip_num_nodes = num_nodes self.lightning_gossip_num_nodes = num_nodes
@ -703,6 +711,10 @@ class ElectrumWindow(App, Logger):
d = OpenWalletDialog(self, path, self.on_open_wallet) d = OpenWalletDialog(self, path, self.on_open_wallet)
d.open() d.open()
def load_wallet_on_start(self):
"""As part of app startup, try to load last wallet."""
self.load_wallet_by_name(self.electrum_config.get_wallet_path(use_gui_last_wallet=True))
def on_open_wallet(self, password, storage): def on_open_wallet(self, password, storage):
if not storage.file_exists(): if not storage.file_exists():
wizard = InstallWizard(self.electrum_config, self.plugins) wizard = InstallWizard(self.electrum_config, self.plugins)

8
electrum/gui/kivy/uix/ui_screens/first_screen.kv

@ -43,7 +43,9 @@ Popup:
height: '48dp' height: '48dp'
text: _('Next') text: _('Next')
on_release: on_release:
app.set_auto_connect(nd.auto_connect) if nd.auto_connect else None # if user chose auto_connect==True, we persist that now;
app.load_wallet_by_name(app.electrum_config.get_wallet_path(use_gui_last_wallet=True)) if nd.auto_connect else app.popup_dialog("initial_network_setup") # if user chose auto_connect==False, that will only get saved after they finish configuring the network.
if nd.auto_connect: app.set_auto_connect(nd.auto_connect)
app.load_wallet_on_start() if nd.auto_connect else app.popup_dialog("initial_network_setup")
nd.was_cancelled = False nd.was_cancelled = False
nd.dismiss() nd.dismiss()

4
electrum/gui/kivy/uix/ui_screens/initial_network_setup.kv

@ -14,7 +14,7 @@ Popup:
height: '48dp' height: '48dp'
text: _('Next') text: _('Next')
on_release: on_release:
app.set_auto_connect(app.auto_connect) app.set_auto_connect(app.auto_connect) # make sure config setting is persisted
app.load_wallet_by_name(app.electrum_config.get_wallet_path(use_gui_last_wallet=True)) app.load_wallet_on_start()
nd.was_cancelled = False nd.was_cancelled = False
nd.dismiss() nd.dismiss()

Loading…
Cancel
Save