2018-08-02 14:23:27 +02:00
|
|
|
#include "RunGui.hpp"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QPalette>
|
|
|
|
#include <QStyleFactory>
|
|
|
|
|
|
|
|
#include "Application.hpp"
|
|
|
|
#include "common/NetworkManager.hpp"
|
|
|
|
#include "singletons/Paths.hpp"
|
|
|
|
#include "singletons/Updates.hpp"
|
2019-08-25 22:58:19 +02:00
|
|
|
#include "util/CombinePath.hpp"
|
2018-08-02 14:23:27 +02:00
|
|
|
#include "widgets/dialogs/LastRunCrashDialog.hpp"
|
|
|
|
|
2018-10-09 18:37:51 +02:00
|
|
|
#ifdef USEWINSDK
|
|
|
|
# include "util/WindowsHelper.hpp"
|
|
|
|
#endif
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
#ifdef C_USE_BREAKPAD
|
2018-08-15 22:46:20 +02:00
|
|
|
# include <QBreakpadHandler.h>
|
2018-08-02 14:23:27 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// void initQt();
|
|
|
|
// void installCustomPalette();
|
|
|
|
// void showLastCrashDialog();
|
|
|
|
// void createRunningFile(const QString &path);
|
|
|
|
// void removeRunningFile(const QString &path);
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
namespace {
|
2018-08-15 22:46:20 +02:00
|
|
|
void installCustomPalette()
|
|
|
|
{
|
|
|
|
// borrowed from
|
|
|
|
// https://stackoverflow.com/questions/15035767/is-the-qt-5-dark-fusion-theme-available-for-windows
|
|
|
|
auto dark = qApp->palette();
|
|
|
|
|
|
|
|
dark.setColor(QPalette::Window, QColor(22, 22, 22));
|
|
|
|
dark.setColor(QPalette::WindowText, Qt::white);
|
|
|
|
dark.setColor(QPalette::Text, Qt::white);
|
|
|
|
dark.setColor(QPalette::Disabled, QPalette::WindowText,
|
|
|
|
QColor(127, 127, 127));
|
|
|
|
dark.setColor(QPalette::Base, QColor("#333"));
|
|
|
|
dark.setColor(QPalette::AlternateBase, QColor("#444"));
|
|
|
|
dark.setColor(QPalette::ToolTipBase, Qt::white);
|
|
|
|
dark.setColor(QPalette::ToolTipText, Qt::white);
|
|
|
|
dark.setColor(QPalette::Disabled, QPalette::Text,
|
|
|
|
QColor(127, 127, 127));
|
|
|
|
dark.setColor(QPalette::Dark, QColor(35, 35, 35));
|
|
|
|
dark.setColor(QPalette::Shadow, QColor(20, 20, 20));
|
|
|
|
dark.setColor(QPalette::Button, QColor(70, 70, 70));
|
|
|
|
dark.setColor(QPalette::ButtonText, Qt::white);
|
|
|
|
dark.setColor(QPalette::Disabled, QPalette::ButtonText,
|
|
|
|
QColor(127, 127, 127));
|
|
|
|
dark.setColor(QPalette::BrightText, Qt::red);
|
|
|
|
dark.setColor(QPalette::Link, QColor(42, 130, 218));
|
|
|
|
dark.setColor(QPalette::Highlight, QColor(42, 130, 218));
|
|
|
|
dark.setColor(QPalette::Disabled, QPalette::Highlight,
|
|
|
|
QColor(80, 80, 80));
|
|
|
|
dark.setColor(QPalette::HighlightedText, Qt::white);
|
|
|
|
dark.setColor(QPalette::Disabled, QPalette::HighlightedText,
|
|
|
|
QColor(127, 127, 127));
|
|
|
|
|
|
|
|
qApp->setPalette(dark);
|
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
void initQt()
|
|
|
|
{
|
|
|
|
// set up the QApplication flags
|
|
|
|
QApplication::setAttribute(Qt::AA_Use96Dpi, true);
|
2018-08-02 14:23:27 +02:00
|
|
|
#ifdef Q_OS_WIN32
|
2018-08-15 22:46:20 +02:00
|
|
|
QApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true);
|
2018-08-02 14:23:27 +02:00
|
|
|
#endif
|
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
QApplication::setStyle(QStyleFactory::create("Fusion"));
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
installCustomPalette();
|
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
void showLastCrashDialog()
|
|
|
|
{
|
2019-08-18 20:14:00 +02:00
|
|
|
//#ifndef C_DISABLE_CRASH_DIALOG
|
|
|
|
// LastRunCrashDialog dialog;
|
|
|
|
|
|
|
|
// switch (dialog.exec())
|
|
|
|
// {
|
|
|
|
// case QDialog::Accepted:
|
|
|
|
// {
|
|
|
|
// };
|
|
|
|
// break;
|
|
|
|
// default:
|
|
|
|
// {
|
|
|
|
// _exit(0);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//#endif
|
2018-08-15 22:46:20 +02:00
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
void createRunningFile(const QString &path)
|
|
|
|
{
|
|
|
|
QFile runningFile(path);
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
runningFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
|
|
|
runningFile.flush();
|
|
|
|
runningFile.close();
|
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
void removeRunningFile(const QString &path)
|
|
|
|
{
|
|
|
|
QFile::remove(path);
|
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void runGui(QApplication &a, Paths &paths, Settings &settings)
|
|
|
|
{
|
2018-08-07 08:12:44 +02:00
|
|
|
initQt();
|
|
|
|
|
2019-08-25 22:58:19 +02:00
|
|
|
auto thread = std::thread([dir = paths.miscDirectory] {
|
|
|
|
{
|
|
|
|
auto path = combinePath(dir, "Update.exe");
|
|
|
|
if (QFile::exists(path))
|
|
|
|
{
|
|
|
|
QFile::remove(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto path = combinePath(dir, "update.zip");
|
|
|
|
if (QFile::exists(path))
|
|
|
|
{
|
|
|
|
QFile::remove(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
chatterino::NetworkManager::init();
|
|
|
|
chatterino::Updates::getInstance().checkForUpdates();
|
|
|
|
|
|
|
|
#ifdef C_USE_BREAKPAD
|
2018-08-12 12:56:28 +02:00
|
|
|
QBreakpadInstance.setDumpPath(getPaths()->settingsFolderPath + "/Crashes");
|
2018-08-02 14:23:27 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Running file
|
2018-08-06 21:17:03 +02:00
|
|
|
auto runningPath =
|
|
|
|
paths.miscDirectory + "/running_" + paths.applicationFilePathHash;
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (QFile::exists(runningPath))
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
showLastCrashDialog();
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
createRunningFile(runningPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
Application app(settings, paths);
|
|
|
|
app.initialize(settings, paths);
|
|
|
|
app.run(a);
|
|
|
|
app.save();
|
|
|
|
|
|
|
|
removeRunningFile(runningPath);
|
|
|
|
|
|
|
|
pajlada::Settings::SettingManager::gSave();
|
|
|
|
|
|
|
|
chatterino::NetworkManager::deinit();
|
|
|
|
|
2018-10-09 18:37:51 +02:00
|
|
|
#ifdef USEWINSDK
|
2018-10-21 13:43:02 +02:00
|
|
|
// flushing windows clipboard to keep copied messages
|
2018-10-09 18:37:51 +02:00
|
|
|
flushClipboard();
|
|
|
|
#endif
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
_exit(0);
|
|
|
|
}
|
|
|
|
} // namespace chatterino
|