mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-24 00:49:46 +00:00
LibWebView+UI: Generate action to enable/disable DevTools
This commit is contained in:
parent
6d30b0f4d4
commit
14d49d5a3a
Notes:
github-actions[bot]
2025-09-18 11:28:44 +00:00
Author: https://github.com/trflynn89
Commit: 14d49d5a3a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6221
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/konradekk
13 changed files with 121 additions and 112 deletions
|
|
@ -453,6 +453,8 @@ ErrorOr<void> Application::launch_devtools_server()
|
|||
m_browser_options.devtools_port = WebView::default_devtools_port;
|
||||
|
||||
m_devtools = TRY(DevTools::DevToolsServer::create(*this, *m_browser_options.devtools_port));
|
||||
on_devtools_enabled();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -683,6 +685,10 @@ void Application::initialize_actions()
|
|||
m_open_settings_page_action = Action::create("Settings"sv, ActionID::OpenSettingsPage, [this]() {
|
||||
open_url_in_new_tab(URL::about_settings(), Web::HTML::ActivateTab::Yes);
|
||||
});
|
||||
m_toggle_devtools_action = Action::create("Enable DevTools"sv, ActionID::ToggleDevTools, [this]() {
|
||||
if (auto result = toggle_devtools_enabled(); result.is_error())
|
||||
display_error_dialog(MUST(String::formatted("Unable to start DevTools: {}", result.error())));
|
||||
});
|
||||
m_view_source_action = Action::create("View Source"sv, ActionID::ViewSource, [this]() {
|
||||
if (auto view = active_web_view(); view.has_value())
|
||||
view->get_source();
|
||||
|
|
@ -833,15 +839,26 @@ void Application::apply_view_options(Badge<ViewImplementation>, ViewImplementati
|
|||
view.debug_request("navigator-compatibility-mode"sv, m_navigator_compatibility_mode);
|
||||
}
|
||||
|
||||
ErrorOr<Application::DevtoolsState> Application::toggle_devtools_enabled()
|
||||
ErrorOr<void> Application::toggle_devtools_enabled()
|
||||
{
|
||||
if (m_devtools) {
|
||||
m_devtools.clear();
|
||||
return DevtoolsState::Disabled;
|
||||
on_devtools_disabled();
|
||||
} else {
|
||||
TRY(launch_devtools_server());
|
||||
}
|
||||
|
||||
TRY(launch_devtools_server());
|
||||
return DevtoolsState::Enabled;
|
||||
return {};
|
||||
}
|
||||
|
||||
void Application::on_devtools_enabled() const
|
||||
{
|
||||
m_toggle_devtools_action->set_text("Disable DevTools"sv);
|
||||
}
|
||||
|
||||
void Application::on_devtools_disabled() const
|
||||
{
|
||||
m_toggle_devtools_action->set_text("Enable DevTools"sv);
|
||||
}
|
||||
|
||||
void Application::refresh_tab_list()
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ public:
|
|||
Action& open_about_page_action() { return *m_open_about_page_action; }
|
||||
Action& open_processes_page_action() { return *m_open_processes_page_action; }
|
||||
Action& open_settings_page_action() { return *m_open_settings_page_action; }
|
||||
Action& toggle_devtools_action() { return *m_toggle_devtools_action; }
|
||||
Action& view_source_action() { return *m_view_source_action; }
|
||||
|
||||
Menu& zoom_menu() { return *m_zoom_menu; }
|
||||
|
|
@ -95,11 +96,7 @@ public:
|
|||
|
||||
void apply_view_options(Badge<ViewImplementation>, ViewImplementation&);
|
||||
|
||||
enum class DevtoolsState {
|
||||
Disabled,
|
||||
Enabled,
|
||||
};
|
||||
ErrorOr<DevtoolsState> toggle_devtools_enabled();
|
||||
ErrorOr<void> toggle_devtools_enabled();
|
||||
void refresh_tab_list();
|
||||
|
||||
protected:
|
||||
|
|
@ -115,6 +112,9 @@ protected:
|
|||
|
||||
virtual Optional<ByteString> ask_user_for_download_folder() const { return {}; }
|
||||
|
||||
virtual void on_devtools_enabled() const;
|
||||
virtual void on_devtools_disabled() const;
|
||||
|
||||
Main::Arguments& arguments() { return m_arguments; }
|
||||
|
||||
private:
|
||||
|
|
@ -189,6 +189,7 @@ private:
|
|||
RefPtr<Action> m_open_about_page_action;
|
||||
RefPtr<Action> m_open_processes_page_action;
|
||||
RefPtr<Action> m_open_settings_page_action;
|
||||
RefPtr<Action> m_toggle_devtools_action;
|
||||
RefPtr<Action> m_view_source_action;
|
||||
|
||||
RefPtr<Menu> m_zoom_menu;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ enum class ActionID {
|
|||
OpenAboutPage,
|
||||
OpenProcessesPage,
|
||||
OpenSettingsPage,
|
||||
ToggleDevTools,
|
||||
ViewSource,
|
||||
|
||||
OpenInNewTab,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue