code clean up and wallet close consistency

This commit is contained in:
Jaquee 2016-12-04 13:13:59 +01:00
parent ead9bd70be
commit eb97bda3a3
No known key found for this signature in database
GPG key ID: 384E52B09F45DC39
3 changed files with 20 additions and 61 deletions

View file

@ -109,30 +109,8 @@ ApplicationWindow {
ctrlPressed = false ctrlPressed = false
} }
function mousePressed(obj, mouseX, mouseY) { function mousePressed(obj, mouseX, mouseY) {}
// if(obj.objectName === "appWindow") function mouseReleased(obj, mouseX, mouseY) {}
// obj = rootItem
// var tmp = rootItem.mapFromItem(obj, mouseX, mouseY)
// if(tmp !== undefined) {
// mouseX = tmp.x
// mouseY = tmp.y
// }
// if(currentItem !== undefined) {
// var tmp_x = rootItem.mapToItem(currentItem, mouseX, mouseY).x
// var tmp_y = rootItem.mapToItem(currentItem, mouseX, mouseY).y
// if(!currentItem.containsPoint(tmp_x, tmp_y)) {
// currentItem.hide()
// currentItem = undefined
// }
// }
}
function mouseReleased(obj, mouseX, mouseY) {
}
function openWalletFromFile(){ function openWalletFromFile(){
persistentSettings.restore_height = 0 persistentSettings.restore_height = 0
@ -153,22 +131,10 @@ ApplicationWindow {
translationManager.setLanguage(locale.split("_")[0]); translationManager.setLanguage(locale.split("_")[0]);
} }
// disconnect handlers before connecting // If currentWallet exists, we're just switching daemon - close/reopen wallet
middlePanel.paymentClicked.disconnect(handlePayment); if (typeof currentWallet !== "undefined" && currentWallet !== null) {
// TODO: remove if statement when PR #111 is merged console.log("Daemon change - closing " + currentWallet)
if(typeof(handleCheckPayment) !== "undefined") { walletManager.closeWalletAsync();
middlePanel.checkPaymentClicked.disconnect(handleCheckPayment);
}
middlePanel.paymentClicked.connect(handlePayment);
middlePanel.sweepUnmixableClicked.connect(handleSweepUnmixable);
// basicPanel.paymentClicked.connect(handlePayment);
middlePanel.checkPaymentClicked.connect(handleCheckPayment);
// currentWallet is defined on daemon address change - close/reopen
// TODO: strict comparison here (!==) causes crash after passwordDialog on previously crashed unsynced wallets
if (currentWallet != undefined) {
console.log("closing currentWallet")
walletManager.closeWallet(currentWallet);
} else { } else {
// set page to transfer if not changing daemon // set page to transfer if not changing daemon
@ -216,7 +182,11 @@ ApplicationWindow {
currentWallet.moneyReceived.disconnect(onWalletMoneyReceived) currentWallet.moneyReceived.disconnect(onWalletMoneyReceived)
currentWallet.transactionCreated.disconnect(onTransactionCreated) currentWallet.transactionCreated.disconnect(onTransactionCreated)
currentWallet.connectionStatusChanged.disconnect(onWalletConnectionStatusChanged) currentWallet.connectionStatusChanged.disconnect(onWalletConnectionStatusChanged)
middlePanel.paymentClicked.disconnect(handlePayment);
middlePanel.sweepUnmixableClicked.disconnect(handleSweepUnmixable);
middlePanel.checkPaymentClicked.disconnect(handleCheckPayment);
// connect handlers
currentWallet.refreshed.connect(onWalletRefresh) currentWallet.refreshed.connect(onWalletRefresh)
currentWallet.updated.connect(onWalletUpdate) currentWallet.updated.connect(onWalletUpdate)
currentWallet.newBlock.connect(onWalletNewBlock) currentWallet.newBlock.connect(onWalletNewBlock)
@ -224,7 +194,9 @@ ApplicationWindow {
currentWallet.moneyReceived.connect(onWalletMoneyReceived) currentWallet.moneyReceived.connect(onWalletMoneyReceived)
currentWallet.transactionCreated.connect(onTransactionCreated) currentWallet.transactionCreated.connect(onTransactionCreated)
currentWallet.connectionStatusChanged.connect(onWalletConnectionStatusChanged) currentWallet.connectionStatusChanged.connect(onWalletConnectionStatusChanged)
middlePanel.paymentClicked.connect(handlePayment);
middlePanel.sweepUnmixableClicked.connect(handleSweepUnmixable);
middlePanel.checkPaymentClicked.connect(handleCheckPayment);
console.log("initializing with daemon address: ", persistentSettings.daemon_address) console.log("initializing with daemon address: ", persistentSettings.daemon_address)
console.log("Recovering from seed: ", persistentSettings.is_recovering) console.log("Recovering from seed: ", persistentSettings.is_recovering)
@ -248,7 +220,7 @@ ApplicationWindow {
if (appWindow.password === '') { if (appWindow.password === '') {
console.error("Error opening wallet with empty password: ", wallet.errorString); console.error("Error opening wallet with empty password: ", wallet.errorString);
console.log("closing wallet async : " + wallet.address) console.log("closing wallet async : " + wallet.address)
walletManager.closeWalletAsync(wallet) walletManager.closeWalletAsync()
// try to open wallet with password; // try to open wallet with password;
passwordDialog.open(wallet.path); passwordDialog.open(wallet.path);
} else { } else {
@ -259,7 +231,7 @@ ApplicationWindow {
informationPopup.text = qsTr("Couldn't open wallet: ") + wallet.errorString; informationPopup.text = qsTr("Couldn't open wallet: ") + wallet.errorString;
informationPopup.icon = StandardIcon.Critical informationPopup.icon = StandardIcon.Critical
console.log("closing wallet async : " + wallet.address) console.log("closing wallet async : " + wallet.address)
walletManager.closeWalletAsync(wallet); walletManager.closeWalletAsync();
informationPopup.open() informationPopup.open()
informationPopup.onCloseCallback = function() { informationPopup.onCloseCallback = function() {
passwordDialog.open(wallet.path) passwordDialog.open(wallet.path)
@ -619,7 +591,6 @@ ApplicationWindow {
middlePanel.enabled = enable; middlePanel.enabled = enable;
leftPanel.enabled = enable; leftPanel.enabled = enable;
rightPanel.enabled = enable; rightPanel.enabled = enable;
// basicPanel.enabled = enable;
} }
function showProcessingSplash(message) { function showProcessingSplash(message) {
@ -640,14 +611,9 @@ ApplicationWindow {
function showWizard(){ function showWizard(){
walletInitialized = false; walletInitialized = false;
splashCounter = 0; splashCounter = 0;
// we can't close async here. Gui crashes if wallet is open walletManager.closeWalletAsync();
if (currentWallet != undefined) {
walletManager.closeWallet(currentWallet);
currentWallet = undefined
}
wizard.restart(); wizard.restart();
rootItem.state = "wizard" rootItem.state = "wizard"
} }
@ -702,8 +668,6 @@ ApplicationWindow {
property bool is_recovering : false property bool is_recovering : false
} }
// TODO: replace with customized popups
// Information dialog // Information dialog
StandardDialog { StandardDialog {
// dynamically change onclose handler // dynamically change onclose handler
@ -748,7 +712,6 @@ ApplicationWindow {
id: passwordDialog id: passwordDialog
onAccepted: { onAccepted: {
appWindow.currentWallet = null
appWindow.initialize(); appWindow.initialize();
} }
onRejected: { onRejected: {
@ -1036,12 +999,8 @@ ApplicationWindow {
} }
} }
onClosing: { onClosing: {
// Make sure wallet is closed before app exit (~Wallet() isn't always invoked) // Close wallet
// Daemon shutdown is handled with signal/slot in main.cpp walletManager.closeWallet();
if (currentWallet != undefined) {
walletManager.closeWallet(currentWallet);
currentWallet = undefined
}
// Stop daemon // Stop daemon
daemonManager.stop(); daemonManager.stop();
} }

View file

@ -78,7 +78,7 @@ Item {
// Always delete the wallet object before creating new - we could be stepping back from recovering wallet // Always delete the wallet object before creating new - we could be stepping back from recovering wallet
if (typeof settingsObject.wallet !== 'undefined') { if (typeof settingsObject.wallet !== 'undefined') {
settingsObject.wallet.destroy() walletManager.closeWallet()
console.log("deleting wallet") console.log("deleting wallet")
} }

View file

@ -79,7 +79,7 @@ Item {
settingsObject['wallet'] = wallet; settingsObject['wallet'] = wallet;
settingsObject['is_recovering'] = true; settingsObject['is_recovering'] = true;
} else { } else {
walletManager.closeWallet(wallet); walletManager.closeWallet();
} }
return success; return success;
} }