2020-09-01 14:31:31 -04:00
|
|
|
/*!
|
2020-08-03 13:27:42 -04:00
|
|
|
* Copyright (C) 2015-2020 by Savoir-faire Linux
|
|
|
|
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>
|
|
|
|
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
|
|
|
|
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "runguard.h"
|
2020-09-17 16:08:52 -04:00
|
|
|
#include "version.h"
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
#include <QCryptographicHash>
|
2021-03-31 14:10:29 -04:00
|
|
|
#include <QApplication>
|
2021-09-08 10:31:38 -04:00
|
|
|
#include <QtWebEngineCore>
|
|
|
|
#include <QtWebEngineQuick>
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
#include <clocale>
|
|
|
|
|
2020-10-26 16:50:07 +01:00
|
|
|
#ifndef ENABLE_TESTS
|
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
static char**
|
2021-06-23 15:38:21 -04:00
|
|
|
parseInputArgument(int& argc, char* argv[], QList<char*> argsToParse)
|
2020-09-01 14:31:31 -04:00
|
|
|
{
|
|
|
|
/*
|
2021-06-23 15:38:21 -04:00
|
|
|
* Forcefully append argsToParse.
|
2020-09-01 14:31:31 -04:00
|
|
|
*/
|
|
|
|
int oldArgc = argc;
|
2021-06-23 15:38:21 -04:00
|
|
|
argc += argsToParse.size();
|
2020-09-01 14:31:31 -04:00
|
|
|
char** newArgv = new char*[argc];
|
|
|
|
for (int i = 0; i < oldArgc; i++) {
|
|
|
|
newArgv[i] = argv[i];
|
|
|
|
}
|
2021-06-23 15:38:21 -04:00
|
|
|
|
|
|
|
for (int i = oldArgc; i < argc; i++) {
|
|
|
|
newArgv[i] = argsToParse.at(i - oldArgc);
|
|
|
|
}
|
2020-09-01 14:31:31 -04:00
|
|
|
return newArgv;
|
|
|
|
}
|
|
|
|
|
2021-06-23 15:38:21 -04:00
|
|
|
// Qt WebEngine Chromium Flags
|
|
|
|
static char noSandbox[] {"--no-sandbox"};
|
|
|
|
static char disableWebSecurity[] {"--disable-web-security"};
|
|
|
|
static char singleProcess[] {"--single-process"};
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
int
|
2020-09-10 17:40:51 -04:00
|
|
|
main(int argc, char* argv[])
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
|
|
|
setlocale(LC_ALL, "en_US.utf8");
|
2021-06-23 15:38:21 -04:00
|
|
|
|
|
|
|
QList<char*> qtWebEngineChromiumFlags;
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
setenv("QT_QPA_PLATFORMTHEME", "gtk3", true);
|
2021-08-25 14:39:39 -04:00
|
|
|
setenv("QML_DISABLE_DISK_CACHE", "1", true);
|
2021-06-03 17:07:52 -04:00
|
|
|
#ifdef __GLIBC__
|
|
|
|
// Current glibc is causing some bugs with font loading
|
|
|
|
// See https://bugreports.qt.io/browse/QTBUG-92969
|
|
|
|
// As I prefer to not use custom patched Qt, just wait for a
|
|
|
|
// new version with this bug fixed
|
|
|
|
if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 33))
|
2021-06-23 15:38:21 -04:00
|
|
|
qtWebEngineChromiumFlags << noSandbox;
|
2021-06-03 17:07:52 -04:00
|
|
|
#endif
|
2020-08-03 13:27:42 -04:00
|
|
|
#endif
|
2021-06-23 15:38:21 -04:00
|
|
|
qtWebEngineChromiumFlags << disableWebSecurity;
|
|
|
|
qtWebEngineChromiumFlags << singleProcess;
|
2021-09-08 10:31:38 -04:00
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
QApplication::setApplicationName("Jami");
|
|
|
|
QApplication::setOrganizationDomain("jami.net");
|
|
|
|
QApplication::setQuitOnLastWindowClosed(false);
|
2020-09-17 16:08:52 -04:00
|
|
|
QCoreApplication::setApplicationVersion(QString(VERSION_STRING));
|
2020-09-01 14:31:31 -04:00
|
|
|
QApplication::setHighDpiScaleFactorRoundingPolicy(
|
2021-02-24 20:28:00 -05:00
|
|
|
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
2021-12-13 14:01:09 -05:00
|
|
|
|
|
|
|
#if defined(Q_OS_MACOS)
|
|
|
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::MetalRhi);
|
|
|
|
#elif defined(Q_OS_WIN)
|
|
|
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::VulkanRhi);
|
2021-12-22 13:04:24 -05:00
|
|
|
#endif
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-06-23 15:38:21 -04:00
|
|
|
auto newArgv = parseInputArgument(argc, argv, qtWebEngineChromiumFlags);
|
|
|
|
|
2020-09-29 11:41:38 -04:00
|
|
|
MainApplication app(argc, newArgv);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Runguard to make sure that only one instance runs at a time.
|
|
|
|
* Note: needs to be after the creation of the application
|
2020-09-10 17:40:51 -04:00
|
|
|
*/
|
2020-08-03 13:27:42 -04:00
|
|
|
QCryptographicHash appData(QCryptographicHash::Sha256);
|
|
|
|
appData.addData(QApplication::applicationName().toUtf8());
|
|
|
|
appData.addData(QApplication::organizationDomain().toUtf8());
|
2021-03-11 13:30:45 -05:00
|
|
|
RunGuard guard(appData.result(), &app);
|
2020-08-03 13:27:42 -04:00
|
|
|
if (!guard.tryToRun()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-27 11:49:34 -05:00
|
|
|
if (!app.init()) {
|
|
|
|
guard.release();
|
|
|
|
return 0;
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Exec the application.
|
|
|
|
*/
|
2020-09-01 14:31:31 -04:00
|
|
|
auto ret = app.exec();
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
guard.release();
|
|
|
|
return ret;
|
|
|
|
}
|
2020-10-26 16:50:07 +01:00
|
|
|
#endif
|