Browse Source

improve lightning_dialog GUI settings

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
ThomasV 6 years ago
parent
commit
32e517f407
  1. 2
      electrum/gui/qt/__init__.py
  2. 81
      electrum/gui/qt/lightning_dialog.py
  3. 5
      electrum/lnwatcher.py

2
electrum/gui/qt/__init__.py

@ -352,7 +352,7 @@ class ElectrumGui(Logger):
with self._num_wizards_lock: with self._num_wizards_lock:
if self._num_wizards_in_progress > 0 or len(self.windows) > 0: if self._num_wizards_in_progress > 0 or len(self.windows) > 0:
return return
if self.config.get('lightning'): if self.config.get('persist_daemon'):
return return
self.app.quit() self.app.quit()
self.app.setQuitOnLastWindowClosed(False) # so _we_ can decide whether to quit self.app.setQuitOnLastWindowClosed(False) # so _we_ can decide whether to quit

81
electrum/gui/qt/lightning_dialog.py

@ -31,13 +31,17 @@ from PyQt5.QtWidgets import *
import PyQt5.QtCore as QtCore import PyQt5.QtCore as QtCore
from electrum.i18n import _ from electrum.i18n import _
from .util import * from .util import HelpLabel, MyTreeView, Buttons
help_about = _("""The local watchtower will persist on this computer after you close help_local = _("""If this option is checked, Electrum will persist as a daemon after
your wallet, but it requires to be online regularly.""") you close all your wallet windows. Your local watchtower will keep
running, and it will protect your channels even if your wallet is not
open. For this to work, your computer needs to be online regularly.""")
help_remote = _(""" To setup a remote watchtower, configure a remote electrum daemon help_remote = _("""To setup a remote watchtower, you must run an Electrum daemon on a
with 'watchtower_host' and 'watchtower_port' """) computer that is always connected to the internet. Configure
'watchtower_host' and 'watchtower_port' in the remote daemon, and
enter the corresponding URL here""")
class WatcherList(MyTreeView): class WatcherList(MyTreeView):
def __init__(self, parent): def __init__(self, parent):
@ -72,8 +76,6 @@ class LightningDialog(QDialog):
self.lnwatcher = self.network.lnwatcher self.lnwatcher = self.network.lnwatcher
self.setWindowTitle(_('Lightning')) self.setWindowTitle(_('Lightning'))
self.setMinimumSize(600, 20) self.setMinimumSize(600, 20)
watchtower_url = self.config.get('watchtower_url')
self.watchtower_e = QLineEdit(watchtower_url)
self.watcher_list = WatcherList(self) self.watcher_list = WatcherList(self)
# channel_db # channel_db
network_w = QWidget() network_w = QWidget()
@ -87,29 +89,54 @@ class LightningDialog(QDialog):
self.status = QLabel('') self.status = QLabel('')
network_vbox.addWidget(self.status) network_vbox.addWidget(self.status)
network_vbox.addStretch(1) network_vbox.addStretch(1)
# local # watchtower
local_w = QWidget() watcher_w = QWidget()
vbox_local = QVBoxLayout(local_w) watcher_vbox = QVBoxLayout(watcher_w)
vbox_local.addWidget(WWLabel(help_about)) watcher_vbox.addWidget(self.watcher_list)
vbox_local.addWidget(self.watcher_list) # settings
# remote settings_w = QWidget()
remote_w = QWidget() settings_vbox = QVBoxLayout(settings_w)
vbox_remote = QVBoxLayout(remote_w) persist_cb = QCheckBox(_("Persist as daemon after GUI is closed"))
vbox_remote.addWidget(WWLabel(help_remote)) persist_cb.setToolTip(help_local)
g = QGridLayout(remote_w) persist_cb.setChecked(bool(self.config.get('persist_daemon', False)))
g.addWidget(QLabel(_('URL') + ':'), 1, 0) def on_persist_checked(v):
g.addWidget(self.watchtower_e, 1, 1) self.config.set_key('persist_daemon', v == Qt.Checked, save=True)
vbox_remote.addLayout(g) persist_cb.stateChanged.connect(on_persist_checked)
vbox_remote.addStretch(1)
remote_cb = QCheckBox(_("Use a remote watchtower"))
remote_cb.setToolTip(help_remote)
remote_cb.setChecked(bool(self.config.get('use_watchtower', False)))
def on_remote_checked(v):
self.config.set_key('use_watchtower', v == Qt.Checked, save=True)
self.watchtower_url_e.setEnabled(v == Qt.Checked)
remote_cb.stateChanged.connect(on_remote_checked)
watchtower_url = self.config.get('watchtower_url')
self.watchtower_url_e = QLineEdit(watchtower_url)
self.watchtower_url_e.setEnabled(self.config.get('use_watchtower', False))
def on_url():
url = self.watchtower_url_e.text() or None
watchtower_url = self.config.set_key('watchtower_url', url)
if url:
self.lnwatcher.set_remote_watchtower()
self.watchtower_url_e.editingFinished.connect(on_url)
g = QGridLayout(settings_w)
g.addWidget(persist_cb, 0, 0, 1, 3)
g.addWidget(remote_cb, 1, 0, 1, 3)
g.addWidget(QLabel(_('URL')), 2, 1)
g.addWidget(self.watchtower_url_e, 2, 2)
settings_vbox.addLayout(g)
settings_vbox.addStretch(1)
# tabs # tabs
tabs = QTabWidget() tabs = QTabWidget()
tabs.addTab(network_w, _('Network')) tabs.addTab(network_w, _('Network'))
tabs.addTab(local_w, _('Watchtower')) tabs.addTab(watcher_w, _('Watchtower'))
tabs.addTab(remote_w, _('Settings')) tabs.addTab(settings_w, _('Settings'))
vbox = QVBoxLayout(self) vbox = QVBoxLayout(self)
vbox.addWidget(tabs) vbox.addWidget(tabs)
b = QPushButton(_('Close')) b = QPushButton(_('Close'))
b.clicked.connect(self.on_close) b.clicked.connect(self.close)
vbox.addLayout(Buttons(b)) vbox.addLayout(Buttons(b))
self.watcher_list.update() self.watcher_list.update()
self.network.register_callback(self.update_status, ['ln_status']) self.network.register_callback(self.update_status, ['ln_status'])
@ -120,12 +147,6 @@ class LightningDialog(QDialog):
self.num_channels.setText(_(f'{known} channels')) self.num_channels.setText(_(f'{known} channels'))
self.status.setText(_(f'Requesting {unknown} channels...') if unknown else '') self.status.setText(_(f'Requesting {unknown} channels...') if unknown else '')
def on_close(self):
url = self.watchtower_e.text()
if url:
self.lnwatcher.set_remote_watchtower()
self.hide()
def is_hidden(self): def is_hidden(self):
return self.isMinimized() or self.isHidden() return self.isMinimized() or self.isHidden()

5
electrum/lnwatcher.py

@ -143,7 +143,10 @@ class LNWatcher(AddressSynchronizer):
def set_remote_watchtower(self): def set_remote_watchtower(self):
watchtower_url = self.config.get('watchtower_url') watchtower_url = self.config.get('watchtower_url')
self.watchtower = jsonrpclib.Server(watchtower_url) if watchtower_url else None try:
self.watchtower = jsonrpclib.Server(watchtower_url) if watchtower_url else None
except:
self.watchtower = None
self.watchtower_queue = asyncio.Queue() self.watchtower_queue = asyncio.Queue()
def get_num_tx(self, outpoint): def get_num_tx(self, outpoint):

Loading…
Cancel
Save