145 lines
3.4 KiB
C++
145 lines
3.4 KiB
C++
//#include "contclasses.h"
|
|
#define INIT_FILELOG
|
|
#include "qtcommon.h"
|
|
#include "qtclasses.h"
|
|
#include "qtvisuals.h"
|
|
#include "settings.h"
|
|
|
|
OverseerHandler *osh = nullptr;
|
|
ini::UserSettings *set = nullptr;
|
|
|
|
bool startupRun = false;
|
|
bool onStartup = false;
|
|
char* userSettingsPath = nullptr;
|
|
|
|
QApplication* createApplication(int &argc, char *argv[]) {
|
|
return new QApplication(argc, argv);
|
|
}
|
|
|
|
bool isInstanceRunning(QString appName) {
|
|
QLocalSocket socket;
|
|
socket.connectToServer(appName);
|
|
bool isOpen = socket.isOpen();
|
|
socket.close();
|
|
return isOpen;
|
|
}
|
|
|
|
QLocalServer* startInstanceServer(QString appName) {
|
|
QLocalServer* server = new QLocalServer;
|
|
server->setSocketOptions(QLocalServer::WorldAccessOption);
|
|
server->listen(appName);
|
|
return server;
|
|
}
|
|
|
|
void closeDebugFileLog() {
|
|
close_file_log_buffer();
|
|
}
|
|
|
|
void parseCmdArgs(int argc, char* argv[]) {
|
|
if(argc == 1) return;
|
|
//char* configPath = nullptr;
|
|
char* arg[] = { (char*)"--config-path=", (char*)"--change-startup" };
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
if(strstr(argv[i], arg[0])) {
|
|
userSettingsPath = argv[i] + strlen(arg[0]);
|
|
}
|
|
|
|
if(strstr(argv[i], arg[1])) {
|
|
if (++i >= argc) return;
|
|
switch (argv[i][0]) {
|
|
case '0':
|
|
startupRun = true;
|
|
onStartup = false;
|
|
break;
|
|
case '1':
|
|
startupRun = true;
|
|
onStartup = true;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
/* set_terminate
|
|
* void closeDebugFileLog2() {
|
|
* close_file_log_buffer();
|
|
* abort();
|
|
* }
|
|
*/
|
|
|
|
int main (int argc, char* argv[]) {
|
|
/*
|
|
* Debug: logging report file
|
|
*/
|
|
initialize_file_log();
|
|
atexit(closeDebugFileLog);
|
|
|
|
QApplication::setStyle(new MixerStyle(QStyleFactory::create("Fusion")));
|
|
//QApplication::setFont(font);
|
|
//QPalette palette = QGuiApplication::palette();
|
|
|
|
//palette.setColor(QPalette::Active, QPalette::Highlight, QColor(255, 192, 203, 200));
|
|
//QColor(30,30,30,100));
|
|
//QGuiApplication::setPalette(palette);
|
|
osh = new OverseerHandler();
|
|
osh->populateSystemValues();
|
|
|
|
/*
|
|
* Arg parsing: (admin?) startup change run
|
|
*/
|
|
parseCmdArgs(argc, argv);
|
|
if (startupRun) {
|
|
if (!isInstanceRunning(PIPE_NAME)) exit(-1);
|
|
//if (startupChangeInfo->permissionChangeScope == NONE) exit(-1);
|
|
osh->updateStartupConfig(onStartup);
|
|
exit(0);
|
|
}
|
|
|
|
//Check if running
|
|
//https://stackoverflow.com/questions/48060989/qt-show-application-if-currently-running
|
|
if (!isInstanceRunning(PIPE_NAME))
|
|
startInstanceServer(PIPE_NAME);
|
|
else exit(0);
|
|
|
|
/*
|
|
* Config file init
|
|
*/
|
|
if (userSettingsPath)
|
|
set = ini::UserSettings::createSettings(userSettingsPath, true);
|
|
|
|
if (set)
|
|
OverseerHandler::settingsPath = std::string(userSettingsPath);
|
|
else setConfigDirToDefaults();
|
|
|
|
StylingHelper::setBackgroundColor(osh->isLightMode());
|
|
//qRegisterMetaType<EndpointWidgetEvent>();
|
|
|
|
//INIT CONT
|
|
log_debugcpp("main init");
|
|
osh->createEndpointHandlers();
|
|
log_debugcpp("Reloaded endpoint handlers");
|
|
|
|
//INIT FRONT
|
|
QScopedPointer<QApplication> app(createApplication(argc, argv));
|
|
|
|
MainWindow window = MainWindow();
|
|
//window.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::QSizePolicy::MinimumExpanding)
|
|
QApplication::setQuitOnLastWindowClosed(false);
|
|
|
|
DarkModeEventFilter* darkMode = new DarkModeEventFilter();
|
|
QAbstractEventDispatcher::instance()->installNativeEventFilter(darkMode);
|
|
|
|
/*
|
|
* QFile styleFile(":/assets/style.qss");
|
|
* styleFile.open(QFile::ReadOnly);
|
|
* QString styleSheet { QLatin1String(styleFile.readAll()) };
|
|
*/
|
|
|
|
return app->exec();
|
|
}
|
|
|