Skip to content

Commit

Permalink
Port AppLaunchContext to cppgir
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed Aug 3, 2023
1 parent 8ec0bdc commit cf781e1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
47 changes: 33 additions & 14 deletions Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ For license and copyright information please follow this link:

#include <QtGui/QDesktopServices>

#include <glibmm.h>
#include <giomm.h>
#include <gio/gio.hpp>

using namespace gi::repository;

namespace Platform {
namespace File {

void UnsafeOpenUrl(const QString &url) {
try {
if (Gio::AppInfo::launch_default_for_uri(
{
const auto result = Gio::AppInfo::launch_default_for_uri(
url.toStdString(),
base::Platform::AppLaunchContext())) {
base::Platform::AppLaunchContext());

if (!result) {
LOG(("App Error: %1").arg(
QString::fromStdString(result.error().what())));
} else if (*result) {
return;
}
} catch (const std::exception &e) {
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
}

QDesktopServices::openUrl(url);
Expand All @@ -45,14 +49,29 @@ bool UnsafeShowOpenWith(const QString &filepath) {
}

void UnsafeLaunch(const QString &filepath) {
try {
if (Gio::AppInfo::launch_default_for_uri(
Glib::filename_to_uri(filepath.toStdString()),
base::Platform::AppLaunchContext())) {
return;
if ([&] {
const auto filename = GLib::filename_to_uri(filepath.toStdString());
if (!filename) {
LOG(("App Error: %1").arg(
QString::fromStdString(filename.error().what())));

return false;
}

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;
}
} catch (const std::exception &e) {
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));

return *result;
}()) {
return;
}

if (UnsafeShowOpenWith(filepath)) {
Expand Down
2 changes: 1 addition & 1 deletion cmake

0 comments on commit cf781e1

Please sign in to comment.