mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-16 07:11:52 +00:00
LibWeb+LibWebView+WebContent: Convert about:settings to a WebUI
Some checks are pending
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This commit is contained in:
parent
c75e40180c
commit
f05b0bfd5f
Notes:
github-actions[bot]
2025-03-28 11:32:05 +00:00
Author: https://github.com/trflynn89
Commit: f05b0bfd5f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4068
23 changed files with 151 additions and 264 deletions
75
Libraries/LibWebView/WebUI/SettingsUI.cpp
Normal file
75
Libraries/LibWebView/WebUI/SettingsUI.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/JsonArray.h>
|
||||
#include <LibURL/Parser.h>
|
||||
#include <LibWebView/Application.h>
|
||||
#include <LibWebView/SearchEngine.h>
|
||||
#include <LibWebView/WebUI/SettingsUI.h>
|
||||
|
||||
namespace WebView {
|
||||
|
||||
void SettingsUI::register_interfaces()
|
||||
{
|
||||
register_interface("loadCurrentSettings"sv, [this](auto const&) {
|
||||
load_current_settings();
|
||||
});
|
||||
register_interface("restoreDefaultSettings"sv, [this](auto const&) {
|
||||
restore_default_settings();
|
||||
});
|
||||
register_interface("setNewTabPageURL"sv, [this](auto const& data) {
|
||||
set_new_tab_page_url(data);
|
||||
});
|
||||
register_interface("loadAvailableSearchEngines"sv, [this](auto const&) {
|
||||
load_available_search_engines();
|
||||
});
|
||||
register_interface("setSearchEngine"sv, [this](auto const& data) {
|
||||
set_search_engine(data);
|
||||
});
|
||||
}
|
||||
|
||||
void SettingsUI::load_current_settings()
|
||||
{
|
||||
auto settings = WebView::Application::settings().serialize_json();
|
||||
async_send_message("loadSettings"sv, settings);
|
||||
}
|
||||
|
||||
void SettingsUI::restore_default_settings()
|
||||
{
|
||||
WebView::Application::settings().restore_defaults();
|
||||
load_current_settings();
|
||||
}
|
||||
|
||||
void SettingsUI::set_new_tab_page_url(JsonValue const& new_tab_page_url)
|
||||
{
|
||||
if (!new_tab_page_url.is_string())
|
||||
return;
|
||||
|
||||
auto parsed_new_tab_page_url = URL::Parser::basic_parse(new_tab_page_url.as_string());
|
||||
if (!parsed_new_tab_page_url.has_value())
|
||||
return;
|
||||
|
||||
WebView::Application::settings().set_new_tab_page_url(parsed_new_tab_page_url.release_value());
|
||||
}
|
||||
|
||||
void SettingsUI::load_available_search_engines()
|
||||
{
|
||||
JsonArray engines;
|
||||
for (auto const& engine : search_engines())
|
||||
engines.must_append(engine.name);
|
||||
|
||||
async_send_message("loadSearchEngines"sv, move(engines));
|
||||
}
|
||||
|
||||
void SettingsUI::set_search_engine(JsonValue const& search_engine)
|
||||
{
|
||||
if (search_engine.is_null())
|
||||
WebView::Application::settings().set_search_engine({});
|
||||
else if (search_engine.is_string())
|
||||
WebView::Application::settings().set_search_engine(search_engine.as_string());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue