This repository has been archived by the owner on Jun 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
77 lines (68 loc) · 2.67 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QFile>
#include "ElgatoStreamDeck/esdplugin.h"
#include <MyPlugin/myplugin.h>
void textMessageLogger(QtMsgType type, const QMessageLogContext &, const QString & msg)
{
QString txt;
QString timestamp = QDateTime::currentDateTime().toString("yyyyMMddHHmmss");
switch (type)
{
case QtInfoMsg:
txt = QString("Info: %1").arg(msg);
break;
case QtDebugMsg:
txt = QString("Debug: %1").arg(msg);
break;
case QtWarningMsg:
txt = QString("Warning: %1").arg(msg);
break;
case QtCriticalMsg:
txt = QString("Critical: %1").arg(msg);
break;
case QtFatalMsg:
txt = QString("Fatal: %1").arg(msg);
break;
}
QFile outFile("log");
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << timestamp << " " << txt << endl;
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
qInstallMessageHandler(textMessageLogger);
// Parse command line arguments
QCommandLineParser cmdParser;
cmdParser.addHelpOption();
QCommandLineOption portOption("port","","port","0");
QCommandLineOption pluginuuidOption("pluginUUID","","pluginUUID","");
QCommandLineOption registerEventOption("registerEvent","","registerEvent","");
QCommandLineOption infoOption("info","","info","");
cmdParser.addOption(portOption);
cmdParser.addOption(pluginuuidOption);
cmdParser.addOption(registerEventOption);
cmdParser.addOption(infoOption);
cmdParser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
cmdParser.process(app);
int websocketPort = cmdParser.value(portOption).toInt();
QString pluginUUID = cmdParser.value(pluginuuidOption);
QString registerEvent = cmdParser.value(registerEventOption);
QString info = cmdParser.value(infoOption);
// Start communication with streamdeck app
ESDPluginBase esdPlugin(websocketPort,pluginUUID,registerEvent,info);
if(!esdPlugin.Connect())
{
app.exit(1);
}
// Listen for stream deck events
MyPlugin actionInstance;
actionInstance.connect(&esdPlugin,&ESDPluginBase::WillAppear,&actionInstance,&MyPlugin::ESDWillAppear);
actionInstance.connect(&esdPlugin,&ESDPluginBase::KeyDown,&actionInstance,&MyPlugin::ESDKeyDown);
actionInstance.connect(&esdPlugin,&ESDPluginBase::KeyUp,&actionInstance,&MyPlugin::ESDKeyUp);
actionInstance.connect(&esdPlugin,&ESDPluginBase::WillDisappear,&actionInstance,&MyPlugin::ESDWillDisappear);
esdPlugin.connect(&actionInstance,&MyPlugin::SetActionTitle,&esdPlugin,&ESDPluginBase::SetTitle);
return app.exec();
}