Allow running in headless mode when no display server is present

This commit is contained in:
Carl Philipp Klemm 2026-04-26 13:49:48 +02:00
parent 93999abafa
commit 36171a221a

View file

@ -14,17 +14,14 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv);
//pw_init(&argc, &argv);
//set info
QCoreApplication::setOrganizationName("UVOS"); QCoreApplication::setOrganizationName("UVOS");
QCoreApplication::setOrganizationDomain("uvos.xyz"); QCoreApplication::setOrganizationDomain("uvos.xyz");
QCoreApplication::setApplicationName("SHinterface"); QCoreApplication::setApplicationName("SHinterface");
QCoreApplication::setApplicationVersion("0.6"); QCoreApplication::setApplicationVersion("0.6");
QDir::setCurrent(a.applicationDirPath()); QStringList args;
for(int i = 0; i < argc; ++i)
args<<argv[i];
//parse comand line //parse comand line
QCommandLineParser parser; QCommandLineParser parser;
@ -42,9 +39,8 @@ int main(int argc, char *argv[])
parser.addOption(settingsPathOption); parser.addOption(settingsPathOption);
QCommandLineOption headlessOption(QStringList()<<"e"<<"headless", QCoreApplication::translate("main", "Dont start the gui")); QCommandLineOption headlessOption(QStringList()<<"e"<<"headless", QCoreApplication::translate("main", "Dont start the gui"));
parser.addOption(headlessOption); parser.addOption(headlessOption);
parser.process(a);
int retVal; parser.process(args);
programMode = PROGRAM_MODE_UI_ONLY; programMode = PROGRAM_MODE_UI_ONLY;
if(parser.isSet(masterOption)) if(parser.isSet(masterOption))
@ -53,6 +49,15 @@ int main(int argc, char *argv[])
if(parser.isSet(headlessOption)) if(parser.isSet(headlessOption))
programMode = PROGRAM_MODE_HEADLESS_PRIMARY; programMode = PROGRAM_MODE_HEADLESS_PRIMARY;
} }
QCoreApplication* a;
if(programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
a = new QCoreApplication(argc, argv);
else
a = new QApplication(argc, argv);
int retVal;
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY) if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
{ {
QString settingsPath = parser.value(settingsPathOption); QString settingsPath = parser.value(settingsPathOption);
@ -118,7 +123,7 @@ int main(int argc, char *argv[])
QObject::connect(w, &MainWindow::createdItem, &globalItems, &ItemStore::addItem); QObject::connect(w, &MainWindow::createdItem, &globalItems, &ItemStore::addItem);
w->show(); w->show();
} }
retVal = a.exec(); retVal = a->exec();
delete w; delete w;
delete microDevice; delete microDevice;
@ -131,9 +136,11 @@ int main(int argc, char *argv[])
QObject::connect(&w, &MainWindow::sigSave, mainObject.tcpClient, &TcpClient::sendItems); QObject::connect(&w, &MainWindow::sigSave, mainObject.tcpClient, &TcpClient::sendItems);
w.show(); w.show();
retVal = a.exec(); retVal = a->exec();
} }
delete a;
return retVal; return retVal;
} }