Parcourir la source

Improve fatal error handling better.

We now have a dialog that can reset the configuration to the defaults
when we encounter a fatal error.
Tobias Hieta il y a 8 ans
Parent
commit
8a79ee7db7

+ 4 - 3
src/main.cpp

@@ -20,6 +20,7 @@
 #include "settings/SettingsSection.h"
 #include "ui/KonvergoWindow.h"
 #include "ui/KonvergoEngine.h"
+#include "ui/ErrorMessage.h"
 #include "UniqueApplication.h"
 #include "utils/HelperLauncher.h"
 #include "utils/Log.h"
@@ -224,11 +225,11 @@ int main(int argc, char *argv[])
     QLOG_FATAL() << "Unhandled FatalException:" << qPrintable(e.message());
     QApplication errApp(argc, argv);
 
-    QErrorMessage* msg = new QErrorMessage;
-    msg->showMessage("Plex Media Player encountered a fatal error and will now quit: " + e.message());
-    QObject::connect(msg, &QErrorMessage::finished, []() { qApp->exit(1); });
+    ErrorMessage* msg = new ErrorMessage(e.message(), true);
+    msg->show();
 
     errApp.exec();
+
     return 1;
   }
 }

+ 8 - 1
src/settings/SettingsComponent.cpp

@@ -588,5 +588,12 @@ void SettingsComponent::setUserRoleList(const QStringList& userRoles)
   }
 
   updatePossibleValues(SETTINGS_SECTION_MAIN, "updateChannel", values);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+bool SettingsComponent::resetAndSaveOldConfiguration()
+{
+  QFile settingsFile(Paths::dataDir("plexmediaplayer.conf"));
+  return settingsFile.rename(Paths::dataDir("plexmediaplayer.conf.old"));
+}
 
-}

+ 6 - 0
src/settings/SettingsComponent.h

@@ -69,8 +69,14 @@ public:
 
   // A hack to load a value from the config file at very early init time, before
   // the SettingsComponent is created.
+  //
   static QVariant readPreinitValue(const QString& sectionID, const QString& key);
 
+  // Moves the current settings file to plexmediaplayer.conf.old to make way for new
+  // configuration.
+  //
+  static bool resetAndSaveOldConfiguration();
+
 private:
   explicit SettingsComponent(QObject *parent = 0);
   bool loadDescription();

+ 1 - 1
src/system/SystemComponent.h

@@ -23,7 +23,7 @@ public:
 
   Q_INVOKABLE QVariantMap systemInformation() const;
   Q_INVOKABLE void exit();
-  Q_INVOKABLE void restart();
+  Q_INVOKABLE static void restart();
 
   Q_INVOKABLE void info(QString text);
 

+ 50 - 0
src/ui/ErrorMessage.cpp

@@ -0,0 +1,50 @@
+//
+// Created by Tobias Hieta on 18/03/16.
+//
+
+#include <QCoreApplication>
+#include <QPushButton>
+#include <QDesktopServices>
+
+#include "system/SystemComponent.h"
+#include "settings/SettingsComponent.h"
+#include "ErrorMessage.h"
+
+/////////////////////////////////////////////////////////////////////////////////////////
+ErrorMessage::ErrorMessage(const QString& errorMessage, bool allowResetConfig)
+  : QMessageBox(nullptr)
+{
+  setIcon(Critical);
+  setText("Plex Media Player encountered a fatal error and must exit");
+  setDetailedText(errorMessage);
+  setInformativeText("Press help below to be redirected to our friendly support forums." \
+                     "Press reset to reset configuration to the default and try again." \
+                     "Press abort to exit.");
+  setWindowTitle("PMP Fatal Error!");
+
+  auto exitButton = addButton(Abort);
+  auto helpButton = addButton(Help);
+
+  QPushButton* resetButton = nullptr;
+  if (allowResetConfig)
+    resetButton = addButton(Reset);
+
+  connect(this, &QMessageBox::buttonClicked, [=](QAbstractButton* button)
+  {
+    if (button == exitButton)
+    {
+      qApp->quit();
+    }
+    else if (button == resetButton)
+    {
+      SettingsComponent::resetAndSaveOldConfiguration();
+      SystemComponent::restart();
+    }
+    else if (button == helpButton)
+    {
+      QDesktopServices::openUrl(QUrl("https://forums.plex.tv/categories/plex-media-player"));
+    }
+  });
+}
+
+

+ 17 - 0
src/ui/ErrorMessage.h

@@ -0,0 +1,17 @@
+//
+// Created by Tobias Hieta on 18/03/16.
+//
+
+#ifndef PLEXMEDIAPLAYER_ERRORMESSAGE_H
+#define PLEXMEDIAPLAYER_ERRORMESSAGE_H
+
+#include <QMessageBox>
+
+class ErrorMessage : public QMessageBox
+{
+  Q_OBJECT
+public:
+  explicit ErrorMessage(const QString& errorMessage, bool allowResetConfig = false);
+};
+
+#endif //PLEXMEDIAPLAYER_ERRORMESSAGE_H