From 49037ecc859a97c38c0e6b58e00a317bd187bd98 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 18 Oct 2022 18:31:59 +0200 Subject: [PATCH] qml: handle bitcoin: and lightning: uri intents --- contrib/android/Dockerfile | 4 +- .../gui/qml/components/WalletMainView.qml | 39 ++++++++++++++----- electrum/gui/qml/qeapp.py | 23 ++++++++++- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/contrib/android/Dockerfile b/contrib/android/Dockerfile index 7f81cbe0a..8e59dc8b4 100644 --- a/contrib/android/Dockerfile +++ b/contrib/android/Dockerfile @@ -175,8 +175,8 @@ RUN cd /opt \ && git remote add sombernight https://github.com/SomberNight/python-for-android \ && git remote add accumulator https://github.com/accumulator/python-for-android \ && git fetch --all \ - # commit: from branch sombernight/electrum_20210421d - && git checkout "1187e179aed6fddb19bf026274ff69903d3b04b2^{commit}" \ + # commit: from branch accumulator/electrum_20210421d + && git checkout "a16a3dd5cf8fe0f846663bce9e248e5432dbbf2d^{commit}" \ && python3 -m pip install --no-build-isolation --no-dependencies --user -e . # build env vars diff --git a/electrum/gui/qml/components/WalletMainView.qml b/electrum/gui/qml/components/WalletMainView.qml index bc7b256f2..e7eb1455b 100644 --- a/electrum/gui/qml/components/WalletMainView.qml +++ b/electrum/gui/qml/components/WalletMainView.qml @@ -12,12 +12,32 @@ Item { property string title: Daemon.currentWallet ? Daemon.currentWallet.name : '' + property var _sendDialog + function openInvoice(key) { var dialog = invoiceDialog.createObject(app, { invoice: invoiceParser, invoice_key: key }) dialog.open() return dialog } + function openSendDialog() { + _sendDialog = sendDialog.createObject(mainView, {invoiceParser: invoiceParser}) + _sendDialog.open() + } + + function closeSendDialog() { + if (_sendDialog) { + _sendDialog.close() + _sendDialog = null + } + } + + function restartSendDialog() { + if (_sendDialog) { + _sendDialog.restart() + } + } + property QtObject menu: Menu { id: menu MenuItem { @@ -136,11 +156,7 @@ Item { Layout.preferredWidth: 1 icon.source: '../../icons/tab_send.png' text: qsTr('Send') - onClicked: { - console.log('send') - _sendDialog = sendDialog.createObject(mainView, {invoiceParser: invoiceParser}) - _sendDialog.open() - } + onClicked: openSendDialog() } Rectangle { Layout.fillWidth: false @@ -168,7 +184,7 @@ Item { onValidationError: { var dialog = app.messageDialog.createObject(app, { text: message }) dialog.closed.connect(function() { - _sendDialog.restart() + restartSendDialog() }) dialog.open() } @@ -181,7 +197,7 @@ Item { } } onValidationSuccess: { - _sendDialog.close() + closeSendDialog() var dialog = invoiceDialog.createObject(app, { invoice: invoiceParser }) dialog.open() } @@ -193,6 +209,13 @@ Item { } } + Connections { + target: AppController + function onUriReceived(uri) { + invoiceParser.recipient = uri + } + } + Component { id: invoiceDialog InvoiceDialog { @@ -233,8 +256,6 @@ Item { } } - property var _sendDialog - Component { id: sendDialog SendDialog { diff --git a/electrum/gui/qml/qeapp.py b/electrum/gui/qml/qeapp.py index 5eeb016dd..273ac8e03 100644 --- a/electrum/gui/qml/qeapp.py +++ b/electrum/gui/qml/qeapp.py @@ -7,8 +7,9 @@ from PyQt5.QtCore import pyqtSlot, pyqtSignal, pyqtProperty, QObject, QUrl, QLoc from PyQt5.QtGui import QGuiApplication, QFontDatabase from PyQt5.QtQml import qmlRegisterType, qmlRegisterUncreatableType, QQmlApplicationEngine -from electrum.logging import Logger, get_logger from electrum import version +from electrum.logging import Logger, get_logger +from electrum.util import BITCOIN_BIP21_URI_SCHEME, LIGHTNING_URI_SCHEME from .qeconfig import QEConfig from .qedaemon import QEDaemon, QEWalletListModel @@ -33,6 +34,7 @@ notification = None class QEAppController(QObject): userNotify = pyqtSignal(str) + uriReceived = pyqtSignal(str) _dummy = pyqtSignal() @@ -56,6 +58,8 @@ class QEAppController(QObject): self.userNotify.connect(self.notifyAndroid) + self.bindIntent() + def on_wallet_loaded(self): qewallet = self._qedaemon.currentWallet if not qewallet: @@ -105,6 +109,23 @@ class QEAppController(QObject): except Exception as e: self.logger.error(repr(e)) + def bindIntent(self): + try: + from android import activity + from jnius import autoclass + PythonActivity = autoclass('org.kivy.android.PythonActivity') + mactivity = PythonActivity.mActivity + self.on_new_intent(mactivity.getIntent()) + activity.bind(on_new_intent=self.on_new_intent) + except Exception as e: + self.logger.error(f'unable to bind intent: {repr(e)}') + + def on_new_intent(self, intent): + data = str(intent.getDataString()) + scheme = str(intent.getScheme()).lower() + if scheme == BITCOIN_BIP21_URI_SCHEME or scheme == LIGHTNING_URI_SCHEME: + self.uriReceived.emit(data) + @pyqtSlot(str, str) def doShare(self, data, title): #if platform != 'android':