2018-08-12 16:45:39 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QSettings>
|
2020-08-24 21:36:45 +02:00
|
|
|
#include <QMessageBox>
|
2021-08-07 12:03:35 +02:00
|
|
|
#include <QStandardPaths>
|
2021-09-28 21:44:09 +02:00
|
|
|
#include <QProcess>
|
|
|
|
|
2020-05-23 22:52:42 +02:00
|
|
|
#include "mainwindow.h"
|
2018-08-12 16:45:39 +02:00
|
|
|
#include "searchresult.h"
|
|
|
|
#include "pdfpreview.h"
|
2020-05-23 22:52:42 +02:00
|
|
|
#include "../shared/common.h"
|
2021-08-07 12:03:35 +02:00
|
|
|
#include "../submodules/qssb.h/qssb.h"
|
2021-09-28 21:44:09 +02:00
|
|
|
#include "ipcserver.h"
|
2020-05-23 22:52:42 +02:00
|
|
|
|
2018-08-12 16:45:39 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-09-28 21:44:09 +02:00
|
|
|
QString socketPath = "/tmp/looqs-spawner";
|
|
|
|
if(argc > 1)
|
|
|
|
{
|
|
|
|
QApplication a(argc, argv);
|
|
|
|
QString arg = argv[1];
|
|
|
|
if(arg == "ipc")
|
|
|
|
{
|
|
|
|
IpcServer *ipcserver = new IpcServer();
|
|
|
|
qDebug() << "Launching ipc";
|
|
|
|
if(!ipcserver->startSpawner(socketPath))
|
|
|
|
{
|
|
|
|
qDebug() << "Error failed to spawn";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
qDebug() << "Launched";
|
|
|
|
}
|
|
|
|
return a.exec();
|
|
|
|
}
|
|
|
|
QProcess process;
|
|
|
|
QStringList args;
|
|
|
|
args << "ipc";
|
|
|
|
if(!process.startDetached("/proc/self/exe", args))
|
|
|
|
{
|
|
|
|
QString errorMsg = "Failed to start IPC server";
|
|
|
|
qDebug() << errorMsg;
|
|
|
|
QMessageBox::critical(nullptr, "Error", errorMsg);
|
|
|
|
}
|
|
|
|
|
2021-08-07 12:03:35 +02:00
|
|
|
struct qssb_policy *policy = qssb_init_policy();
|
|
|
|
std::string appDataLocation = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation).toStdString();
|
|
|
|
std::string cacheDataLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation).toStdString();
|
2021-09-28 21:44:09 +02:00
|
|
|
std::string sockPath = socketPath.toStdString();
|
2021-08-07 12:03:35 +02:00
|
|
|
policy->namespace_options = QSSB_UNSHARE_NETWORK | QSSB_UNSHARE_USER;
|
2021-09-28 21:44:09 +02:00
|
|
|
|
2021-08-07 12:03:35 +02:00
|
|
|
qssb_append_path_policy(policy, QSSB_FS_ALLOW_READ | QSSB_FS_ALLOW_REMOVE_FILE, "/");
|
|
|
|
qssb_append_path_policy(policy, QSSB_FS_ALLOW_READ | QSSB_FS_ALLOW_REMOVE_FILE | QSSB_FS_ALLOW_WRITE,
|
|
|
|
appDataLocation.c_str());
|
|
|
|
qssb_append_path_policy(policy, QSSB_FS_ALLOW_READ | QSSB_FS_ALLOW_REMOVE_FILE | QSSB_FS_ALLOW_WRITE,
|
|
|
|
cacheDataLocation.c_str());
|
|
|
|
|
|
|
|
int ret = qssb_enable_policy(policy);
|
|
|
|
if(ret != 0)
|
|
|
|
{
|
|
|
|
qDebug() << "Failed to establish sandbox";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
qssb_free_policy(policy);
|
|
|
|
|
2020-05-23 22:52:42 +02:00
|
|
|
Common::setupAppInfo();
|
2018-08-12 16:45:39 +02:00
|
|
|
QApplication a(argc, argv);
|
2020-08-24 21:36:45 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Common::ensureConfigured();
|
|
|
|
}
|
2021-06-12 14:59:58 +02:00
|
|
|
catch(LooqsGeneralException &e)
|
2020-08-24 21:36:45 +02:00
|
|
|
{
|
|
|
|
qDebug() << e.message;
|
|
|
|
QMessageBox::critical(nullptr, "Error", e.message);
|
|
|
|
return 1;
|
|
|
|
}
|
2018-08-12 16:45:39 +02:00
|
|
|
qRegisterMetaType<QVector<SearchResult>>("QVector<SearchResult>");
|
|
|
|
qRegisterMetaType<QVector<PdfPreview>>("QVector<PdfPreview>");
|
|
|
|
qRegisterMetaType<PdfPreview>("PdfPreview");
|
2021-09-28 21:44:09 +02:00
|
|
|
|
|
|
|
IPCClient client{socketPath};
|
|
|
|
MainWindow w{0, client};
|
2018-08-12 16:45:39 +02:00
|
|
|
w.showMaximized();
|
|
|
|
|
|
|
|
return a.exec();
|
|
|
|
}
|