1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-09-10 12:03:18 +02:00

misc: use single process mode for qt webEngine

1. Add --single-process
2. Rename the httpUserAgent to jami-qt

Change-Id: I6de29ee89176b453f12ce225acf926dd1b819c18
This commit is contained in:
Ming Rui Zhang 2021-06-23 15:38:21 -04:00
parent 712f2c3b30
commit e165855e95
4 changed files with 39 additions and 23 deletions

View file

@ -24,7 +24,9 @@ import QtQuick 2.14
import net.jami.Helpers 1.0
Item {
readonly property string appTitle: "Jami" + (UpdateManager.isCurrentVersionBeta() ? " (BETA)" : "")
readonly property string appTitle: "Jami" + (UpdateManager.isCurrentVersionBeta()
? " (BETA)" : "")
readonly property string httpUserAgentName: "jami-qt"
// Misc
property string accept: qsTr("Accept")

View file

@ -31,26 +31,36 @@
#ifndef ENABLE_TESTS
static char**
parseInputArgument(int& argc, char* argv[], char* argToParse)
parseInputArgument(int& argc, char* argv[], QList<char*> argsToParse)
{
/*
* Forcefully append argToParse.
* Forcefully append argsToParse.
*/
int oldArgc = argc;
argc = argc + 1 + 1;
argc += argsToParse.size();
char** newArgv = new char*[argc];
for (int i = 0; i < oldArgc; i++) {
newArgv[i] = argv[i];
}
newArgv[oldArgc] = argToParse;
newArgv[oldArgc + 1] = nullptr;
for (int i = oldArgc; i < argc; i++) {
newArgv[i] = argsToParse.at(i - oldArgc);
}
return newArgv;
}
// Qt WebEngine Chromium Flags
static char noSandbox[] {"--no-sandbox"};
static char disableWebSecurity[] {"--disable-web-security"};
static char singleProcess[] {"--single-process"};
int
main(int argc, char* argv[])
{
setlocale(LC_ALL, "en_US.utf8");
QList<char*> qtWebEngineChromiumFlags;
#ifdef Q_OS_LINUX
setenv("QT_QPA_PLATFORMTHEME", "gtk3", true);
#ifdef __GLIBC__
@ -59,9 +69,12 @@ main(int argc, char* argv[])
// 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))
setenv("QTWEBENGINE_CHROMIUM_FLAGS", "--no-sandbox", true);
qtWebEngineChromiumFlags << noSandbox;
#endif
#endif
qtWebEngineChromiumFlags << disableWebSecurity;
qtWebEngineChromiumFlags << singleProcess;
QApplication::setApplicationName("Jami");
QApplication::setOrganizationDomain("jami.net");
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
@ -75,8 +88,8 @@ main(int argc, char* argv[])
#endif
QtWebEngine::initialize();
char ARG_DISABLE_WEB_SECURITY[] = "--disable-web-security";
auto newArgv = parseInputArgument(argc, argv, ARG_DISABLE_WEB_SECURITY);
auto newArgv = parseInputArgument(argc, argv, qtWebEngineChromiumFlags);
MainApplication app(argc, newArgv);
/*

View file

@ -365,10 +365,16 @@ MainApplication::parseArguments()
parser.addHelpOption();
parser.addVersionOption();
// This option is forced into the arg list.
// These options are potentially forced into the arg list.
QCommandLineOption webSecurityDisableOption(QStringList() << "disable-web-security");
parser.addOption(webSecurityDisableOption);
QCommandLineOption noSandboxOption(QStringList() << "no-sandbox");
parser.addOption(noSandboxOption);
QCommandLineOption singleProcessOption(QStringList() << "single-process");
parser.addOption(singleProcessOption);
QCommandLineOption webDebugOption(QStringList() << "remote-debugging-port",
"Web debugging port.",
"port");

View file

@ -287,7 +287,6 @@ Rectangle {
settings.localStorageEnabled: true
webChannel: messageWebViewChannel
profile: messageWebViewProfile
DropArea{
anchors.fill: parent
@ -319,6 +318,8 @@ Rectangle {
":/linkify-string.js"))
messageWebView.runJavaScript(UtilsAdapter.qStringFromFile(
":/qwebchannel.js"))
messageWebView.runJavaScript(UtilsAdapter.qStringFromFile(
":/jed.js"))
messageWebView.runJavaScript(UtilsAdapter.qStringFromFile(
":/emoji.js"))
messageWebView.runJavaScript(UtilsAdapter.qStringFromFile(
@ -342,24 +343,18 @@ Rectangle {
}
Component.onCompleted: {
profile.cachePath = UtilsAdapter.getCachePath()
profile.persistentStoragePath = UtilsAdapter.getCachePath()
profile.persistentCookiesPolicy = WebEngineProfile.NoPersistentCookies
profile.httpCacheType = WebEngineProfile.NoCache
profile.httpUserAgent = JamiStrings.httpUserAgentName
messageWebView.loadHtml(UtilsAdapter.qStringFromFile(
":/chatview.html"), ":/chatview.html")
messageWebView.url = "qrc:/chatview.html"
}
}
// Provide WebEngineProfile.
WebEngineProfile {
id: messageWebViewProfile
cachePath: UtilsAdapter.getCachePath()
persistentStoragePath: UtilsAdapter.getCachePath()
persistentCookiesPolicy: WebEngineProfile.NoPersistentCookies
httpCacheType: WebEngineProfile.NoCache
httpUserAgent: "jami-windows"
}
// Provide WebChannel by registering jsBridgeObject.
WebChannel {
id: messageWebViewChannel