diff --git a/applications/CMakeLists.txt b/applications/CMakeLists.txt index d2fc195c..d2abb5c8 100644 --- a/applications/CMakeLists.txt +++ b/applications/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16) find_package(Albert REQUIRED) -project(applications VERSION 12.2) +project(applications VERSION 12.3) file(GLOB_RECURSE I18N_SOURCES src/*) diff --git a/applications/src/xdg/application.cpp b/applications/src/xdg/application.cpp index 0fe32e2f..090f7738 100644 --- a/applications/src/xdg/application.cpp +++ b/applications/src/xdg/application.cpp @@ -159,7 +159,7 @@ Application::Application(const QString &id, const QString &path, ParseOptions po } catch (const out_of_range &e) { - WARN << "Desktop action" << action_id << "skipped: " << e.what(); + WARN << QString("%1: Desktop action '%2' skipped: %3").arg(path, action_id, e.what()); } } } catch (const out_of_range &) { } diff --git a/applications/src/xdg/desktopentryparser.cpp b/applications/src/xdg/desktopentryparser.cpp index ab7fae15..bbe04c24 100644 --- a/applications/src/xdg/desktopentryparser.cpp +++ b/applications/src/xdg/desktopentryparser.cpp @@ -47,7 +47,7 @@ QString DesktopEntryParser::getRawValue(const QString §ion, const QString &k .arg(section, key).toStdString()); } } catch (const out_of_range&) { - throw SectionDoesNotExist(QString("Section '%1' does not contain a key '{}'.") + throw SectionDoesNotExist(QString("Desktop entry does not contain a section '%1'.") .arg(section).toStdString()); } } diff --git a/applications/src/xdg/plugin.cpp b/applications/src/xdg/plugin.cpp index f4655e7f..b2754b5c 100644 --- a/applications/src/xdg/plugin.cpp +++ b/applications/src/xdg/plugin.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace std; using namespace albert; @@ -99,56 +100,57 @@ Plugin::Plugin() // Indexer - indexer.parallel = [this](const bool &abort) + indexer.parallel = [this](const bool &abort) -> vector> { - // Get a map of unique desktop entries according to the spec - map desktopFiles; // Desktop id > path + Application::ParseOptions po { + .ignore_show_in_keys = ignore_show_in_keys(), + .use_exec = use_exec(), + .use_generic_name = use_generic_name(), + .use_keywords = use_keywords(), + .use_non_localized_name = use_non_localized_name() + }; + + // Get a map of unique desktop entries according to the spec + map> apps; // Desktop id > path for (const QString &dir : appDirectories()) { + DEBG << "Scanning desktop entries in:" << dir; + QDirIterator fIt(dir, QStringList("*.desktop"), QDir::Files, QDirIterator::Subdirectories|QDirIterator::FollowSymlinks); while (!fIt.next().isEmpty()) { + if (abort) + return {}; + + const auto path = fIt.filePath(); + // To determine the ID of a desktop file, make its full path relative to // the $XDG_DATA_DIRS component in which the desktop file is installed, // remove the "applications/" prefix, and turn '/' into '-'. - static QRegularExpression re("^.*applications/"); - QString desktopFileId = fIt.filePath().remove(re).replace("/","-").chopped(8).toLower(); // sizeof '.desktop' - if (const auto &[it, success] = desktopFiles.emplace(desktopFileId, fIt.filePath()); !success) - DEBG << QString("Desktop file '%1' will be skipped: Shadowed by '%2'").arg(fIt.filePath(), desktopFiles[desktopFileId]); - } - } - - // Index the unique desktop files - vector> apps; - for (const auto &[id, path] : desktopFiles) - { - if (abort) - return apps; - - try - { - Application::ParseOptions po{ - .ignore_show_in_keys = ignore_show_in_keys(), - .use_exec = use_exec(), - .use_generic_name = use_generic_name(), - .use_keywords = use_keywords(), - .use_non_localized_name = use_non_localized_name() - }; - - apps.emplace_back(make_shared(id, path, po)); - } - catch (const exception &e) - { - DEBG << QString("Skipped desktop entry '%1': %2").arg(path, e.what()); + static const QRegularExpression re("^.*applications/"); + const auto id = fIt.filePath().remove(re).replace("/","-").chopped(8).toLower(); // '.desktop' + + try + { + if (const auto &[it, success] = apps.emplace(id, make_shared(id, path, po)); + success) + DEBG << QString("Valid desktop file '%1': '%2'").arg(path, it->second->name()); + else + DEBG << QString("Skipped %1: Shadowed by '%2'").arg(path, it->second->path()); + } + catch (const exception &e) + { + DEBG << QString("Skipped %1: %2").arg(path, e.what()); + } } } - ranges::sort(apps, [](const auto &a, const auto &b){ return a->id() < b->id(); }); - - return apps; + vector> ret; + ranges::move(apps | ranges::views::values, back_inserter(ret)); + return ret; }; indexer.finish = [this](vector> &&result) @@ -172,7 +174,6 @@ Plugin::Plugin() setUserTerminalFromConfig(); // Populate index - vector index_items; for (const auto &app : applications) for (const auto & alias : static_pointer_cast(app)->names())