1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +00:00

Assistant: Add new URLProvider to open URL's in the browser

This commit is contained in:
Edwin Hoksberg 2021-07-02 23:24:19 +02:00 committed by Gunnar Beutner
parent d12e14fa95
commit d5dfc255ed
3 changed files with 45 additions and 0 deletions

View file

@ -41,6 +41,11 @@ void FileResult::activate() const
Desktop::Launcher::open(URL::create_with_file_protocol(title()));
}
void URLResult::activate() const
{
Desktop::Launcher::open(URL::create_with_url_or_path(title()));
}
void AppProvider::query(String const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete)
{
if (query.starts_with("="))
@ -151,4 +156,23 @@ void FileProvider::build_filesystem_cache()
return 0; }, [this](auto) { m_building_cache = false; });
}
void URLProvider::query(String const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete)
{
URL url = URL(query);
if (url.scheme().is_empty())
url.set_scheme("http");
if (url.host().is_empty())
url.set_host(query);
if (url.paths().is_empty())
url.set_paths({ "" });
if (!url.is_valid())
return;
Vector<NonnullRefPtr<Result>> results;
results.append(adopt_ref(*new URLResult(url)));
on_complete(results);
}
}