Merge tag 'v4.10.0' into dev

# Conflicts:
#	README.md
#	Telegram/Resources/winrc/Telegram.rc
#	Telegram/Resources/winrc/Updater.rc
#	Telegram/SourceFiles/apiwrap.cpp
#	Telegram/SourceFiles/core/version.h
#	Telegram/SourceFiles/data/data_stories.cpp
#	Telegram/SourceFiles/platform/win/windows_app_user_model_id.cpp
#	Telegram/lib_ui
#	snap/snapcraft.yaml
This commit is contained in:
ZavaruKitsu
2023-09-23 10:58:57 +03:00
353 changed files with 7144 additions and 3482 deletions
@@ -11,12 +11,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h"
#include "base/platform/linux/base_linux_dbus_utilities.h"
#include "base/platform/linux/base_linux_xdp_utilities.h"
#include "ui/platform/ui_platform_window_title.h"
#include "platform/linux/linux_desktop_environment.h"
#include "platform/linux/linux_wayland_integration.h"
#include "lang/lang_keys.h"
#include "mainwindow.h"
#include "storage/localstorage.h"
#include "core/launcher.h"
#include "core/sandbox.h"
#include "core/core_settings.h"
#include "core/update_checker.h"
#include "webview/platform/linux/webview_linux_webkitgtk.h"
@@ -52,115 +54,135 @@ using Platform::internal::WaylandIntegration;
namespace Platform {
namespace {
bool PortalAutostart(bool start, bool silent) {
void PortalAutostart(bool enabled, Fn<void(bool)> done) {
if (cExeName().isEmpty()) {
return false;
if (done) {
done(false);
}
return;
}
auto error = false;
try {
const auto connection = Gio::DBus::Connection::get_sync(
Gio::DBus::BusType::SESSION);
const auto handleToken = Glib::ustring("tdesktop")
+ std::to_string(base::RandomValue<uint>());
std::vector<Glib::ustring> commandline;
commandline.push_back(cExeName().toStdString());
if (Core::Launcher::Instance().customWorkingDir()) {
commandline.push_back("-workdir");
commandline.push_back(cWorkingDir().toStdString());
const auto connection = [&] {
try {
return Gio::DBus::Connection::get_sync(
Gio::DBus::BusType::SESSION);
} catch (const std::exception &e) {
if (done) {
LOG(("Portal Autostart Error: %1").arg(e.what()));
}
return Glib::RefPtr<Gio::DBus::Connection>();
}
commandline.push_back("-autostart");
}();
std::map<Glib::ustring, Glib::VariantBase> options;
options["handle_token"] = Glib::create_variant(handleToken);
options["reason"] = Glib::create_variant(
Glib::ustring(
tr::lng_settings_auto_start(tr::now).toStdString()));
options["autostart"] = Glib::create_variant(start);
options["commandline"] = Glib::create_variant(commandline);
options["dbus-activatable"] = Glib::create_variant(false);
if (!connection) {
if (done) {
done(false);
}
return;
}
auto uniqueName = connection->get_unique_name();
uniqueName.erase(0, 1);
uniqueName.replace(uniqueName.find('.'), 1, 1, '_');
const auto handleToken = Glib::ustring("tdesktop")
+ std::to_string(base::RandomValue<uint>());
const auto requestPath = Glib::ustring(
"/org/freedesktop/portal/desktop/request/")
+ uniqueName
+ '/'
+ handleToken;
std::vector<Glib::ustring> commandline;
commandline.push_back(cExeName().toStdString());
if (Core::Launcher::Instance().customWorkingDir()) {
commandline.push_back("-workdir");
commandline.push_back(cWorkingDir().toStdString());
}
commandline.push_back("-autostart");
const auto loop = Glib::MainLoop::create();
std::map<Glib::ustring, Glib::VariantBase> options;
options["handle_token"] = Glib::create_variant(handleToken);
options["reason"] = Glib::create_variant(
Glib::ustring(
tr::lng_settings_auto_start(tr::now).toStdString()));
options["autostart"] = Glib::create_variant(enabled);
options["commandline"] = Glib::create_variant(commandline);
options["dbus-activatable"] = Glib::create_variant(false);
auto uniqueName = connection->get_unique_name();
uniqueName.erase(0, 1);
uniqueName.replace(uniqueName.find('.'), 1, 1, '_');
const auto requestPath = Glib::ustring(
"/org/freedesktop/portal/desktop/request/")
+ uniqueName
+ '/'
+ handleToken;
const auto window = std::make_shared<QWidget>();
window->setAttribute(Qt::WA_DontShowOnScreen);
window->setWindowModality(Qt::ApplicationModal);
window->show();
const auto signalId = std::make_shared<uint>();
*signalId = connection->signal_subscribe(
[=](
const Glib::RefPtr<Gio::DBus::Connection> &connection,
const Glib::ustring &sender_name,
const Glib::ustring &object_path,
const Glib::ustring &interface_name,
const Glib::ustring &signal_name,
const Glib::VariantContainerBase &parameters) {
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
(void)window; // don't destroy until finish
const auto signalId = connection->signal_subscribe(
[&](
const Glib::RefPtr<Gio::DBus::Connection> &connection,
const Glib::ustring &sender_name,
const Glib::ustring &object_path,
const Glib::ustring &interface_name,
const Glib::ustring &signal_name,
const Glib::VariantContainerBase &parameters) {
try {
const auto response = parameters.get_child(
0
).get_dynamic<uint>();
if (response) {
if (!silent) {
if (done) {
LOG(("Portal Autostart Error: Request denied"));
done(false);
}
error = true;
} else if (done) {
done(enabled);
}
} catch (const std::exception &e) {
if (!silent) {
LOG(("Portal Autostart Error: %1").arg(
QString::fromStdString(e.what())));
if (done) {
LOG(("Portal Autostart Error: %1").arg(e.what()));
done(false);
}
error = true;
}
loop->quit();
},
base::Platform::XDP::kService,
base::Platform::XDP::kRequestInterface,
"Response",
requestPath);
if (*signalId) {
connection->signal_unsubscribe(*signalId);
}
});
},
base::Platform::XDP::kService,
base::Platform::XDP::kRequestInterface,
"Response",
requestPath);
const auto signalGuard = gsl::finally([&] {
if (signalId != 0) {
connection->signal_unsubscribe(signalId);
}
});
connection->call(
base::Platform::XDP::kObjectPath,
"org.freedesktop.portal.Background",
"RequestBackground",
Glib::create_variant(std::tuple{
base::Platform::XDP::ParentWindowID(),
options,
}),
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
try {
connection->call_finish(result);
} catch (const std::exception &e) {
if (done) {
LOG(("Portal Autostart Error: %1").arg(e.what()));
done(false);
}
connection->call_sync(
base::Platform::XDP::kObjectPath,
"org.freedesktop.portal.Background",
"RequestBackground",
Glib::create_variant(std::tuple{
base::Platform::XDP::ParentWindowID(),
options,
}),
base::Platform::XDP::kService);
if (signalId != 0) {
QWidget window;
window.setAttribute(Qt::WA_DontShowOnScreen);
window.setWindowModality(Qt::ApplicationModal);
window.show();
loop->run();
}
} catch (const std::exception &e) {
if (!silent) {
LOG(("Portal Autostart Error: %1").arg(
QString::fromStdString(e.what())));
}
error = true;
}
return !error;
if (*signalId) {
connection->signal_unsubscribe(*signalId);
}
}
});
},
base::Platform::XDP::kService);
}
bool GenerateDesktopFile(
@@ -261,7 +283,7 @@ bool GenerateDesktopFile(
target->save_to_file(targetFile.toStdString());
} catch (const std::exception &e) {
if (!silent) {
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
LOG(("App Error: %1").arg(e.what()));
}
return false;
}
@@ -353,7 +375,7 @@ bool GenerateServiceFile(bool silent = false) {
target->save_to_file(targetFile.toStdString());
} catch (const std::exception &e) {
if (!silent) {
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
LOG(("App Error: %1").arg(e.what()));
}
return false;
}
@@ -371,15 +393,16 @@ bool GenerateServiceFile(bool silent = false) {
}
try {
const auto connection = Gio::DBus::Connection::get_sync(
Gio::DBus::BusType::SESSION);
connection->call_sync(
Gio::DBus::Connection::get_sync(
Gio::DBus::BusType::SESSION
)->call(
base::Platform::DBus::kObjectPath,
base::Platform::DBus::kInterface,
"ReloadConfig",
{},
base::Platform::DBus::kService);
{},
base::Platform::DBus::kService
);
} catch (...) {
}
@@ -426,7 +449,10 @@ void SetApplicationIcon(const QIcon &icon) {
QString SingleInstanceLocalServerName(const QString &hash) {
#if defined Q_OS_LINUX && QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
if (KSandbox::isSnap()) {
return u"snap.telegram-desktop."_q + hash;
return u"snap."_q
+ qEnvironmentVariable("SNAP_INSTANCE_NAME")
+ '.'
+ hash;
}
return hash + '-' + cGUIDStr();
#else // Q_OS_LINUX && Qt >= 6.2.0
@@ -436,18 +462,13 @@ QString SingleInstanceLocalServerName(const QString &hash) {
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
std::optional<bool> IsDarkMode() {
try {
const auto result = base::Platform::XDP::ReadSetting(
"org.freedesktop.appearance",
"color-scheme");
const auto result = base::Platform::XDP::ReadSetting<uint>(
"org.freedesktop.appearance",
"color-scheme");
if (result.has_value()) {
return result->get_dynamic<uint>() == 1;
}
} catch (...) {
}
return std::nullopt;
return result.has_value()
? std::make_optional(*result == 1)
: std::nullopt;
}
#endif // Qt < 6.5.0
@@ -456,13 +477,12 @@ bool AutostartSupported() {
}
void AutostartToggle(bool enabled, Fn<void(bool)> done) {
if (KSandbox::isFlatpak()) {
PortalAutostart(enabled, done);
return;
}
const auto success = [&] {
const auto silent = !done;
if (KSandbox::isFlatpak()) {
return PortalAutostart(enabled, silent);
}
const auto autostart = QStandardPaths::writableLocation(
QStandardPaths::GenericConfigLocation)
+ u"/autostart/"_q;
@@ -478,7 +498,7 @@ void AutostartToggle(bool enabled, Fn<void(bool)> done) {
autostart,
{ u"-autostart"_q },
true,
silent);
!done);
}();
if (done) {
@@ -510,6 +530,15 @@ bool SkipTaskbarSupported() {
return false;
}
bool RunInBackground() {
using Ui::Platform::TitleControl;
const auto layout = Ui::Platform::TitleControlsLayout();
return (ranges::contains(layout.left, TitleControl::Close)
|| ranges::contains(layout.right, TitleControl::Close))
&& !ranges::contains(layout.left, TitleControl::Minimize)
&& !ranges::contains(layout.right, TitleControl::Minimize);
}
QString ExecutablePathForShortcuts() {
if (Core::UpdaterDisabled()) {
const auto &arguments = Core::Launcher::Instance().arguments();
@@ -616,18 +645,6 @@ void start() {
Glib::init();
Gio::init();
#ifdef DESKTOP_APP_USE_PACKAGED_RLOTTIE
g_warning(
"Application has been built with foreign rlottie, "
"animated emojis won't be colored to the selected pack.");
#endif // DESKTOP_APP_USE_PACKAGED_RLOTTIE
#ifdef DESKTOP_APP_USE_PACKAGED_FONTS
g_warning(
"Application was built without embedded fonts, "
"this may lead to font issues.");
#endif // DESKTOP_APP_USE_PACKAGED_FONTS
Webview::WebKitGTK::SetSocketPath(u"%1/%2-%3-webview-%4"_q.arg(
QDir::tempPath(),
h,