From e17a7cc22249731c2d8f8d600d00ad568066c1bf Mon Sep 17 00:00:00 2001 From: fourtf Date: Fri, 20 Apr 2018 00:15:57 +0200 Subject: [PATCH] added basic last run crash dialog --- chatterino.pro | 6 ++++-- src/application.cpp | 1 + src/main.cpp | 20 ++++++++++++++++++++ src/singletons/pathmanager.cpp | 9 +++++++++ src/singletons/pathmanager.hpp | 2 ++ src/singletons/updatemanager.cpp | 9 ++------- src/singletons/updatemanager.hpp | 2 +- src/widgets/lastruncrashdialog.cpp | 18 ++++++++++++++++++ src/widgets/lastruncrashdialog.hpp | 15 +++++++++++++++ src/widgets/settingspages/aboutpage.cpp | 1 + 10 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 src/widgets/lastruncrashdialog.cpp create mode 100644 src/widgets/lastruncrashdialog.hpp diff --git a/chatterino.pro b/chatterino.pro index 10d5c130c..bd11290ac 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -180,7 +180,8 @@ SOURCES += \ src/singletons/helper/pubsubhelpers.cpp \ src/singletons/helper/pubsubactions.cpp \ src/widgets/selectchanneldialog.cpp \ - src/singletons/updatemanager.cpp + src/singletons/updatemanager.cpp \ + src/widgets/lastruncrashdialog.cpp HEADERS += \ src/precompiled_header.hpp \ @@ -303,7 +304,8 @@ HEADERS += \ src/singletons/helper/pubsubhelpers.hpp \ src/singletons/helper/pubsubactions.hpp \ src/widgets/selectchanneldialog.hpp \ - src/singletons/updatemanager.hpp + src/singletons/updatemanager.hpp \ + src/widgets/lastruncrashdialog.hpp RESOURCES += \ resources/resources.qrc diff --git a/src/application.cpp b/src/application.cpp index f18b80739..925b3c67f 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -5,6 +5,7 @@ #include "singletons/emotemanager.hpp" #include "singletons/loggingmanager.hpp" #include "singletons/nativemessagingmanager.hpp" +#include "singletons/pathmanager.hpp" #include "singletons/pubsubmanager.hpp" #include "singletons/settingsmanager.hpp" #include "singletons/thememanager.hpp" diff --git a/src/main.cpp b/src/main.cpp index f8e81b63a..ebc7be590 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "singletons/nativemessagingmanager.hpp" #include "singletons/pathmanager.hpp" #include "util/networkmanager.hpp" +#include "widgets/lastruncrashdialog.hpp" #include #include @@ -76,6 +77,22 @@ int runGui(int argc, char *argv[]) // Initialize NetworkManager chatterino::util::NetworkManager::init(); + // Running file + auto &pathMan = chatterino::singletons::PathManager::getInstance(); + auto runningPath = pathMan.settingsFolderPath + "/running_" + pathMan.appPathHash; + + if (QFile::exists(runningPath)) { + chatterino::widgets::LastRunCrashDialog dialog; + dialog.exec(); + } else { + QFile runningFile(runningPath); + + runningFile.open(QIODevice::WriteOnly | QIODevice::Truncate); + runningFile.flush(); + runningFile.close(); + } + + // Application { // Initialize application chatterino::Application app; @@ -86,6 +103,9 @@ int runGui(int argc, char *argv[]) // Application will go out of scope here and deinitialize itself } + // Running file + QFile::remove(runningPath); + // Save settings pajlada::Settings::SettingManager::save(); diff --git a/src/singletons/pathmanager.cpp b/src/singletons/pathmanager.cpp index 9d6e73155..3fd3f6dc6 100644 --- a/src/singletons/pathmanager.cpp +++ b/src/singletons/pathmanager.cpp @@ -1,6 +1,7 @@ #include "singletons/pathmanager.hpp" #include +#include #include #include @@ -15,6 +16,14 @@ PathManager &PathManager::getInstance() bool PathManager::init(int argc, char **argv) { + // hash of app path + this->appPathHash = QCryptographicHash::hash(QCoreApplication::applicationFilePath().toUtf8(), + QCryptographicHash::Sha224) + .toBase64() + .mid(0, 32) + .replace("+", "-") + .replace("/", "x"); + // Options bool portable = false; diff --git a/src/singletons/pathmanager.hpp b/src/singletons/pathmanager.hpp index c4e6875d8..10ba3ab62 100644 --- a/src/singletons/pathmanager.hpp +++ b/src/singletons/pathmanager.hpp @@ -29,6 +29,8 @@ public: QString whispersLogsFolderPath; QString mentionsLogsFolderPath; + QString appPathHash; + bool createFolder(const QString &folderPath); }; diff --git a/src/singletons/updatemanager.cpp b/src/singletons/updatemanager.cpp index 4c7a5d4c7..87f312525 100644 --- a/src/singletons/updatemanager.cpp +++ b/src/singletons/updatemanager.cpp @@ -33,13 +33,8 @@ void UpdateManager::checkForUpdates() util::NetworkRequest req(url); req.setTimeout(20000); - req.getJSON([this](QJsonDocument &document) { - if (document.isEmpty()) { - qDebug() << "error updating"; - return; - } - - QJsonValue version_val = document.object().value("version"); + req.getJSON([this](QJsonObject &object) { + QJsonValue version_val = object.value("version"); if (!version_val.isString()) { qDebug() << "error updating"; return; diff --git a/src/singletons/updatemanager.hpp b/src/singletons/updatemanager.hpp index 3f4bba2b1..a52a88d23 100644 --- a/src/singletons/updatemanager.hpp +++ b/src/singletons/updatemanager.hpp @@ -17,7 +17,7 @@ public: const QString &getCurrentVersion() const; const QString &getOnlineVersion() const; - pajlada::Signals::Signal onlineVersionUpdated; + pajlada::Signals::NoArgSignal onlineVersionUpdated; private: QString currentVersion; diff --git a/src/widgets/lastruncrashdialog.cpp b/src/widgets/lastruncrashdialog.cpp new file mode 100644 index 000000000..8568e34e1 --- /dev/null +++ b/src/widgets/lastruncrashdialog.cpp @@ -0,0 +1,18 @@ +#include "lastruncrashdialog.hpp" + +#include + +namespace chatterino { +namespace widgets { + +LastRunCrashDialog::LastRunCrashDialog() +{ + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget( + new QLabel("The application wasn't terminated properly last time it was executed.")); + + this->setLayout(layout); +} + +} // namespace widgets +} // namespace chatterino diff --git a/src/widgets/lastruncrashdialog.hpp b/src/widgets/lastruncrashdialog.hpp new file mode 100644 index 000000000..03b07ca18 --- /dev/null +++ b/src/widgets/lastruncrashdialog.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace chatterino { +namespace widgets { + +class LastRunCrashDialog : public QDialog +{ +public: + LastRunCrashDialog(); +}; + +} // namespace widgets +} // namespace chatterino diff --git a/src/widgets/settingspages/aboutpage.cpp b/src/widgets/settingspages/aboutpage.cpp index a9398dd74..fac0a3f35 100644 --- a/src/widgets/settingspages/aboutpage.cpp +++ b/src/widgets/settingspages/aboutpage.cpp @@ -51,6 +51,7 @@ AboutPage::AboutPage() github->setOpenExternalLinks(true); // github->setPalette(palette); } + layout->addStretch(1); }