added basic last run crash dialog

This commit is contained in:
fourtf 2018-04-20 00:15:57 +02:00
parent 683c4aed2d
commit e17a7cc222
10 changed files with 73 additions and 10 deletions

View file

@ -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

View file

@ -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"

View file

@ -2,6 +2,7 @@
#include "singletons/nativemessagingmanager.hpp"
#include "singletons/pathmanager.hpp"
#include "util/networkmanager.hpp"
#include "widgets/lastruncrashdialog.hpp"
#include <QAbstractNativeEventFilter>
#include <QApplication>
@ -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();

View file

@ -1,6 +1,7 @@
#include "singletons/pathmanager.hpp"
#include <QCoreApplication>
#include <QCryptographicHash>
#include <QDir>
#include <QStandardPaths>
@ -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;

View file

@ -29,6 +29,8 @@ public:
QString whispersLogsFolderPath;
QString mentionsLogsFolderPath;
QString appPathHash;
bool createFolder(const QString &folderPath);
};

View file

@ -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;

View file

@ -17,7 +17,7 @@ public:
const QString &getCurrentVersion() const;
const QString &getOnlineVersion() const;
pajlada::Signals::Signal onlineVersionUpdated;
pajlada::Signals::NoArgSignal onlineVersionUpdated;
private:
QString currentVersion;

View file

@ -0,0 +1,18 @@
#include "lastruncrashdialog.hpp"
#include <QVBoxLayout>
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

View file

@ -0,0 +1,15 @@
#pragma once
#include <QDialog>
namespace chatterino {
namespace widgets {
class LastRunCrashDialog : public QDialog
{
public:
LastRunCrashDialog();
};
} // namespace widgets
} // namespace chatterino

View file

@ -51,6 +51,7 @@ AboutPage::AboutPage()
github->setOpenExternalLinks(true);
// github->setPalette(palette);
}
layout->addStretch(1);
}