mirror-chatterino2/src/widgets/dialogs/LastRunCrashDialog.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

110 lines
3 KiB
C++
Raw Normal View History

#include "widgets/dialogs/LastRunCrashDialog.hpp"
#include "common/Args.hpp"
#include "common/Literals.hpp"
#include "common/Modes.hpp"
#include "singletons/Paths.hpp"
#include "util/LayoutCreator.hpp"
#include <QDesktopServices>
2018-06-01 14:20:46 +02:00
#include <QDialogButtonBox>
#include <QDir>
2018-06-01 14:20:46 +02:00
#include <QLabel>
#include <QMessageBox>
#include <QProcess>
2018-06-01 14:20:46 +02:00
#include <QPushButton>
#include <QRandomGenerator>
#include <QStringBuilder>
2018-04-20 00:15:57 +02:00
#include <QVBoxLayout>
namespace {
using namespace chatterino::literals;
const std::initializer_list<QString> MESSAGES = {
u"Oops..."_s, u"NotLikeThis"_s,
u"NOOOOOO"_s, u"I'm sorry"_s,
u"We're sorry"_s, u"My bad"_s,
u"FailFish"_s, u"O_o"_s,
u"Sorry :("_s, u"I blame cosmic rays"_s,
u"I blame TMI"_s, u"I blame Helix"_s,
u"Oopsie woopsie"_s,
};
QString randomMessage()
{
return *(MESSAGES.begin() +
(QRandomGenerator::global()->generate64() % MESSAGES.size()));
}
} // namespace
2018-04-20 00:15:57 +02:00
namespace chatterino {
using namespace literals;
LastRunCrashDialog::LastRunCrashDialog(const Args &args)
2018-04-20 00:15:57 +02:00
{
2018-06-01 14:20:46 +02:00
this->setWindowFlag(Qt::WindowContextHelpButtonHint, false);
this->setWindowTitle(u"Chatterino - " % randomMessage());
2018-06-26 17:06:17 +02:00
auto layout =
LayoutCreator<LastRunCrashDialog>(this).setLayoutType<QVBoxLayout>();
QString text =
u"Chatterino unexpectedly crashed and restarted. "_s
"<i>You can disable automatic restarts in the settings.</i><br><br>";
#ifdef CHATTERINO_WITH_CRASHPAD
auto reportsDir =
QDir(getPaths()->crashdumpDirectory).filePath(u"reports"_s);
text += u"A <b>crash report</b> has been saved to "
"<a href=\"file:///" %
reportsDir % u"\">" % reportsDir % u"</a>.<br>";
if (args.exceptionCode)
{
text += u"The last run crashed with code <code>0x" %
QString::number(*args.exceptionCode, 16) % u"</code>";
if (args.exceptionMessage)
{
text += u" (" % *args.exceptionMessage % u")";
}
text += u".<br>"_s;
}
text +=
"Crash reports are <b>only stored locally</b> and never uploaded.<br>"
"<br>Please <a "
"href=\"https://github.com/Chatterino/chatterino2/issues/new\">report "
"the crash</a> "
u"so it can be prevented in the future."_s;
if (Modes::instance().isNightly)
{
text += u" Make sure you're using the latest nightly version!"_s;
}
text +=
u"<br>For more information, <a href=\"https://wiki.chatterino.com/Crash%20Analysis/\">consult the wiki</a>."_s;
#endif
auto label = layout.emplace<QLabel>(text);
label->setTextInteractionFlags(Qt::TextBrowserInteraction);
label->setOpenExternalLinks(true);
label->setWordWrap(true);
layout->addSpacing(16);
auto buttons = layout.emplace<QDialogButtonBox>();
auto *okButton = buttons->addButton(u"Ok"_s, QDialogButtonBox::AcceptRole);
QObject::connect(okButton, &QPushButton::clicked, [this] {
this->accept();
});
2018-04-20 00:15:57 +02:00
}
2018-04-20 00:15:57 +02:00
} // namespace chatterino