1
mirror of https://github.com/monero-project/monero-gui synced 2024-11-24 11:17:15 +01:00

confirm daemon running on exit

This commit is contained in:
Jaquee 2017-03-01 22:03:50 +01:00
parent 988e299290
commit bce496b8d1
6 changed files with 76 additions and 4 deletions

14
MainApp.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "MainApp.h"
#include <QCloseEvent>
bool MainApp::event (QEvent *event)
{
// Catch application exit event and signal to qml app to handle exit
if(event->type() == QEvent::Close) {
event->ignore();
emit closing();
return true;
}
return false;
}

18
MainApp.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef MAINAPP_H
#define MAINAPP_H
#include <QApplication>
class MainApp : public QApplication
{
Q_OBJECT
public:
MainApp(int &argc, char** argv) : QApplication(argc, argv) {};
private:
bool event(QEvent *e);
signals:
void closing();
};
#endif // MAINAPP_H

View File

@ -45,6 +45,9 @@ Window {
property alias cancelVisible: cancelButton.visible
property alias okVisible: okButton.visible
property alias textArea: dialogContent
property alias okText: okButton.text
property alias cancelText: cancelButton.text
property var icon
// same signals as Dialog has

View File

@ -50,6 +50,7 @@
#include "AddressBook.h"
#include "model/AddressBookModel.h"
#include "wallet/wallet2_api.h"
#include "MainApp.h"
// IOS exclusions
#ifndef Q_OS_IOS
@ -74,7 +75,7 @@ int main(int argc, char *argv[])
Monero::Wallet::init(argv[0], "monero-wallet-gui");
qInstallMessageHandler(messageHandler);
QApplication app(argc, argv);
MainApp app(argc, argv);
qDebug() << "app startd";
@ -146,6 +147,8 @@ int main(int argc, char *argv[])
engine.addImageProvider(QLatin1String("qrcode"), new QRCodeImageProvider());
const QStringList arguments = QCoreApplication::arguments();
engine.rootContext()->setContextProperty("mainApp", &app);
// Exclude daemon manager from IOS
#ifndef Q_OS_IOS
DaemonManager * daemonManager = DaemonManager::instance(&arguments);
@ -210,4 +213,3 @@ int main(int argc, char *argv[])
return app.exec();
}

View File

@ -686,6 +686,7 @@ ApplicationWindow {
informationPopup.title = qsTr("Error") + translationManager.emptyString;
informationPopup.text = "internal error";
informationPopup.icon = StandardIcon.Critical
informationPopup.onCloseCallback = null
informationPopup.open()
return
}
@ -792,6 +793,9 @@ ApplicationWindow {
daemonManager.daemonStartFailure.connect(onDaemonStartFailure);
daemonManager.daemonStopped.connect(onDaemonStopped);
// Connect app exit to qml window exit handling
mainApp.closing.connect(appWindow.close);
if(!walletsFound()) {
rootItem.state = "wizard"
} else {
@ -1249,10 +1253,39 @@ ApplicationWindow {
id: notifier
}
}
onClosing: {
// If daemon is running - prompt user before exiting
if(typeof daemonManager != undefined && daemonManager.running(persistentSettings.testnet)) {
close.accepted = false;
// Show confirmation dialog
confirmationDialog.title = qsTr("Daemon is running") + translationManager.emptyString;
confirmationDialog.text = qsTr("Daemon will still be running in background when GUI is closed.");
confirmationDialog.icon = StandardIcon.Question
confirmationDialog.cancelText = qsTr("Stop daemon")
confirmationDialog.onAcceptedCallback = function() {
closeAccepted();
}
confirmationDialog.onRejectedCallback = function() {
daemonManager.stop(persistentSettings.testnet);
closeAccepted();
};
confirmationDialog.open()
} else {
closeAccepted();
}
}
function closeAccepted(){
// Close wallet non async on exit
daemonManager.exit();
walletManager.closeWallet();
Qt.quit();
}
function checkUpdates() {

View File

@ -38,7 +38,8 @@ HEADERS += \
src/libwalletqt/AddressBook.h \
src/zxcvbn-c/zxcvbn.h \
src/libwalletqt/UnsignedTransaction.h \
src/QR-Code-scanner/QrCodeScanner.h
src/QR-Code-scanner/QrCodeScanner.h \
MainApp.h
SOURCES += main.cpp \
filter.cpp \
@ -61,7 +62,8 @@ SOURCES += main.cpp \
src/libwalletqt/AddressBook.cpp \
src/zxcvbn-c/zxcvbn.c \
src/libwalletqt/UnsignedTransaction.cpp \
src/QR-Code-scanner/QrCodeScanner.cpp
src/QR-Code-scanner/QrCodeScanner.cpp \
MainApp.cpp
!ios {
HEADERS += src/daemon/DaemonManager.h