-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
63 lines (52 loc) · 1.84 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "controllerwindow.h"
#include "qmainwidget.h"
#include <QApplication>
#include "QtSingleApplication/QtSingleApplication"
#include <QDebug>
#include <windows.h>
#include <QString>
QString getArgCommand(int argc, char *argv[])
{
for(int i = 0; i < argc; ++i) {
if (strcmp(argv[i], "--enable") == 0 || strcmp(argv[i], "-e") == 0) {
return "enable";
} else if (strcmp(argv[i], "--disable") == 0 || strcmp(argv[i], "-d") == 0) {
return "disable";
} else if (strcmp(argv[i], "--quit") == 0 || strcmp(argv[i], "-q") == 0) {
return "quit";
}
}
return "";
}
int main(int argc, char *argv[])
{
QtSingleApplication app("org.what.huh.bribri.xboxtovjoy", argc, argv);
QString command = getArgCommand(argc, argv);
if (app.isRunning()) {
if (!command.isEmpty()) {
qDebug() << "Sending running instance command:" << command;
app.sendMessage(command, 500);
} else {
qDebug() << "Already running";
}
return 0;
} else if (command == "quit") {
return 0;
}
QMainWidget *mainWidget;
if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS)) {
qWarning() << "Warning: failed to set process priority. Error:" << GetLastError();
}
qApp->setQuitOnLastWindowClosed(false);
mainWidget = new QMainWidget(command != "disable", NULL);
app.connect(&app, SIGNAL(messageReceived(QString)), mainWidget, SLOT(appMessageReceived(QString)));
if (!command.isEmpty()) {
mainWidget->appMessageReceived(command);
}
int result = app.exec();
qDebug() << "Shutting down...";
mainWidget->deinitialize();
delete mainWidget;
qDebug() << "Done";
return result;
}