From 6a6982cdae016fa435973551d7e82883b94f7754 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Mon, 27 Feb 2023 12:20:51 +0100 Subject: [PATCH] qml: defer intent handling at startup, otherwise it gets lost as the app is not handling the signal yet. Also defer intent handling until a wallet is opened. --- .../gui/qml/components/WalletMainView.qml | 15 +++++++++++++++ electrum/gui/qml/qeapp.py | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/electrum/gui/qml/components/WalletMainView.qml b/electrum/gui/qml/components/WalletMainView.qml index d629cf4b7..622632150 100644 --- a/electrum/gui/qml/components/WalletMainView.qml +++ b/electrum/gui/qml/components/WalletMainView.qml @@ -14,6 +14,7 @@ Item { property string title: Daemon.currentWallet ? Daemon.currentWallet.name : '' property var _sendDialog + property string _intentUri function openInvoice(key) { var dialog = invoiceDialog.createObject(app, { invoice: invoiceParser, invoice_key: key }) @@ -229,10 +230,24 @@ Item { Connections { target: AppController function onUriReceived(uri) { + console.log('uri received: ' + uri) + if (!Daemon.currentWallet) { + console.log('No wallet open, deferring') + _intentUri = uri + return + } invoiceParser.recipient = uri } } + Connections { + target: Daemon + function onWalletLoaded() { + if (_intentUri) + invoiceParser.recipient = _intentUri + } + } + Component { id: invoiceDialog InvoiceDialog { diff --git a/electrum/gui/qml/qeapp.py b/electrum/gui/qml/qeapp.py index 43ddd78db..622d262fb 100644 --- a/electrum/gui/qml/qeapp.py +++ b/electrum/gui/qml/qeapp.py @@ -56,8 +56,6 @@ class QEAppController(BaseCrashReporter, QObject): sendingBugreportSuccess = pyqtSignal(str) sendingBugreportFailure = pyqtSignal(str) - _crash_user_text = '' - def __init__(self, qedaemon, plugins): BaseCrashReporter.__init__(self, None, None, None) QObject.__init__(self) @@ -65,6 +63,10 @@ class QEAppController(BaseCrashReporter, QObject): self._qedaemon = qedaemon self._plugins = plugins + self._crash_user_text = '' + self._app_started = False + self._intent = '' + # set up notification queue and notification_timer self.user_notification_queue = queue.Queue() self.user_notification_last_time = 0 @@ -142,15 +144,23 @@ class QEAppController(BaseCrashReporter, QObject): self.logger.error(f'unable to bind intent: {repr(e)}') def on_new_intent(self, intent): + if not self._app_started: + self._intent = intent + return + data = str(intent.getDataString()) + self.logger.debug(f'received intent: {repr(data)}') scheme = str(intent.getScheme()).lower() if scheme == BITCOIN_BIP21_URI_SCHEME or scheme == LIGHTNING_URI_SCHEME: self.uriReceived.emit(data) + def startupFinished(self): + self._app_started = True + if self._intent: + self.on_new_intent(self._intent) + @pyqtSlot(str, str) def doShare(self, data, title): - #if platform != 'android': - #return try: from jnius import autoclass, cast except ImportError: @@ -352,6 +362,7 @@ class ElectrumQmlApplication(QGuiApplication): if object is None: self._valid = False self.engine.objectCreated.disconnect(self.objectCreated) + self.appController.startupFinished() def message_handler(self, line, funct, file): # filter out common harmless messages