Perform initial refactoring work

Things that were once singletons are no longer singletons, but are
instead stored in the "Application" singleton

Some singletons still remain, and some renaming/renamespacing is left
This commit is contained in:
Rasmus Karlsson
2018-04-27 22:11:19 +02:00
parent 32b6417a55
commit ae26b835b6
78 changed files with 850 additions and 773 deletions
+14 -76
View File
@@ -17,21 +17,6 @@
#include <fstream>
#include <iostream>
#ifdef Q_OS_WIN
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#endif
bool isBigEndian()
{
int test = 1;
char *p = (char *)&test;
return p[0] == 0;
}
void runNativeMessagingHost();
int runGui(int argc, char *argv[]);
int main(int argc, char *argv[])
@@ -45,7 +30,7 @@ int main(int argc, char *argv[])
// TODO: can be any argument
if (args.size() > 0 && args[0].startsWith("chrome-extension://")) {
runNativeMessagingHost();
chatterino::Application::runNativeMessagingHost();
return 0;
}
@@ -67,18 +52,17 @@ int runGui(int argc, char *argv[])
a.installNativeEventFilter(new chatterino::util::DpiNativeEventFilter);
#endif
// Initialize settings
bool success = chatterino::singletons::PathManager::getInstance().init(argc, argv);
if (!success) {
printf("Error initializing paths\n");
return 1;
}
// Initialize NetworkManager
chatterino::util::NetworkManager::init();
// Initialize application
chatterino::Application::instantiate(argc, argv);
auto app = chatterino::getApp();
app->construct();
auto &pathMan = *app->paths;
// Running file
auto &pathMan = chatterino::singletons::PathManager::getInstance();
auto runningPath = pathMan.settingsFolderPath + "/running_" + pathMan.appPathHash;
if (QFile::exists(runningPath)) {
@@ -94,16 +78,14 @@ int runGui(int argc, char *argv[])
runningFile.close();
}
// Application
{
// Initialize application
chatterino::Application app;
app->initialize();
// Start the application
app.run(a);
// Start the application
// This is a blocking call
app->run(a);
// Application will go out of scope here and deinitialize itself
}
// We have finished our application, make sure we save stuff
app->save();
// Running file
QFile::remove(runningPath);
@@ -116,47 +98,3 @@ int runGui(int argc, char *argv[])
_exit(0);
}
void runNativeMessagingHost()
{
#ifdef Q_OS_WIN
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
#endif
auto &nmm = chatterino::singletons::NativeMessagingManager::getInstance();
#if 0
bool bigEndian = isBigEndian();
#endif
while (true) {
char size_c[4];
std::cin.read(size_c, 4);
if (std::cin.eof()) {
break;
}
uint32_t size = *reinterpret_cast<uint32_t *>(size_c);
#if 0
// To avoid breaking strict-aliasing rules and potentially inducing undefined behaviour, the following code can be run instead
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;
}
#endif
char *b = (char *)malloc(size + 1);
std::cin.read(b, size);
*(b + size) = '\0';
nmm.sendToGuiProcess(QByteArray(b, size));
free(b);
}
}