mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Use xdg-activation to open URLs&files
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user