Преглед на файлове

Fixed Disconnect on closing the GUI

Cyamond преди 5 години
родител
ревизия
3579a3190e
променени са 5 файла, в които са добавени 22 реда и са изтрити 28 реда
  1. 1 1
      gui/src/SwitchIpPopupForm.ui.qml
  2. 4 6
      gui/src/main.cpp
  3. 0 4
      gui/src/main.qml
  4. 15 12
      gui/src/qmlhandler.cpp
  5. 2 5
      gui/src/qmlhandler.h

+ 1 - 1
gui/src/SwitchIpPopupForm.ui.qml

@@ -74,7 +74,7 @@ Popup {
                     // @disable-check M223
                     if (switchIpInput.acceptableInput) {
                         // @disable-check M222
-                        _qmlHandler.onSwitchPopupEnterIp(popupIpInput.text)
+                        _qmlHandler.onSwitchPopupEnterIp(switchIpInput.text)
                         // @disable-check M222
                         popup.close()
                     }

+ 4 - 6
gui/src/main.cpp

@@ -18,10 +18,6 @@
 using namespace std;
 
 int main(int argc, char *argv[]) {
-  qInfo() << "Program Start";
-
-  // ########## Load GUI ##########
-
   QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
 
   // This has to be here to fix warnings
@@ -39,7 +35,9 @@ int main(int argc, char *argv[]) {
 
   QObject *object = component.create();
 
-  app.setQuitOnLastWindowClosed(false);
+  int ret = app.exec();
+
+  qmlHandler.onExit();
 
-  return app.exec();
+  return ret;
 }

+ 0 - 4
gui/src/main.qml

@@ -87,8 +87,4 @@ ApplicationWindow {
       swipeView.interactive = false
       ipDialog.open()
     }
-
-    onClosing: {
-      _qmlHandler.onClosing();
-    }
 }

+ 15 - 12
gui/src/qmlhandler.cpp

@@ -7,6 +7,7 @@
 #include <sys/wait.h>
 #include <thread>
 #include <unistd.h>
+#include <QGuiApplication>
 
 #include "qmlhandler.h"
 #include <boost/asio.hpp>
@@ -21,12 +22,20 @@ int inpipefd[2];
 int outpipefd[2];
 char buf[1024];
 
+bool programActive = true;
+
+void QMLHandler::onExit() {
+  write(outpipefd[1], "disconnect\n", strlen("disconnect\n"));
+}
+
 void QMLHandler::handleJSON(string buffer) {
   Json::Value root;
-  Json::Reader reader;
+  Json::CharReaderBuilder builder;
+  Json::CharReader * reader = builder.newCharReader();
+  string jsonError;
+
+  bool parsingSuccessful = reader->parse(buffer.c_str(), buffer.c_str() + buffer.size(), &root, &jsonError);
 
-  bool parsingSuccessful = reader.parse(buffer, root);
-  qInfo() << parsingSuccessful;
   if (!parsingSuccessful) {
     return;
   }
@@ -38,7 +47,7 @@ void QMLHandler::handleJSON(string buffer) {
   }
 
   else if (cmd == "close") {
-    exit(0);
+    programActive = false;
   }
 }
 
@@ -49,7 +58,7 @@ void QMLHandler::readPipeLoop() {
   inPipeStatus.fd = inpipefd[0];
   inPipeStatus.events = POLLIN;
 
-  while (true) {
+  while (programActive) {
     poll(&inPipeStatus, 1, 100);
 
     if (inPipeStatus.revents & POLLIN) {
@@ -79,12 +88,6 @@ void QMLHandler::readPipeLoop() {
 
 QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
 
-// Main
-void QMLHandler::onClosing() {
-  qInfo() << "Closing";
-  write(outpipefd[1], "disconnect\n", strlen("disconnect\n"));
-}
-
 // Sending
 void QMLHandler::onSendingSelectFileButton(QUrl url) {
   emit log("File Selected: " + url.toString());
@@ -114,7 +117,7 @@ void QMLHandler::onIpPopupEnterIp(QString ip) {
     // Child
     dup2(outpipefd[0], STDIN_FILENO);
     dup2(inpipefd[1], STDOUT_FILENO);
-    dup2(inpipefd[1], STDERR_FILENO);
+    //dup2(inpipefd[1], STDERR_FILENO);
 
     // ask kernel to deliver SIGTERM in case the parent dies
     prctl(PR_SET_PDEATHSIG, SIGTERM);

+ 2 - 5
gui/src/qmlhandler.h

@@ -12,11 +12,11 @@ class QMLHandler : public QObject {
 
 private:
   void handleJSON(std::string buffer);
+  void readPipeLoop();
 
 public:
   explicit QMLHandler(QObject *parent = 0);
-  void readPipeLoop();
-  void serverStatusLoop();
+  void onExit();
 
 signals:
   // Sending
@@ -39,9 +39,6 @@ signals:
   void footerSetStatus(QString status);
 
 public slots:
-  // Main
-  void onClosing();
-
   // Sending
   void onSendingSelectFileButton(QUrl url);
   void onSendingSendFileButton();