mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-02 15:35:51 +00:00
Port AppLaunchContext to cppgir
This commit is contained in:
@@ -12,21 +12,25 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
|
|
||||||
#include <QtGui/QDesktopServices>
|
#include <QtGui/QDesktopServices>
|
||||||
|
|
||||||
#include <glibmm.h>
|
#include <gio/gio.hpp>
|
||||||
#include <giomm.h>
|
|
||||||
|
using namespace gi::repository;
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace File {
|
namespace File {
|
||||||
|
|
||||||
void UnsafeOpenUrl(const QString &url) {
|
void UnsafeOpenUrl(const QString &url) {
|
||||||
try {
|
{
|
||||||
if (Gio::AppInfo::launch_default_for_uri(
|
const auto result = Gio::AppInfo::launch_default_for_uri(
|
||||||
url.toStdString(),
|
url.toStdString(),
|
||||||
base::Platform::AppLaunchContext())) {
|
base::Platform::AppLaunchContext());
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
LOG(("App Error: %1").arg(
|
||||||
|
QString::fromStdString(result.error().what())));
|
||||||
|
} else if (*result) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (const std::exception &e) {
|
|
||||||
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
@@ -45,14 +49,29 @@ bool UnsafeShowOpenWith(const QString &filepath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UnsafeLaunch(const QString &filepath) {
|
void UnsafeLaunch(const QString &filepath) {
|
||||||
try {
|
if ([&] {
|
||||||
if (Gio::AppInfo::launch_default_for_uri(
|
const auto filename = GLib::filename_to_uri(filepath.toStdString());
|
||||||
Glib::filename_to_uri(filepath.toStdString()),
|
if (!filename) {
|
||||||
base::Platform::AppLaunchContext())) {
|
LOG(("App Error: %1").arg(
|
||||||
return;
|
QString::fromStdString(filename.error().what())));
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} catch (const std::exception &e) {
|
|
||||||
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
|
const auto result = Gio::AppInfo::launch_default_for_uri(
|
||||||
|
*filename,
|
||||||
|
base::Platform::AppLaunchContext());
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
LOG(("App Error: %1").arg(
|
||||||
|
QString::fromStdString(result.error().what())));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *result;
|
||||||
|
}()) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UnsafeShowOpenWith(filepath)) {
|
if (UnsafeShowOpenWith(filepath)) {
|
||||||
|
Submodule Telegram/lib_base updated: efd052594d...609a9e69f2
Submodule Telegram/lib_ui updated: 91d43ea4b5...0f25a94510
2
cmake
2
cmake
Submodule cmake updated: 0620bb7b87...d1c98b4c47
Reference in New Issue
Block a user