Skip to content

Commit

Permalink
[applications] More precise debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelSchneid3r committed Sep 7, 2024
1 parent cb9d144 commit 9803142
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion applications/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/*)

Expand Down
2 changes: 1 addition & 1 deletion applications/src/xdg/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &) { }
Expand Down
2 changes: 1 addition & 1 deletion applications/src/xdg/desktopentryparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ QString DesktopEntryParser::getRawValue(const QString &section, 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());
}
}
Expand Down
73 changes: 37 additions & 36 deletions applications/src/xdg/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QRegularExpression>
#include <QStandardPaths>
#include <QWidget>
#include <ranges>
using namespace std;
using namespace albert;

Expand Down Expand Up @@ -99,56 +100,57 @@ Plugin::Plugin()

// Indexer

indexer.parallel = [this](const bool &abort)
indexer.parallel = [this](const bool &abort) -> vector<shared_ptr<applications::Application>>
{
// Get a map of unique desktop entries according to the spec

map<QString, QString> 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<QString, shared_ptr<applications::Application>> 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<shared_ptr<applications::Application>> 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<Application>(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<Application>(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<shared_ptr<applications::Application>> ret;
ranges::move(apps | ranges::views::values, back_inserter(ret));
return ret;
};

indexer.finish = [this](vector<shared_ptr<applications::Application>> &&result)
Expand All @@ -172,7 +174,6 @@ Plugin::Plugin()
setUserTerminalFromConfig();

// Populate index

vector<IndexItem> index_items;
for (const auto &app : applications)
for (const auto & alias : static_pointer_cast<Application>(app)->names())
Expand Down

0 comments on commit 9803142

Please sign in to comment.