mirror-chatterino2/src/main.cpp

135 lines
4.1 KiB
C++
Raw Normal View History

#include "application.hpp"
#include "singletons/nativemessagingmanager.hpp"
#include "singletons/pathmanager.hpp"
#include "util/networkmanager.hpp"
2018-04-20 00:15:57 +02:00
#include "widgets/lastruncrashdialog.hpp"
2017-01-11 01:08:20 +01:00
#include <QAbstractNativeEventFilter>
2017-01-11 01:08:20 +01:00
#include <QApplication>
2018-04-09 22:59:19 +02:00
#include <QFile>
#include <QLibrary>
2018-04-09 22:59:19 +02:00
#include <QStringList>
2018-05-23 19:42:42 +02:00
#include <QStyleFactory>
2018-04-09 22:59:19 +02:00
#ifdef USEWINSDK
#include "util/nativeeventhelper.hpp"
#endif
#include <fstream>
#include <iostream>
2018-04-09 22:59:19 +02:00
int runGui(int argc, char *argv[]);
int main(int argc, char *argv[])
2018-04-09 22:59:19 +02:00
{
// read args
QStringList args;
for (int i = 1; i < argc; i++) {
args << argv[i];
}
// TODO: can be any argument
if (args.size() > 0 && args[0].startsWith("chrome-extension://")) {
2018-05-23 12:44:01 +02:00
chatterino::Application::instantiate(argc, argv);
auto app = chatterino::getApp();
app->construct();
chatterino::Application::runNativeMessagingHost();
2018-04-09 22:59:19 +02:00
return 0;
}
// run gui
return runGui(argc, argv);
}
int runGui(int argc, char *argv[])
2016-12-29 17:31:07 +01:00
{
QApplication::setAttribute(Qt::AA_Use96Dpi, true);
#ifdef Q_OS_WIN32
QApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true);
#endif
2018-01-19 14:48:17 +01:00
// QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL, true);
2016-12-29 17:31:07 +01:00
QApplication a(argc, argv);
2016-12-30 19:20:04 +01:00
2018-05-23 19:42:42 +02:00
QApplication::setStyle(QStyleFactory::create("Fusion"));
// borrowed from
// https://stackoverflow.com/questions/15035767/is-the-qt-5-dark-fusion-theme-available-for-windows
QPalette darkPalette = a.palette();
darkPalette.setColor(QPalette::Window, QColor(33, 33, 33));
darkPalette.setColor(QPalette::WindowText, Qt::white);
darkPalette.setColor(QPalette::Text, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(127, 127, 127));
darkPalette.setColor(QPalette::Base, QColor(90, 90, 90));
darkPalette.setColor(QPalette::AlternateBase, QColor(66, 66, 66));
darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
darkPalette.setColor(QPalette::Dark, QColor(35, 35, 35));
darkPalette.setColor(QPalette::Shadow, QColor(20, 20, 20));
darkPalette.setColor(QPalette::Button, QColor(70, 70, 70));
darkPalette.setColor(QPalette::ButtonText, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127));
darkPalette.setColor(QPalette::BrightText, Qt::red);
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80));
darkPalette.setColor(QPalette::HighlightedText, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(127, 127, 127));
qApp->setPalette(darkPalette);
// Install native event handler for hidpi on windows
#ifdef USEWINSDK
a.installNativeEventFilter(new chatterino::util::DpiNativeEventFilter);
#endif
// Initialize NetworkManager
chatterino::util::NetworkManager::init();
// Initialize application
chatterino::Application::instantiate(argc, argv);
auto app = chatterino::getApp();
app->construct();
auto &pathMan = *app->paths;
2018-04-20 00:15:57 +02:00
// Running file
auto runningPath = pathMan.settingsFolderPath + "/running_" + pathMan.appPathHash;
if (QFile::exists(runningPath)) {
2018-04-22 20:48:00 +02:00
#ifndef DISABLE_CRASH_DIALOG
2018-04-20 00:15:57 +02:00
chatterino::widgets::LastRunCrashDialog dialog;
dialog.exec();
2018-04-22 20:48:00 +02:00
#endif
2018-04-20 00:15:57 +02:00
} else {
QFile runningFile(runningPath);
runningFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
runningFile.flush();
runningFile.close();
}
app->initialize();
2016-12-29 17:31:07 +01:00
// Start the application
// This is a blocking call
app->run(a);
2017-01-03 21:19:33 +01:00
// We have finished our application, make sure we save stuff
app->save();
2017-01-23 09:49:30 +01:00
2018-04-20 00:15:57 +02:00
// Running file
QFile::remove(runningPath);
// Save settings
pajlada::Settings::SettingManager::save();
// Deinitialize NetworkManager (stop thread and wait for finish, should be instant)
chatterino::util::NetworkManager::deinit();
2018-01-18 07:56:02 +01:00
_exit(0);
2016-12-29 17:31:07 +01:00
}