Port AppLaunchContext to cppgir

This commit is contained in:
Ilya Fedin 2023-08-01 16:04:25 +04:00 committed by John Preston
parent 8ec0bdcac9
commit cf781e1043
4 changed files with 36 additions and 17 deletions

View file

@ -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)) {

@ -1 +1 @@
Subproject commit efd052594db9f3d85a2fbcba76db6fdecf226597 Subproject commit 609a9e69f2a69fea050e75cbe2b546b4aa1e4914

@ -1 +1 @@
Subproject commit 91d43ea4b50ef1e7df810ab1f14c49e044570734 Subproject commit 0f25a9451012c7fba93777a009f3b5dcc0f1ca89

2
cmake

@ -1 +1 @@
Subproject commit 0620bb7b87a0ec9195151fd5eb0cf38656c1280b Subproject commit d1c98b4c472c7b59c239006a06d7a784a60a347f