Split webview initialization from GtkIntegration class

This commit is contained in:
Ilya Fedin 2021-08-25 11:37:20 +04:00 committed by John Preston
parent 51df482571
commit 6192413f0b
5 changed files with 38 additions and 67 deletions

View File

@ -9,10 +9,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/crash_reports.h" #include "core/crash_reports.h"
#include "core/update_checker.h" #include "core/update_checker.h"
#include "platform/linux/linux_gtk_integration.h" #include "base/platform/linux/base_linux_gtk_integration.h"
#ifndef DESKTOP_APP_DISABLE_WEBKITGTK
#include "webview/platform/linux/webview_linux_webkit2gtk.h"
#endif // !DESKTOP_APP_DISABLE_WEBKITGTK
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <glibmm.h>
#include <giomm.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
@ -24,7 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Platform { namespace Platform {
namespace { namespace {
using Platform::internal::GtkIntegration; using BaseGtkIntegration = base::Platform::GtkIntegration;
class Arguments { class Arguments {
public: public:
@ -53,17 +60,21 @@ Launcher::Launcher(int argc, char *argv[])
} }
int Launcher::exec() { int Launcher::exec() {
Glib::init();
Gio::init();
for (auto i = begin(_arguments), e = end(_arguments); i != e; ++i) { for (auto i = begin(_arguments), e = end(_arguments); i != e; ++i) {
if (*i == "-basegtkintegration" && std::distance(i, e) > 2) { if (*i == "-basegtkintegration" && std::distance(i, e) > 2) {
return GtkIntegration::Exec( BaseGtkIntegration::SetServiceName(QString::fromStdString(*(i + 2)));
GtkIntegration::Type::Base, if (const auto integration = BaseGtkIntegration::Instance()) {
QString::fromStdString(*(i + 1)), return integration->exec(QString::fromStdString(*(i + 1)));
QString::fromStdString(*(i + 2))); }
return 1;
#ifndef DESKTOP_APP_DISABLE_WEBKITGTK
} else if (*i == "-webviewhelper" && std::distance(i, e) > 2) { } else if (*i == "-webviewhelper" && std::distance(i, e) > 2) {
return GtkIntegration::Exec( Webview::WebKit2Gtk::SetServiceName(*(i + 2));
GtkIntegration::Type::Webview, return Webview::WebKit2Gtk::Exec(*(i + 1));
QString::fromStdString(*(i + 1)), #endif // !DESKTOP_APP_DISABLE_WEBKITGTK
QString::fromStdString(*(i + 2)));
} }
} }

View File

@ -15,20 +15,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/linux/base_linux_dbus_utilities.h" #include "base/platform/linux/base_linux_dbus_utilities.h"
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#ifndef DESKTOP_APP_DISABLE_WEBKITGTK
#include "webview/platform/linux/webview_linux_webkit2gtk.h"
#endif // !DESKTOP_APP_DISABLE_WEBKITGTK
#include <QtCore/QProcess> #include <QtCore/QProcess>
#include <giomm.h> #include <glibmm.h>
namespace Platform { namespace Platform {
namespace internal { namespace internal {
namespace { namespace {
constexpr auto kBaseService = "org.telegram.desktop.BaseGtkIntegration-%1"_cs; constexpr auto kBaseService = "org.telegram.desktop.BaseGtkIntegration-%1"_cs;
constexpr auto kWebviewService = "org.telegram.desktop.GtkIntegration.WebviewHelper-%1-%2"_cs;
using BaseGtkIntegration = base::Platform::GtkIntegration; using BaseGtkIntegration = base::Platform::GtkIntegration;
@ -42,31 +37,8 @@ QString GtkIntegration::AllowedBackends() {
: QString(); : QString();
} }
int GtkIntegration::Exec(
Type type,
const QString &parentDBusName,
const QString &serviceName) {
Glib::init();
Gio::init();
if (type == Type::Base) {
BaseGtkIntegration::SetServiceName(serviceName);
if (const auto integration = BaseGtkIntegration::Instance()) {
return integration->exec(parentDBusName);
}
#ifndef DESKTOP_APP_DISABLE_WEBKITGTK
} else if (type == Type::Webview) {
Webview::WebKit2Gtk::SetServiceName(serviceName.toStdString());
return Webview::WebKit2Gtk::Exec(parentDBusName.toStdString());
#endif // !DESKTOP_APP_DISABLE_WEBKITGTK
}
return 1;
}
void GtkIntegration::Start(Type type) { void GtkIntegration::Start(Type type) {
if (type != Type::Base if (type != Type::Base) {
&& type != Type::Webview) {
return; return;
} }
@ -74,16 +46,7 @@ void GtkIntegration::Start(Type type) {
char h[33] = { 0 }; char h[33] = { 0 };
hashMd5Hex(d.constData(), d.size(), h); hashMd5Hex(d.constData(), d.size(), h);
if (type == Type::Base) { BaseGtkIntegration::SetServiceName(kBaseService.utf16().arg(h));
BaseGtkIntegration::SetServiceName(kBaseService.utf16().arg(h));
} else if (type == Type::Webview) {
#ifndef DESKTOP_APP_DISABLE_WEBKITGTK
Webview::WebKit2Gtk::SetServiceName(
kWebviewService.utf16().arg(h).arg("%1").toStdString());
#endif // !DESKTOP_APP_DISABLE_WEBKITGTK
return;
}
const auto dbusName = [] { const auto dbusName = [] {
try { try {

View File

@ -14,16 +14,10 @@ class GtkIntegration {
public: public:
enum class Type { enum class Type {
Base, Base,
Webview,
}; };
static QString AllowedBackends(); static QString AllowedBackends();
static int Exec(
Type type,
const QString &parentDBusName,
const QString &serviceName);
static void Start(Type type); static void Start(Type type);
static void Autorestart(Type type); static void Autorestart(Type type);

View File

@ -14,13 +14,6 @@ QString GtkIntegration::AllowedBackends() {
return {}; return {};
} }
int GtkIntegration::Exec(
Type type,
const QString &parentDBusName,
const QString &serviceName) {
return 1;
}
void GtkIntegration::Start(Type type) { void GtkIntegration::Start(Type type) {
} }

View File

@ -35,6 +35,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/linux/base_linux_xcb_utilities.h" #include "base/platform/linux/base_linux_xcb_utilities.h"
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION #endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
#ifndef DESKTOP_APP_DISABLE_WEBKITGTK
#include "webview/platform/linux/webview_linux_webkit2gtk.h"
#endif // !DESKTOP_APP_DISABLE_WEBKITGTK
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <QtWidgets/QStyle> #include <QtWidgets/QStyle>
#include <QtWidgets/QDesktopWidget> #include <QtWidgets/QDesktopWidget>
@ -75,6 +79,7 @@ constexpr auto kDarkColorLimit = 192;
constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs; constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs;
constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs; constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs;
constexpr auto kIBusPortalService = "org.freedesktop.portal.IBus"_cs; constexpr auto kIBusPortalService = "org.freedesktop.portal.IBus"_cs;
constexpr auto kWebviewService = "org.telegram.desktop.GtkIntegration.WebviewHelper-%1-%2"_cs;
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
void PortalAutostart(bool start, bool silent) { void PortalAutostart(bool start, bool silent) {
@ -645,14 +650,19 @@ void start() {
qputenv("PULSE_PROP_application.name", AppName.utf8()); qputenv("PULSE_PROP_application.name", AppName.utf8());
qputenv("PULSE_PROP_application.icon_name", GetIconName().toLatin1()); qputenv("PULSE_PROP_application.icon_name", GetIconName().toLatin1());
Glib::init();
Gio::init();
Glib::set_prgname(cExeName().toStdString()); Glib::set_prgname(cExeName().toStdString());
Glib::set_application_name(std::string(AppName)); Glib::set_application_name(std::string(AppName));
GtkIntegration::Start(GtkIntegration::Type::Base); GtkIntegration::Start(GtkIntegration::Type::Base);
GtkIntegration::Start(GtkIntegration::Type::Webview);
#ifndef DESKTOP_APP_DISABLE_WEBKITGTK
const auto d = QFile::encodeName(QDir(cWorkingDir()).absolutePath());
char h[33] = { 0 };
hashMd5Hex(d.constData(), d.size(), h);
Webview::WebKit2Gtk::SetServiceName(
kWebviewService.utf16().arg(h).arg("%1").toStdString());
#endif // !DESKTOP_APP_DISABLE_WEBKITGTK
#ifdef DESKTOP_APP_USE_PACKAGED_RLOTTIE #ifdef DESKTOP_APP_USE_PACKAGED_RLOTTIE
g_warning( g_warning(