mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use xdg-activation to open URLs&files
This commit is contained in:
parent
c5702f0887
commit
d500714242
4 changed files with 26 additions and 4 deletions
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/linux/file_utilities_linux.h"
|
#include "platform/linux/file_utilities_linux.h"
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#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"
|
#include "platform/linux/linux_xdp_open_with_dialog.h"
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
|
@ -24,7 +25,9 @@ namespace File {
|
||||||
void UnsafeOpenUrl(const QString &url) {
|
void UnsafeOpenUrl(const QString &url) {
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
try {
|
try {
|
||||||
if (Gio::AppInfo::launch_default_for_uri(url.toStdString())) {
|
if (Gio::AppInfo::launch_default_for_uri(
|
||||||
|
url.toStdString(),
|
||||||
|
base::Platform::AppLaunchContext())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (const Glib::Error &e) {
|
} catch (const Glib::Error &e) {
|
||||||
|
@ -53,7 +56,8 @@ void UnsafeLaunch(const QString &filepath) {
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
try {
|
try {
|
||||||
if (Gio::AppInfo::launch_default_for_uri(
|
if (Gio::AppInfo::launch_default_for_uri(
|
||||||
Glib::filename_to_uri(filepath.toStdString()))) {
|
Glib::filename_to_uri(filepath.toStdString()),
|
||||||
|
base::Platform::AppLaunchContext())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (const Glib::Error &e) {
|
} 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/base_platform_info.h"
|
||||||
#include "base/platform/linux/base_linux_glibmm_helper.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_xdp_utilities.h"
|
||||||
|
#include "base/platform/linux/base_linux_wayland_integration.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "base/random.h"
|
#include "base/random.h"
|
||||||
|
@ -77,6 +78,17 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
|
||||||
const auto handleToken = Glib::ustring("tdesktop")
|
const auto handleToken = Glib::ustring("tdesktop")
|
||||||
+ std::to_string(base::RandomValue<uint>());
|
+ 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();
|
auto uniqueName = connection->get_unique_name();
|
||||||
uniqueName.erase(0, 1);
|
uniqueName.erase(0, 1);
|
||||||
uniqueName.replace(uniqueName.find('.'), 1, 1, '_');
|
uniqueName.replace(uniqueName.find('.'), 1, 1, '_');
|
||||||
|
@ -133,6 +145,12 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
|
||||||
"ask",
|
"ask",
|
||||||
Glib::Variant<bool>::create(true)
|
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,
|
fdList,
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit d69b49fdd7bcb0b3414bc66fb34606dd56f695ba
|
Subproject commit 500731e1f9a4a8b98e388e7a06b91b41d8df7211
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4768e7ee03aa22f64f73dc13016d5bd94a047496
|
Subproject commit a7117df837db39e8d2e4590dd6b0434415f79264
|
Loading…
Add table
Reference in a new issue