mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Split webview initialization from GtkIntegration class
This commit is contained in:
parent
51df482571
commit
6192413f0b
5 changed files with 38 additions and 67 deletions
|
@ -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 <QtWidgets/QApplication>
|
||||
|
||||
#include <glibmm.h>
|
||||
#include <giomm.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <QtCore/QProcess>
|
||||
|
||||
#include <giomm.h>
|
||||
#include <glibmm.h>
|
||||
|
||||
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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QStyle>
|
||||
#include <QtWidgets/QDesktopWidget>
|
||||
|
@ -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(
|
||||
|
|
Loading…
Add table
Reference in a new issue