瀏覽代碼

Exit Helper after 3 minutes

On windows it was pretty annoying that the Helper hanged around forever
since it was never used there anyway. So now we hang around 3 minutes
after the main application quit and then exit from the helper.
Restarting the app resets the timer. When we have the possibility to
start the main app from the helper we need to check that setting before
starting the quit timer.
Tobias Hieta 9 年之前
父節點
當前提交
4b8796dd15
共有 2 個文件被更改,包括 19 次插入0 次删除
  1. 16 0
      src/tools/helper/HelperSocket.cpp
  2. 3 0
      src/tools/helper/HelperSocket.h

+ 16 - 0
src/tools/helper/HelperSocket.cpp

@@ -14,6 +14,13 @@
 HelperSocket::HelperSocket(QObject* parent)
 {
   m_server = new LocalJsonServer("pmpHelper", this);
+  m_quitTimer = new QTimer(this);
+
+  connect(m_quitTimer, &QTimer::timeout, []()
+  {
+    QLOG_DEBUG() << "Quit timer ran out, quitting...";
+    qApp->quit();
+  });
 
   connect(m_server, &LocalJsonServer::clientConnected, this, &HelperSocket::clientConnected);
   connect(m_server, &LocalJsonServer::messageReceived, this, &HelperSocket::message);
@@ -30,6 +37,15 @@ void HelperSocket::clientConnected(QLocalSocket* socket)
   hello.insert("version", Version::GetVersionString());
   hello.insert("path", QCoreApplication::applicationFilePath());
   m_server->sendMessage(hello, socket);
+
+  // if we are going to quit, restart the timer.
+  m_quitTimer->stop();
+
+  connect(socket, &QLocalSocket::disconnected, [=](){
+    // give us 5 minute to upload a crash log if we got one. then quit
+    QLOG_DEBUG() << "PMP application quit, let's wait 3 minutes and then exit";
+    m_quitTimer->start(3 * 60 * 1000);
+  });
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////

+ 3 - 0
src/tools/helper/HelperSocket.h

@@ -8,6 +8,8 @@
 #include "Paths.h"
 #include "LocalJsonServer.h"
 
+#include <QTimer>
+
 class HelperSocket : public QObject
 {
   Q_OBJECT
@@ -18,6 +20,7 @@ private:
   Q_SLOT void clientConnected(QLocalSocket* socket);
   Q_SLOT void message(const QVariant& message);
   LocalJsonServer* m_server;
+  QTimer* m_quitTimer;
 };
 
 #endif //KONVERGO_HELPERSOCKET_H