Use xdg-activation to open URLs&files

This commit is contained in:
Ilya Fedin 2022-08-02 19:25:48 +04:00 committed by John Preston
parent c5702f0887
commit d500714242
4 changed files with 26 additions and 4 deletions

View File

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/linux/file_utilities_linux.h"
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include "base/platform/linux/base_linux_app_launch_context.h"
#include "platform/linux/linux_xdp_open_with_dialog.h"
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
@ -24,7 +25,9 @@ namespace File {
void UnsafeOpenUrl(const QString &url) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
try {
if (Gio::AppInfo::launch_default_for_uri(url.toStdString())) {
if (Gio::AppInfo::launch_default_for_uri(
url.toStdString(),
base::Platform::AppLaunchContext())) {
return;
}
} catch (const Glib::Error &e) {
@ -53,7 +56,8 @@ void UnsafeLaunch(const QString &filepath) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
try {
if (Gio::AppInfo::launch_default_for_uri(
Glib::filename_to_uri(filepath.toStdString()))) {
Glib::filename_to_uri(filepath.toStdString()),
base::Platform::AppLaunchContext())) {
return;
}
} catch (const Glib::Error &e) {

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h"
#include "base/platform/linux/base_linux_glibmm_helper.h"
#include "base/platform/linux/base_linux_xdp_utilities.h"
#include "base/platform/linux/base_linux_wayland_integration.h"
#include "core/application.h"
#include "window/window_controller.h"
#include "base/random.h"
@ -77,6 +78,17 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
const auto handleToken = Glib::ustring("tdesktop")
+ std::to_string(base::RandomValue<uint>());
const auto activationToken = []() -> std::optional<Glib::ustring> {
using base::Platform::WaylandIntegration;
if (const auto integration = WaylandIntegration::Instance()) {
if (const auto token = integration->activationToken()
; !token.isNull()) {
return Glib::ustring(token.toStdString());
}
}
return std::nullopt;
}();
auto uniqueName = connection->get_unique_name();
uniqueName.erase(0, 1);
uniqueName.replace(uniqueName.find('.'), 1, 1, '_');
@ -133,6 +145,12 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
"ask",
Glib::Variant<bool>::create(true)
},
activationToken
? std::pair<Glib::ustring, Glib::VariantBase>{
"activation_token",
Glib::Variant<Glib::ustring>::create(*activationToken)
}
: std::pair<Glib::ustring, Glib::VariantBase>{},
}),
}),
fdList,

@ -1 +1 @@
Subproject commit d69b49fdd7bcb0b3414bc66fb34606dd56f695ba
Subproject commit 500731e1f9a4a8b98e388e7a06b91b41d8df7211

@ -1 +1 @@
Subproject commit 4768e7ee03aa22f64f73dc13016d5bd94a047496
Subproject commit a7117df837db39e8d2e4590dd6b0434415f79264