From 6f89598a7bc079179a375910750280d206e228dd Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 5 Oct 2020 13:02:21 +0400 Subject: [PATCH] Clean old attempts to register url scheme on scheme registration --- .../platform/linux/specific_linux.cpp | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 50e1dcdd5..85347bf55 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -1423,13 +1423,13 @@ void RegisterCustomScheme(bool force) { GError *error = nullptr; - const auto actualCommandlineBuilder = qsl("%1 --") + const auto neededCommandlineBuilder = qsl("%1 --") .arg((IsStaticBinary() || InAppImage()) ? cExeDir() + cExeName() : cExeName()); - const auto actualCommandline = qsl("%1 %u") - .arg(actualCommandlineBuilder); + const auto neededCommandline = qsl("%1 %u") + .arg(neededCommandlineBuilder); auto currentAppInfo = g_app_info_get_default_for_type( kHandlerTypeName.utf8(), @@ -1441,13 +1441,36 @@ void RegisterCustomScheme(bool force) { g_object_unref(currentAppInfo); - if (currentCommandline == actualCommandline) { + if (currentCommandline == neededCommandline) { return; } } + auto registeredAppInfoList = g_app_info_get_recommended_for_type( + kHandlerTypeName.utf8()); + + for (auto l = registeredAppInfoList; l != nullptr; l = l->next) { + const auto currentRegisteredAppInfo = reinterpret_cast( + l->data); + + const auto currentAppInfoId = QString( + g_app_info_get_id(currentRegisteredAppInfo)); + + const auto currentCommandline = QString( + g_app_info_get_commandline(currentRegisteredAppInfo)); + + if (currentCommandline == neededCommandline + && currentAppInfoId.startsWith(qsl("userapp-"))) { + g_app_info_delete(currentRegisteredAppInfo); + } + } + + if (registeredAppInfoList) { + g_list_free_full(registeredAppInfoList, g_object_unref); + } + auto newAppInfo = g_app_info_create_from_commandline( - actualCommandlineBuilder.toUtf8(), + neededCommandlineBuilder.toUtf8(), AppName.utf8(), G_APP_INFO_CREATE_SUPPORTS_URIS, &error);