Browse Source

qml: handle bitcoin: and lightning: uri intents

patch-4
Sander van Grieken 2 years ago
parent
commit
49037ecc85
  1. 4
      contrib/android/Dockerfile
  2. 39
      electrum/gui/qml/components/WalletMainView.qml
  3. 23
      electrum/gui/qml/qeapp.py

4
contrib/android/Dockerfile

@ -175,8 +175,8 @@ RUN cd /opt \
&& git remote add sombernight https://github.com/SomberNight/python-for-android \ && git remote add sombernight https://github.com/SomberNight/python-for-android \
&& git remote add accumulator https://github.com/accumulator/python-for-android \ && git remote add accumulator https://github.com/accumulator/python-for-android \
&& git fetch --all \ && git fetch --all \
# commit: from branch sombernight/electrum_20210421d # commit: from branch accumulator/electrum_20210421d
&& git checkout "1187e179aed6fddb19bf026274ff69903d3b04b2^{commit}" \ && git checkout "a16a3dd5cf8fe0f846663bce9e248e5432dbbf2d^{commit}" \
&& python3 -m pip install --no-build-isolation --no-dependencies --user -e . && python3 -m pip install --no-build-isolation --no-dependencies --user -e .
# build env vars # build env vars

39
electrum/gui/qml/components/WalletMainView.qml

@ -12,12 +12,32 @@ Item {
property string title: Daemon.currentWallet ? Daemon.currentWallet.name : '' property string title: Daemon.currentWallet ? Daemon.currentWallet.name : ''
property var _sendDialog
function openInvoice(key) { function openInvoice(key) {
var dialog = invoiceDialog.createObject(app, { invoice: invoiceParser, invoice_key: key }) var dialog = invoiceDialog.createObject(app, { invoice: invoiceParser, invoice_key: key })
dialog.open() dialog.open()
return dialog 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 { property QtObject menu: Menu {
id: menu id: menu
MenuItem { MenuItem {
@ -136,11 +156,7 @@ Item {
Layout.preferredWidth: 1 Layout.preferredWidth: 1
icon.source: '../../icons/tab_send.png' icon.source: '../../icons/tab_send.png'
text: qsTr('Send') text: qsTr('Send')
onClicked: { onClicked: openSendDialog()
console.log('send')
_sendDialog = sendDialog.createObject(mainView, {invoiceParser: invoiceParser})
_sendDialog.open()
}
} }
Rectangle { Rectangle {
Layout.fillWidth: false Layout.fillWidth: false
@ -168,7 +184,7 @@ Item {
onValidationError: { onValidationError: {
var dialog = app.messageDialog.createObject(app, { text: message }) var dialog = app.messageDialog.createObject(app, { text: message })
dialog.closed.connect(function() { dialog.closed.connect(function() {
_sendDialog.restart() restartSendDialog()
}) })
dialog.open() dialog.open()
} }
@ -181,7 +197,7 @@ Item {
} }
} }
onValidationSuccess: { onValidationSuccess: {
_sendDialog.close() closeSendDialog()
var dialog = invoiceDialog.createObject(app, { invoice: invoiceParser }) var dialog = invoiceDialog.createObject(app, { invoice: invoiceParser })
dialog.open() dialog.open()
} }
@ -193,6 +209,13 @@ Item {
} }
} }
Connections {
target: AppController
function onUriReceived(uri) {
invoiceParser.recipient = uri
}
}
Component { Component {
id: invoiceDialog id: invoiceDialog
InvoiceDialog { InvoiceDialog {
@ -233,8 +256,6 @@ Item {
} }
} }
property var _sendDialog
Component { Component {
id: sendDialog id: sendDialog
SendDialog { SendDialog {

23
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.QtGui import QGuiApplication, QFontDatabase
from PyQt5.QtQml import qmlRegisterType, qmlRegisterUncreatableType, QQmlApplicationEngine from PyQt5.QtQml import qmlRegisterType, qmlRegisterUncreatableType, QQmlApplicationEngine
from electrum.logging import Logger, get_logger
from electrum import version 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 .qeconfig import QEConfig
from .qedaemon import QEDaemon, QEWalletListModel from .qedaemon import QEDaemon, QEWalletListModel
@ -33,6 +34,7 @@ notification = None
class QEAppController(QObject): class QEAppController(QObject):
userNotify = pyqtSignal(str) userNotify = pyqtSignal(str)
uriReceived = pyqtSignal(str)
_dummy = pyqtSignal() _dummy = pyqtSignal()
@ -56,6 +58,8 @@ class QEAppController(QObject):
self.userNotify.connect(self.notifyAndroid) self.userNotify.connect(self.notifyAndroid)
self.bindIntent()
def on_wallet_loaded(self): def on_wallet_loaded(self):
qewallet = self._qedaemon.currentWallet qewallet = self._qedaemon.currentWallet
if not qewallet: if not qewallet:
@ -105,6 +109,23 @@ class QEAppController(QObject):
except Exception as e: except Exception as e:
self.logger.error(repr(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) @pyqtSlot(str, str)
def doShare(self, data, title): def doShare(self, data, title):
#if platform != 'android': #if platform != 'android':

Loading…
Cancel
Save