Set service name for lib_base and lib_webview gtk integration

This commit is contained in:
Ilya Fedin 2021-07-07 08:25:23 +04:00 committed by John Preston
parent 3cdd115317
commit 17cee8ec56
7 changed files with 53 additions and 45 deletions

View file

@ -58,18 +58,17 @@ int Launcher::exec() {
return GtkIntegration::Exec( return GtkIntegration::Exec(
GtkIntegration::Type::Base, GtkIntegration::Type::Base,
QString::fromStdString(*(i + 1)), QString::fromStdString(*(i + 1)),
std::stoi(*(i + 2))); QString::fromStdString(*(i + 2)));
} else if (*i == "-webviewhelper" && std::distance(i, e) > 3) { } else if (*i == "-webviewhelper" && std::distance(i, e) > 2) {
return GtkIntegration::Exec( return GtkIntegration::Exec(
GtkIntegration::Type::Webview, GtkIntegration::Type::Webview,
QString::fromStdString(*(i + 1)), QString::fromStdString(*(i + 1)),
std::stoi(*(i + 2)), QString::fromStdString(*(i + 2)));
std::stoi(*(i + 3)));
} else if (*i == "-gtkintegration" && std::distance(i, e) > 2) { } else if (*i == "-gtkintegration" && std::distance(i, e) > 2) {
return GtkIntegration::Exec( return GtkIntegration::Exec(
GtkIntegration::Type::TDesktop, GtkIntegration::Type::TDesktop,
QString::fromStdString(*(i + 1)), QString::fromStdString(*(i + 1)),
std::stoi(*(i + 2))); QString::fromStdString(*(i + 2)));
} }
} }

View file

