mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
Assistant: Cache AppFile objects on AppProvider creation
This avoids unnecesarily recreating AppFiles on every query.
This commit is contained in:
parent
6ecff2ac28
commit
4d4ac769c1
2 changed files with 16 additions and 4 deletions
|
@ -62,6 +62,13 @@ void URLResult::activate() const
|
||||||
Desktop::Launcher::open(URL::create_with_url_or_path(title()));
|
Desktop::Launcher::open(URL::create_with_url_or_path(title()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppProvider::AppProvider()
|
||||||
|
{
|
||||||
|
Desktop::AppFile::for_each([this](NonnullRefPtr<Desktop::AppFile> app_file) {
|
||||||
|
m_app_file_cache.append(move(app_file));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void AppProvider::query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete)
|
void AppProvider::query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete)
|
||||||
{
|
{
|
||||||
if (query.starts_with('=') || query.starts_with('$'))
|
if (query.starts_with('=') || query.starts_with('$'))
|
||||||
|
@ -69,17 +76,17 @@ void AppProvider::query(DeprecatedString const& query, Function<void(Vector<Nonn
|
||||||
|
|
||||||
Vector<NonnullRefPtr<Result>> results;
|
Vector<NonnullRefPtr<Result>> results;
|
||||||
|
|
||||||
Desktop::AppFile::for_each([&](NonnullRefPtr<Desktop::AppFile> app_file) {
|
for (auto const& app_file : m_app_file_cache) {
|
||||||
auto query_and_arguments = query.split_limit(' ', 2);
|
auto query_and_arguments = query.split_limit(' ', 2);
|
||||||
auto app_name = query_and_arguments.is_empty() ? query : query_and_arguments[0];
|
auto app_name = query_and_arguments.is_empty() ? query : query_and_arguments[0];
|
||||||
auto arguments = query_and_arguments.size() < 2 ? DeprecatedString::empty() : query_and_arguments[1];
|
auto arguments = query_and_arguments.size() < 2 ? DeprecatedString::empty() : query_and_arguments[1];
|
||||||
auto match_result = fuzzy_match(app_name, app_file->name());
|
auto match_result = fuzzy_match(app_name, app_file->name());
|
||||||
if (!match_result.matched)
|
if (!match_result.matched)
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
auto icon = GUI::FileIconProvider::icon_for_executable(app_file->executable());
|
auto icon = GUI::FileIconProvider::icon_for_executable(app_file->executable());
|
||||||
results.append(adopt_ref(*new AppResult(icon.bitmap_for_size(16), app_file->name(), {}, app_file, arguments, match_result.score)));
|
results.append(make_ref_counted<AppResult>(icon.bitmap_for_size(16), app_file->name(), DeprecatedString::empty(), app_file, arguments, match_result.score));
|
||||||
});
|
};
|
||||||
|
|
||||||
on_complete(move(results));
|
on_complete(move(results));
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,12 @@ public:
|
||||||
|
|
||||||
class AppProvider final : public Provider {
|
class AppProvider final : public Provider {
|
||||||
public:
|
public:
|
||||||
|
AppProvider();
|
||||||
|
|
||||||
void query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete) override;
|
void query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Vector<NonnullRefPtr<Desktop::AppFile>> m_app_file_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CalculatorProvider final : public Provider {
|
class CalculatorProvider final : public Provider {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue