From 6192413f0bd3fc34fa7bef595d2f625c5373d884 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 25 Aug 2021 11:37:20 +0400 Subject: [PATCH] Split webview initialization from GtkIntegration class --- .../platform/linux/launcher_linux.cpp | 31 ++++++++----- .../platform/linux/linux_gtk_integration.cpp | 43 ++----------------- .../platform/linux/linux_gtk_integration.h | 6 --- .../linux/linux_gtk_integration_dummy.cpp | 7 --- .../platform/linux/specific_linux.cpp | 18 ++++++-- 5 files changed, 38 insertions(+), 67 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp index 1d962d27b9..9c3caa54a1 100644 --- a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp @@ -9,10 +9,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/crash_reports.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 +#include +#include + #include #include #include @@ -24,7 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Platform { namespace { -using Platform::internal::GtkIntegration; +using BaseGtkIntegration = base::Platform::GtkIntegration; class Arguments { public: @@ -53,17 +60,21 @@ Launcher::Launcher(int argc, char *argv[]) } int Launcher::exec() { + Glib::init(); + Gio::init(); + for (auto i = begin(_arguments), e = end(_arguments); i != e; ++i) { if (*i == "-basegtkintegration" && std::distance(i, e) > 2) { - return GtkIntegration::Exec( - GtkIntegration::Type::Base, - QString::fromStdString(*(i + 1)), - QString::fromStdString(*(i + 2))); + BaseGtkIntegration::SetServiceName(QString::fromStdString(*(i + 2))); + if (const auto integration = BaseGtkIntegration::Instance()) { + return integration->exec(QString::fromStdString(*(i + 1))); + } + return 1; +#ifndef DESKTOP_APP_DISABLE_WEBKITGTK } else if (*i == "-webviewhelper" && std::distance(i, e) > 2) { - return GtkIntegration::Exec( - GtkIntegration::Type::Webview, - QString::fromStdString(*(i + 1)), - QString::fromStdString(*(i + 2))); + Webview::WebKit2Gtk::SetServiceName(*(i + 2)); + return Webview::WebKit2Gtk::Exec(*(i + 1)); +#endif // !DESKTOP_APP_DISABLE_WEBKITGTK } } diff --git a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp index f771d8c425..976970d6bd 100644 --- a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp @@ -15,20 +15,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/platform/linux/base_linux_dbus_utilities.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 -#include +#include namespace Platform { namespace internal { namespace { 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; @@ -42,31 +37,8 @@ QString GtkIntegration::AllowedBackends() { : 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) { - if (type != Type::Base - && type != Type::Webview) { + if (type != Type::Base) { return; } @@ -74,16 +46,7 @@ void GtkIntegration::Start(Type type) { char h[33] = { 0 }; hashMd5Hex(d.constData(), d.size(), h); - if (type == Type::Base) { - 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; - } + BaseGtkIntegration::SetServiceName(kBaseService.utf16().arg(h)); const auto dbusName = [] { try { diff --git a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.h b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.h index 8f85486bb8..f0229ac13b 100644 --- a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.h +++ b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.h @@ -14,16 +14,10 @@ class GtkIntegration { public: enum class Type { Base, - Webview, }; static QString AllowedBackends(); - static int Exec( - Type type, - const QString &parentDBusName, - const QString &serviceName); - static void Start(Type type); static void Autorestart(Type type); diff --git a/Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp b/Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp index b19a2c0336..66a4fb5422 100644 --- a/Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp @@ -14,13 +14,6 @@ QString GtkIntegration::AllowedBackends() { return {}; } -int GtkIntegration::Exec( - Type type, - const QString &parentDBusName, - const QString &serviceName) { - return 1; -} - void GtkIntegration::Start(Type type) { } diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 8b26bba939..581077e2b4 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -35,6 +35,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/platform/linux/base_linux_xcb_utilities.h" #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 #include #include @@ -75,6 +79,7 @@ constexpr auto kDarkColorLimit = 192; constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs; constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_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 void PortalAutostart(bool start, bool silent) { @@ -645,14 +650,19 @@ void start() { qputenv("PULSE_PROP_application.name", AppName.utf8()); qputenv("PULSE_PROP_application.icon_name", GetIconName().toLatin1()); - Glib::init(); - Gio::init(); - Glib::set_prgname(cExeName().toStdString()); Glib::set_application_name(std::string(AppName)); 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 g_warning(