2017-06-13 21:13:58 +02:00
|
|
|
#include "application.hpp"
|
2018-04-12 00:09:16 +02:00
|
|
|
#include "singletons/nativemessagingmanager.hpp"
|
2018-01-05 02:23:49 +01:00
|
|
|
#include "singletons/pathmanager.hpp"
|
2018-04-12 00:09:16 +02:00
|
|
|
#include "util/networkmanager.hpp"
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-09-21 17:34:41 +02:00
|
|
|
#include <QAbstractNativeEventFilter>
|
2017-01-11 01:08:20 +01:00
|
|
|
#include <QApplication>
|
2018-04-09 22:59:19 +02:00
|
|
|
#include <QFile>
|
2017-09-21 17:34:41 +02:00
|
|
|
#include <QLibrary>
|
2018-04-09 22:59:19 +02:00
|
|
|
#include <QStringList>
|
|
|
|
|
2017-09-21 17:34:41 +02:00
|
|
|
#ifdef USEWINSDK
|
2017-12-19 01:32:06 +01:00
|
|
|
#include "util/nativeeventhelper.hpp"
|
2017-09-21 17:34:41 +02:00
|
|
|
#endif
|
|
|
|
|
2018-04-12 00:09:16 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
2018-04-09 22:59:19 +02:00
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
2018-04-12 00:09:16 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <stdio.h>
|
2018-04-09 22:59:19 +02:00
|
|
|
#endif
|
|
|
|
|
2018-04-14 22:31:31 +02:00
|
|
|
bool isBigEndian()
|
|
|
|
{
|
|
|
|
int test = 1;
|
|
|
|
char *p = (char *)&test;
|
|
|
|
|
|
|
|
return p[0] == 0;
|
|
|
|
}
|
|
|
|
|
2018-04-09 22:59:19 +02:00
|
|
|
void runNativeMessagingHost();
|
|
|
|
int runGui(int argc, char *argv[]);
|
|
|
|
|
2017-04-13 18:51:46 +02:00
|
|
|
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://")) {
|
|
|
|
runNativeMessagingHost();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// run gui
|
|
|
|
return runGui(argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
int runGui(int argc, char *argv[])
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2017-12-23 21:18:13 +01:00
|
|
|
QApplication::setAttribute(Qt::AA_Use96Dpi, true);
|
2018-01-11 20:16:25 +01:00
|
|
|
#ifdef Q_OS_WIN32
|
2017-12-23 21:18:13 +01:00
|
|
|
QApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true);
|
2018-01-11 20:16:25 +01:00
|
|
|
#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
|
|
|
|
2017-12-19 01:32:06 +01:00
|
|
|
// Install native event handler for hidpi on windows
|
2017-09-21 17:34:41 +02:00
|
|
|
#ifdef USEWINSDK
|
2017-12-19 01:32:06 +01:00
|
|
|
a.installNativeEventFilter(new chatterino::util::DpiNativeEventFilter);
|
2017-09-21 17:34:41 +02:00
|
|
|
#endif
|
|
|
|
|
2017-05-30 15:22:44 +02:00
|
|
|
// Initialize settings
|
2018-01-05 02:23:49 +01:00
|
|
|
bool success = chatterino::singletons::PathManager::getInstance().init(argc, argv);
|
2018-01-05 01:55:21 +01:00
|
|
|
if (!success) {
|
2018-01-05 02:23:49 +01:00
|
|
|
printf("Error initializing paths\n");
|
2017-05-30 15:22:44 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-10-27 20:09:02 +02:00
|
|
|
// Initialize NetworkManager
|
|
|
|
chatterino::util::NetworkManager::init();
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
{
|
|
|
|
// Initialize application
|
|
|
|
chatterino::Application app;
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
// Start the application
|
2018-04-14 22:31:31 +02:00
|
|
|
app.run(a);
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
// Application will go out of scope here and deinitialize itself
|
|
|
|
}
|
2017-01-23 09:49:30 +01:00
|
|
|
|
2017-05-30 15:22:44 +02:00
|
|
|
// Save settings
|
|
|
|
pajlada::Settings::SettingManager::save();
|
|
|
|
|
2017-10-27 20:09:02 +02:00
|
|
|
// 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
|
|
|
}
|
2018-04-09 22:59:19 +02:00
|
|
|
|
|
|
|
void runNativeMessagingHost()
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
_setmode(_fileno(stdin), _O_BINARY);
|
|
|
|
_setmode(_fileno(stdout), _O_BINARY);
|
|
|
|
#endif
|
|
|
|
|
2018-04-12 00:09:16 +02:00
|
|
|
auto &nmm = chatterino::singletons::NativeMessagingManager::getInstance();
|
2018-04-09 22:59:19 +02:00
|
|
|
|
2018-04-14 22:31:31 +02:00
|
|
|
bool bigEndian = isBigEndian();
|
|
|
|
|
2018-04-09 22:59:19 +02:00
|
|
|
while (true) {
|
|
|
|
char size_c[4];
|
|
|
|
std::cin.read(size_c, 4);
|
|
|
|
|
|
|
|
if (std::cin.eof()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-04-14 22:31:31 +02:00
|
|
|
uint32_t size = 0;
|
|
|
|
if (bigEndian) {
|
|
|
|
size = size_c[3] | static_cast<uint32_t>(size_c[2]) << 8 |
|
|
|
|
static_cast<uint32_t>(size_c[1]) << 16 | static_cast<uint32_t>(size_c[0]) << 24;
|
|
|
|
} else {
|
|
|
|
size = size_c[0] | static_cast<uint32_t>(size_c[1]) << 8 |
|
|
|
|
static_cast<uint32_t>(size_c[2]) << 16 | static_cast<uint32_t>(size_c[3]) << 24;
|
|
|
|
}
|
2018-04-09 22:59:19 +02:00
|
|
|
|
|
|
|
char *b = (char *)malloc(size + 1);
|
|
|
|
std::cin.read(b, size);
|
|
|
|
*(b + size) = '\0';
|
|
|
|
|
2018-04-12 00:09:16 +02:00
|
|
|
nmm.sendToGuiProcess(QByteArray(b, size));
|
|
|
|
|
|
|
|
free(b);
|
2018-04-09 22:59:19 +02:00
|
|
|
}
|
|
|
|
}
|