Browser: Add help menu item

Contributes towards: #21091
This commit is contained in:
Hugh Davenport 2024-01-04 16:55:09 +13:00 committed by Andrew Kaster
parent e4244f7469
commit 87e00565f1
3 changed files with 12 additions and 6 deletions

View file

@ -16,6 +16,7 @@
#include <Applications/BrowserSettings/Defaults.h>
#include <LibConfig/Client.h>
#include <LibCore/StandardPaths.h>
#include <LibDesktop/Launcher.h>
#include <LibGUI/Application.h>
#include <LibGUI/Clipboard.h>
#include <LibGUI/Icon.h>
@ -49,7 +50,7 @@ static ByteString bookmarks_file_path()
return builder.to_byte_string();
}
BrowserWindow::BrowserWindow(WebView::CookieJar& cookie_jar, Vector<URL> const& initial_urls)
BrowserWindow::BrowserWindow(WebView::CookieJar& cookie_jar, Vector<URL> const& initial_urls, StringView const man_file)
: m_cookie_jar(cookie_jar)
, m_window_actions(*this)
{
@ -138,13 +139,13 @@ BrowserWindow::BrowserWindow(WebView::CookieJar& cookie_jar, Vector<URL> const&
m_window_actions.vertical_tabs_action().set_checked(vertical_tabs);
m_tab_widget->set_tab_position(vertical_tabs ? TabPosition::Left : TabPosition::Top);
build_menus();
build_menus(man_file);
for (size_t i = 0; i < initial_urls.size(); ++i)
create_new_tab(initial_urls[i], (i == 0) ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No);
}
void BrowserWindow::build_menus()
void BrowserWindow::build_menus(StringView const man_file)
{
auto file_menu = add_menu("&File"_string);
file_menu->add_action(WindowActions::the().create_new_tab_action());
@ -445,6 +446,9 @@ void BrowserWindow::build_menus()
auto help_menu = add_menu("&Help"_string);
help_menu->add_action(GUI::CommonActions::make_command_palette_action(this));
help_menu->add_action(GUI::CommonActions::make_help_action([man_file](auto&) {
Desktop::Launcher::open(URL::create_with_file_scheme(man_file), "/bin/Help");
}));
help_menu->add_action(WindowActions::the().about_action());
}

View file

@ -51,9 +51,9 @@ public:
void broadcast_window_size(Gfx::IntSize);
private:
BrowserWindow(WebView::CookieJar&, Vector<URL> const&);
BrowserWindow(WebView::CookieJar&, Vector<URL> const&, StringView const);
void build_menus();
void build_menus(StringView const);
ErrorOr<void> load_search_engines(GUI::Menu& settings_menu);
void set_window_title_for_tab(Tab const&);

View file

@ -105,6 +105,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.parse(arguments);
auto app = TRY(GUI::Application::create(arguments));
auto const man_file = "/usr/share/man/man1/Applications/Browser.md"sv;
Config::pledge_domain("Browser");
Config::monitor_domain("Browser");
@ -113,6 +114,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
// the user's downloads directory.
// FIXME: This should go away with a standalone download manager at some point.
TRY(Desktop::Launcher::add_allowed_url(URL::create_with_file_scheme(Core::StandardPaths::downloads_directory())));
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme(man_file) }));
TRY(Desktop::Launcher::seal_allowlist());
TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));
@ -171,7 +173,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
initial_urls.append(Browser::g_home_url);
auto cookie_jar = TRY(WebView::CookieJar::create(*database));
auto window = Browser::BrowserWindow::construct(cookie_jar, initial_urls);
auto window = Browser::BrowserWindow::construct(cookie_jar, initial_urls, man_file);
auto content_filters_watcher = TRY(Core::FileWatcher::create());
content_filters_watcher->on_change = [&](Core::FileWatcherEvent const&) {