IPC and custom protocol handler for monero://

This commit is contained in:
dsc
2019-03-22 21:02:08 +01:00
committed by xmrdsc
parent ff6ce6294b
commit 18f2accc7f
13 changed files with 354 additions and 15 deletions

View File

@@ -399,6 +399,49 @@ ApplicationWindow {
leftPanel.balanceLabelText = qsTr("Balance (#%1%2)").arg(currentWallet.currentSubaddressAccount).arg(accountLabel === "" ? "" : (" " + accountLabel));
}
function onUriHandler(uri){
if(uri.startsWith("monero://")){
var address = uri.substring("monero://".length);
var params = {}
if(address.length === 0) return;
var spl = address.split("?");
if(spl.length > 2) return;
if(spl.length >= 1) {
// parse additional params
address = spl[0];
if(spl.length === 2){
spl.shift();
var item = spl[0];
var _spl = item.split("&");
for (var param in _spl){
var _item = _spl[param];
if(!_item.indexOf("=") > 0) continue;
var __spl = _item.split("=");
if(__spl.length !== 2) continue;
params[__spl[0]] = __spl[1];
}
}
}
// Fill fields
middlePanel.transferView.sendTo(address, params["tx_payment_id"], params["tx_description"], params["tx_amount"]);
// Raise window
appWindow.raise();
appWindow.show();
// @TODO: remove after paymentID deprecation
if(params.hasOwnProperty("tx_payment_id"))
persistentSettings.showPid = true;
}
}
function onWalletConnectionStatusChanged(status){
console.log("Wallet connection status changed " + status)
middlePanel.updateStatus();
@@ -489,6 +532,12 @@ ApplicationWindow {
// Force switch normal view
rootItem.state = "normal";
// Process queued IPC command
if(typeof IPC !== "undefined" && IPC.queuedCmd().length > 0){
var queuedCmd = IPC.queuedCmd();
if(/^\w+:\/\/(.*)$/.test(queuedCmd)) appWindow.onUriHandler(queuedCmd); // uri
}
}
function onWalletClosed(walletAddress) {
@@ -1086,6 +1135,7 @@ ApplicationWindow {
walletManager.deviceButtonPressed.connect(onDeviceButtonPressed);
walletManager.checkUpdatesComplete.connect(onWalletCheckUpdatesComplete);
walletManager.walletPassphraseNeeded.connect(onWalletPassphraseNeeded);
IPC.uriHandler.connect(onUriHandler);
if(typeof daemonManager != "undefined") {
daemonManager.daemonStarted.connect(onDaemonStarted);