mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibWebView: Support custom search engines
This allows the user to store custom search engines via about:settings. Custom engines will be displayed below the builtin engines in the drop- down to select the default engine. A couple of edge cases here: 1. We currently reject a custom engine if one with the same name already exists. In the future, we should allow editing custom engines. 2. If a custom engine which was the default engine is removed, we will disable search rather than falling back to any other engine.
This commit is contained in:
parent
dbf4b189a4
commit
2810071a9c
Notes:
github-actions[bot]
2025-04-06 11:46:03 +00:00
Author: https://github.com/trflynn89
Commit: 2810071a9c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4237
7 changed files with 317 additions and 28 deletions
|
@ -34,6 +34,12 @@ void SettingsUI::register_interfaces()
|
|||
register_interface("setSearchEngine"sv, [this](auto const& data) {
|
||||
set_search_engine(data);
|
||||
});
|
||||
register_interface("addCustomSearchEngine"sv, [this](auto const& data) {
|
||||
add_custom_search_engine(data);
|
||||
});
|
||||
register_interface("removeCustomSearchEngine"sv, [this](auto const& data) {
|
||||
remove_custom_search_engine(data);
|
||||
});
|
||||
register_interface("setAutocompleteEngine"sv, [this](auto const& data) {
|
||||
set_autocomplete_engine(data);
|
||||
});
|
||||
|
@ -94,7 +100,7 @@ void SettingsUI::set_languages(JsonValue const& languages)
|
|||
void SettingsUI::load_available_engines()
|
||||
{
|
||||
JsonArray search_engines;
|
||||
for (auto const& engine : WebView::search_engines())
|
||||
for (auto const& engine : WebView::builtin_search_engines())
|
||||
search_engines.must_append(engine.name);
|
||||
|
||||
JsonArray autocomplete_engines;
|
||||
|
@ -116,6 +122,22 @@ void SettingsUI::set_search_engine(JsonValue const& search_engine)
|
|||
WebView::Application::settings().set_search_engine(search_engine.as_string());
|
||||
}
|
||||
|
||||
void SettingsUI::add_custom_search_engine(JsonValue const& search_engine)
|
||||
{
|
||||
if (auto custom_engine = Settings::parse_custom_search_engine(search_engine); custom_engine.has_value())
|
||||
WebView::Application::settings().add_custom_search_engine(custom_engine.release_value());
|
||||
|
||||
load_current_settings();
|
||||
}
|
||||
|
||||
void SettingsUI::remove_custom_search_engine(JsonValue const& search_engine)
|
||||
{
|
||||
if (auto custom_engine = Settings::parse_custom_search_engine(search_engine); custom_engine.has_value())
|
||||
WebView::Application::settings().remove_custom_search_engine(*custom_engine);
|
||||
|
||||
load_current_settings();
|
||||
}
|
||||
|
||||
void SettingsUI::set_autocomplete_engine(JsonValue const& autocomplete_engine)
|
||||
{
|
||||
if (autocomplete_engine.is_null())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue