2022-06-13 13:38:47 +08:00
|
|
|
#include <QDebug>
|
|
|
|
#include "ukui-search-app-data-service.h"
|
|
|
|
#include "app-db-manager.h"
|
|
|
|
|
|
|
|
using namespace UkuiSearch;
|
2022-06-23 10:21:22 +08:00
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
UkuiSearchAppDataService::UkuiSearchAppDataService(int &argc, char *argv[], const QString &applicationName):
|
|
|
|
QtSingleApplication (applicationName, argc, argv)
|
|
|
|
{
|
2022-06-23 10:21:22 +08:00
|
|
|
qDebug() << "ukui search app data service constructor start";
|
2022-06-13 13:38:47 +08:00
|
|
|
setApplicationVersion(QString("v%1").arg(VERSION));
|
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
|
|
|
|
if (!this->isRunning()) {
|
2022-06-23 10:21:22 +08:00
|
|
|
qDebug() << "First running";
|
|
|
|
AppDBManager::getInstance();
|
|
|
|
|
|
|
|
connect(this, &QtSingleApplication::messageReceived, [ & ](QString msg) {
|
2022-06-13 13:38:47 +08:00
|
|
|
this->parseCmd(msg, true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//parse cmd
|
2022-06-23 10:21:22 +08:00
|
|
|
qDebug() << "parse cmd";
|
2022-06-13 13:38:47 +08:00
|
|
|
auto message = this->arguments().join(' ').toUtf8();
|
|
|
|
parseCmd(message, !isRunning());
|
2022-06-23 10:21:22 +08:00
|
|
|
qDebug() << "ukui search app data service constructor end";
|
2022-06-13 13:38:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchAppDataService::parseCmd(QString msg, bool isPrimary)
|
|
|
|
{
|
|
|
|
QCommandLineParser parser;
|
|
|
|
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
|
|
|
|
|
|
|
QCommandLineOption quitOption(QStringList()<<"q"<<"quit", tr("Stop service"));
|
|
|
|
parser.addOption(quitOption);
|
|
|
|
|
|
|
|
if (isPrimary) {
|
|
|
|
const QStringList args = QString(msg).split(' ');
|
|
|
|
parser.process(args);
|
|
|
|
|
|
|
|
if (parser.isSet(quitOption)) {
|
|
|
|
qApp->quit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (arguments().count() < 2) {
|
|
|
|
parser.showHelp();
|
|
|
|
}
|
|
|
|
parser.process(arguments());
|
|
|
|
sendMessage(msg);
|
|
|
|
}
|
|
|
|
}
|