Przeglądaj źródła

Linux: Don't show settings dialog always when launched twice

For #3273 #3771 #3485
See also d503221b2e22109eb9f2a3d875dcd247dd8b4cf9
Markus Goetz 10 lat temu
rodzic
commit
641dece89a
3 zmienionych plików z 14 dodań i 1 usunięć
  1. 8 0
      src/gui/application.cpp
  2. 3 0
      src/gui/application.h
  3. 3 1
      src/gui/main.cpp

+ 8 - 0
src/gui/application.cpp

@@ -101,6 +101,8 @@ Application::Application(int &argc, char **argv) :
     _userTriggeredConnect(false),
     _debugMode(false)
 {
+    _startedAt.start();
+
 // TODO: Can't set this without breaking current config pathes
 //    setOrganizationName(QLatin1String(APPLICATION_VENDOR));
     setOrganizationDomain(QLatin1String(APPLICATION_REV_DOMAIN));
@@ -301,6 +303,12 @@ void Application::slotParseMessage(const QString &msg, QObject*)
         parseOptions(options);
         setupLogging();
     } else if (msg.startsWith(QLatin1String("MSG_SHOWSETTINGS"))) {
+        qDebug() << "Running for" << _startedAt.elapsed()/1000.0 << "sec";
+        if (isSessionRestored() && _startedAt.elapsed() < 10*1000) {
+            // This call is mirrored with the one in int main()
+            qWarning() << "Ignoring MSG_SHOWSETTINGS, possibly double-invocation of client via session restore and auto start";
+            return;
+        }
         showSettingsDialog();
     }
 }

+ 3 - 0
src/gui/application.h

@@ -19,6 +19,7 @@
 #include <QPointer>
 #include <QQueue>
 #include <QTimer>
+#include <QElapsedTimer>
 
 #include "qtsingleapplication.h"
 
@@ -97,6 +98,8 @@ private:
     bool _helpOnly;
     bool _versionOnly;
 
+    QElapsedTimer _startedAt;
+
     // options from command line:
     bool _showLogWindow;
     QString _logFile;

+ 3 - 1
src/gui/main.cpp

@@ -89,6 +89,7 @@ int main(int argc, char **argv)
     if(app.isRunning()) {
         qDebug() << Q_FUNC_INFO << "Already running, exiting...";
         if (app.isSessionRestored()) {
+            // This call is mirrored with the one in Application::slotParseMessage
             qDebug() << "Session was restored, don't notify app!";
             return -1;
         }
@@ -99,8 +100,9 @@ int main(int argc, char **argv)
             if(!app.sendMessage(QLatin1String("MSG_PARSEOPTIONS:") + msg))
                 return -1;
         }
-        if(!app.sendMessage(QLatin1String("MSG_SHOWSETTINGS")))
+        if(!app.sendMessage(QLatin1String("MSG_SHOWSETTINGS"))) {
             return -1;
+        }
         return 0;
     } else {
         if (!QSystemTrayIcon::isSystemTrayAvailable()) {