@ -16,11 +16,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/linux/base_linux_glibmm_helper.h" #include "base/platform/linux/base_linux_glibmm_helper.h"
#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"
#include "webview/platform/linux/webview_linux_webkit2gtk.h"
#include "platform/linux/linux_gtk_integration_p.h" #include "platform/linux/linux_gtk_integration_p.h"
#include "platform/linux/linux_gdk_helper.h" #include "platform/linux/linux_gdk_helper.h"
#include "platform/linux/linux_gtk_open_with_dialog.h" #include "platform/linux/linux_gtk_open_with_dialog.h"
#include "platform/linux/linux_wayland_integration.h" #include "platform/linux/linux_wayland_integration.h"
#include "webview/webview_interface.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "core/application.h" #include "core/application.h"
@ -42,6 +42,8 @@ using BaseGtkIntegration = base::Platform::GtkIntegration;
namespace { namespace {
constexpr auto kService = "org.telegram.desktop.GtkIntegration-%1"_cs; constexpr auto kService = "org.telegram.desktop.GtkIntegration-%1"_cs;
constexpr auto kBaseService = "org.telegram.desktop.BaseGtkIntegration-%1"_cs;
constexpr auto kWebviewService = "org.telegram.desktop.GtkIntegration.WebviewHelper-%1-%2"_cs;
constexpr auto kObjectPath = "/org/telegram/desktop/GtkIntegration"_cs; constexpr auto kObjectPath = "/org/telegram/desktop/GtkIntegration"_cs;
constexpr auto kInterface = "org.telegram.desktop.GtkIntegration"_cs; constexpr auto kInterface = "org.telegram.desktop.GtkIntegration"_cs;
constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs; constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs;
@ -66,6 +68,8 @@ constexpr auto kIntrospectionXML = R"INTROSPECTION(<node>
</interface> </interface>
</node>)INTROSPECTION"_cs; </node>)INTROSPECTION"_cs;
Glib::ustring ServiceName;
bool GetImageFromClipboardSupported() { bool GetImageFromClipboardSupported() {
return (gtk_clipboard_get != nullptr) return (gtk_clipboard_get != nullptr)
&& (gtk_clipboard_wait_for_contents != nullptr) && (gtk_clipboard_wait_for_contents != nullptr)
@ -93,8 +97,7 @@ public:
return Glib::RefPtr<Gio::DBus::Connection>(); return Glib::RefPtr<Gio::DBus::Connection>();
} }
}()) }())
, interfaceVTable(sigc::mem_fun(this, &Private::handleMethodCall)) , interfaceVTable(sigc::mem_fun(this, &Private::handleMethodCall)) {
, serviceName(kService.utf16().arg(getpid()).toStdString()) {
} }
void handleMethodCall( void handleMethodCall(
@ -109,7 +112,6 @@ public:
const Glib::RefPtr<Gio::DBus::Connection> dbusConnection; const Glib::RefPtr<Gio::DBus::Connection> dbusConnection;
const Gio::DBus::InterfaceVTable interfaceVTable; const Gio::DBus::InterfaceVTable interfaceVTable;
Glib::RefPtr<Gio::DBus::NodeInfo> introspectionData; Glib::RefPtr<Gio::DBus::NodeInfo> introspectionData;
Glib::ustring serviceName;
Glib::ustring parentDBusName; Glib::ustring parentDBusName;
bool remoting = true; bool remoting = true;
uint registerId = 0; uint registerId = 0;
@ -303,7 +305,7 @@ void GtkIntegration::load(const QString &allowedBackends) {
base::Platform::MakeGlibVariant(std::tuple{ base::Platform::MakeGlibVariant(std::tuple{
Glib::ustring(allowedBackends.toStdString()), Glib::ustring(allowedBackends.toStdString()),
}), }),
_private->serviceName); ServiceName);
} catch (...) { } catch (...) {
} }
@ -344,9 +346,8 @@ void GtkIntegration::load(const QString &allowedBackends) {
Loaded = true; Loaded = true;
} }
int GtkIntegration::exec(const QString &parentDBusName, int ppid) { int GtkIntegration::exec(const QString &parentDBusName) {
_private->remoting = false; _private->remoting = false;
_private->serviceName = kService.utf16().arg(ppid).toStdString();
_private->parentDBusName = parentDBusName.toStdString(); _private->parentDBusName = parentDBusName.toStdString();
_private->introspectionData = Gio::DBus::NodeInfo::create_for_xml( _private->introspectionData = Gio::DBus::NodeInfo::create_for_xml(
@ -357,7 +358,7 @@ int GtkIntegration::exec(const QString &parentDBusName, int ppid) {
_private->introspectionData->lookup_interface(), _private->introspectionData->lookup_interface(),
_private->interfaceVTable); _private->interfaceVTable);
const auto app = Gio::Application::create(_private->serviceName); const auto app = Gio::Application::create(ServiceName);
app->hold(); app->hold();
_private->parentServiceWatcherId = base::Platform::DBus::RegisterServiceWatcher( _private->parentServiceWatcherId = base::Platform::DBus::RegisterServiceWatcher(
_private->dbusConnection, _private->dbusConnection,
@ -406,7 +407,7 @@ bool GtkIntegration::showOpenWithDialog(const QString &filepath) const {
Glib::ustring(parent.toStdString()), Glib::ustring(parent.toStdString()),
Glib::ustring(filepath.toStdString()), Glib::ustring(filepath.toStdString()),
}), }),
_private->serviceName); ServiceName);
const auto context = Glib::MainContext::create(); const auto context = Glib::MainContext::create();
const auto loop = Glib::MainLoop::create(context); const auto loop = Glib::MainLoop::create(context);
@ -434,7 +435,7 @@ bool GtkIntegration::showOpenWithDialog(const QString &filepath) const {
} catch (...) { } catch (...) {
} }
}, },
_private->serviceName, ServiceName,
std::string(kInterface), std::string(kInterface),
"OpenWithDialogResponse", "OpenWithDialogResponse",
std::string(kObjectPath)); std::string(kObjectPath));
@ -505,7 +506,7 @@ QImage GtkIntegration::getImageFromClipboard() const {
{}, {},
{}, {},
outFdList, outFdList,
_private->serviceName); ServiceName);
const auto streamSize = base::Platform::GlibVariantCast<int>( const auto streamSize = base::Platform::GlibVariantCast<int>(
reply.get_child(1)); reply.get_child(1));
@ -609,25 +610,22 @@ QString GtkIntegration::AllowedBackends() {
int GtkIntegration::Exec( int GtkIntegration::Exec(
Type type, Type type,
const QString &parentDBusName, const QString &parentDBusName,
int ppid, const QString &serviceName) {
uint instanceNumber) {
Glib::init(); Glib::init();
Gio::init(); Gio::init();
if (type == Type::Base) { if (type == Type::Base) {
BaseGtkIntegration::SetServiceName(serviceName);
if (const auto integration = BaseGtkIntegration::Instance()) { if (const auto integration = BaseGtkIntegration::Instance()) {
return integration->exec(parentDBusName, ppid); return integration->exec(parentDBusName);
} }
} else if (type == Type::Webview) { } else if (type == Type::Webview) {
if (const auto instance = Webview::CreateInstance({})) { Webview::WebKit2Gtk::SetServiceName(serviceName.toStdString());
return instance->exec( return Webview::WebKit2Gtk::Exec(parentDBusName.toStdString());
parentDBusName.toStdString(),
ppid,
instanceNumber);
}
} else if (type == Type::TDesktop) { } else if (type == Type::TDesktop) {
ServiceName = serviceName.toStdString();
if (const auto integration = Instance()) { if (const auto integration = Instance()) {
return integration->exec(parentDBusName, ppid); return integration->exec(parentDBusName);
} }
} }
@ -635,10 +633,27 @@ int GtkIntegration::Exec(
} }
void GtkIntegration::Start(Type type) { void GtkIntegration::Start(Type type) {
if (type != Type::Base && type != Type::TDesktop) { if (type != Type::Base
&& type != Type::Webview
&& type != Type::TDesktop) {
return; return;
} }
const auto d = QFile::encodeName(QDir(cWorkingDir()).absolutePath());
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) {
Webview::WebKit2Gtk::SetServiceName(
kWebviewService.utf16().arg(h).arg("%1").toStdString());
return;
} else {
ServiceName = kService.utf16().arg(h).toStdString();
}
const auto dbusName = [] { const auto dbusName = [] {
try { try {
static const auto connection = Gio::DBus::Connection::get_sync( static const auto connection = Gio::DBus::Connection::get_sync(
@ -659,7 +674,9 @@ void GtkIntegration::Start(Type type) {
? qsl("-basegtkintegration") ? qsl("-basegtkintegration")
: qsl("-gtkintegration"), : qsl("-gtkintegration"),
dbusName, dbusName,
QString::number(getpid()), (type == Type::Base)
? kBaseService.utf16().arg(h)
: kService.utf16().arg(h),
}); });
} }
@ -672,18 +689,11 @@ void GtkIntegration::Autorestart(Type type) {
static const auto connection = Gio::DBus::Connection::get_sync( static const auto connection = Gio::DBus::Connection::get_sync(
Gio::DBus::BusType::BUS_TYPE_SESSION); Gio::DBus::BusType::BUS_TYPE_SESSION);
const auto baseServiceName = [] {
if (const auto integration = BaseGtkIntegration::Instance()) {
return integration->serviceName();
}
return QString();
}();
base::Platform::DBus::RegisterServiceWatcher( base::Platform::DBus::RegisterServiceWatcher(
connection, connection,
(type == Type::Base) (type == Type::Base)
? baseServiceName.toStdString() ? Glib::ustring(BaseGtkIntegration::ServiceName().toStdString())
: kService.utf16().arg(getpid()).toStdString(), : ServiceName,
[=]( [=](
const Glib::ustring &service, const Glib::ustring &service,
const Glib::ustring &oldOwner, const Glib::ustring &oldOwner,

View file

@ -21,7 +21,7 @@ public:
static GtkIntegration *Instance(); static GtkIntegration *Instance();
void load(const QString &allowedBackends); void load(const QString &allowedBackends);
int exec(const QString &parentDBusName, int ppid); int exec(const QString &parentDBusName);
[[nodiscard]] bool showOpenWithDialog(const QString &filepath) const; [[nodiscard]] bool showOpenWithDialog(const QString &filepath) const;
@ -32,8 +32,7 @@ public:
static int Exec( static int Exec(
Type type, Type type,
const QString &parentDBusName, const QString &parentDBusName,
int ppid, const QString &serviceName);
uint instanceNumber = 0);
static void Start(Type type); static void Start(Type type);

View file

@ -25,7 +25,7 @@ GtkIntegration *GtkIntegration::Instance() {
void GtkIntegration::load(const QString &allowedBackends) { void GtkIntegration::load(const QString &allowedBackends) {
} }
int GtkIntegration::exec(const QString &parentDBusName, int ppid) { int GtkIntegration::exec(const QString &parentDBusName) {
return 1; return 1;
} }
@ -44,8 +44,7 @@ QString GtkIntegration::AllowedBackends() {
int GtkIntegration:Exec( int GtkIntegration:Exec(
Type type, Type type,
const QString &parentDBusName, const QString &parentDBusName,
int ppid, const QString &serviceName) {
uint instanceNumber) {
return 1; return 1;
} }

View file

@ -746,6 +746,7 @@ void start() {
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);
GtkIntegration::Start(GtkIntegration::Type::TDesktop); GtkIntegration::Start(GtkIntegration::Type::TDesktop);
#ifdef DESKTOP_APP_USE_PACKAGED_RLOTTIE #ifdef DESKTOP_APP_USE_PACKAGED_RLOTTIE

@ -1 +1 @@
Subproject commit f493a8174f993119de8d9a5170dc89641bfafbef Subproject commit b721f4d1302c5119d59ab35ddfd5abb90fab42ed

@ -1 +1 @@
Subproject commit 794aba38bac729471afbcc3aca62400bafd55b4c Subproject commit 1a3206777c0bca6d9fb5b643131e6d2b028a336f