Skip to content

Commit

Permalink
Use Gio::AppInfo::get_recommended_for_type from glibmm 2.76
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed Mar 18, 2023
1 parent e6b7288 commit 0d37d47
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions base/platform/linux/base_url_scheme_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <ksandbox.h>

#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include <gio/gio.h>
#include <glibmm.h>
#include <giomm.h>
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
Expand Down Expand Up @@ -164,38 +163,25 @@ void RegisterUrlScheme(const UrlSchemeDescriptor &descriptor) {

void UnregisterUrlScheme(const UrlSchemeDescriptor &descriptor) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
const auto handlerType = QString("x-scheme-handler/%1")
.arg(descriptor.protocol);
const auto handlerType = "x-scheme-handler/"
+ descriptor.protocol.toStdString();

const auto neededCommandline = KShell::joinArgs(QStringList{
descriptor.executable,
} + KShell::splitArgs(descriptor.arguments) + QStringList{
"--",
"%u",
}).toUtf8();

auto registeredAppInfoList = g_app_info_get_recommended_for_type(
handlerType.toUtf8().constData());

for (auto l = registeredAppInfoList; l != nullptr; l = l->next) {
const auto currentRegisteredAppInfo = reinterpret_cast<GAppInfo*>(
l->data);

const auto currentAppInfoId = QString(
g_app_info_get_id(currentRegisteredAppInfo));
}).toStdString();

const auto currentCommandline = QString(
g_app_info_get_commandline(currentRegisteredAppInfo));
const auto registeredAppInfos = Gio::AppInfo::get_recommended_for_type(
handlerType);

if (currentCommandline == neededCommandline
&& currentAppInfoId.startsWith("userapp-")) {
g_app_info_delete(currentRegisteredAppInfo);
for (const auto &appInfo : registeredAppInfos) {
if (appInfo->get_commandline() == neededCommandline
&& !appInfo->get_id().compare(0, 8, "userapp-")) {
appInfo->do_delete();
}
}

if (registeredAppInfoList) {
g_list_free_full(registeredAppInfoList, g_object_unref);
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
}

Expand Down

2 comments on commit 0d37d47

@mikhailnov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broke building (v4.7.1):

DEBUG: /builddir/build/BUILD/tdesktop-4.7.1-full/Telegram/lib_base/base/platform/linux/base_url_scheme_linux.cpp: In function ‘void base::Platform::UnregisterUrlScheme(const base::Platform::UrlSchemeDescriptor&)’:
DEBUG: /builddir/build/BUILD/tdesktop-4.7.1-full/Telegram/lib_base/base/platform/linux/base_url_scheme_linux.cpp:176:55: error: ‘get_recommended_for_type’ is not a member of ‘Gio::AppInfo’
DEBUG:   176 |         const auto registeredAppInfos = Gio::AppInfo::get_recommended_for_type(
DEBUG:       |                                                       ^~~~~~~~~~~~~~~~~~~~~~~~

@mikhailnov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(как обычно, по коммиту нифига непонятно, зачем это изменение вообще сделано)

Please sign in to comment.