Ladybird: Allow opening multiple URLs at once from the command line

Each URL is opened in a separate tab on startup, and the active tab is
the first URL supplied.
This commit is contained in:
Adam Harald Jørgensen 2023-09-11 15:31:23 +02:00 committed by Sam Atkins
parent 40dea272d2
commit 7bf842a974
Notes: sideshowbarker 2024-07-17 07:43:44 +09:00
3 changed files with 18 additions and 11 deletions

View file

@ -39,7 +39,7 @@ static QIcon const& app_icon()
return icon;
}
BrowserWindow::BrowserWindow(Optional<URL> const& initial_url, WebView::CookieJar& cookie_jar, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling, UseLagomNetworking use_lagom_networking)
BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar& cookie_jar, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling, UseLagomNetworking use_lagom_networking)
: m_cookie_jar(cookie_jar)
, m_webdriver_content_ipc_path(webdriver_content_ipc_path)
, m_enable_callgrind_profiling(enable_callgrind_profiling)
@ -403,9 +403,13 @@ BrowserWindow::BrowserWindow(Optional<URL> const& initial_url, WebView::CookieJa
m_go_forward_action->setEnabled(false);
m_reload_action->setEnabled(false);
if (initial_url.has_value()) {
auto initial_url_string = qstring_from_ak_deprecated_string(initial_url->serialize());
new_tab(initial_url_string, Web::HTML::ActivateTab::Yes);
if (!initial_urls.is_empty()) {
bool is_first_tab = true;
for (auto const& url : initial_urls) {
auto initial_url_string = qstring_from_ak_deprecated_string(url.serialize());
new_tab(initial_url_string, is_first_tab ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No);
is_first_tab = false;
}
} else {
new_tab(Settings::the()->new_tab_page(), Web::HTML::ActivateTab::Yes);
}

View file

@ -25,7 +25,7 @@ class WebContentView;
class BrowserWindow : public QMainWindow {
Q_OBJECT
public:
explicit BrowserWindow(Optional<URL> const& initial_url, WebView::CookieJar&, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling, UseLagomNetworking);
explicit BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar&, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling, UseLagomNetworking);
WebContentView& view() const { return m_current_tab->view(); }

View file

@ -70,7 +70,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Gfx::FontDatabase::set_default_font_query("Katica 10 400 0");
Gfx::FontDatabase::set_fixed_width_font_query("Csilla 10 400 0");
StringView raw_url;
Vector<StringView> raw_urls;
StringView webdriver_content_ipc_path;
bool enable_callgrind_profiling = false;
bool enable_sql_database = false;
@ -78,7 +78,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Core::ArgsParser args_parser;
args_parser.set_general_help("The Ladybird web browser :^)");
args_parser.add_positional_argument(raw_url, "URL to open", "url", Core::ArgsParser::Required::No);
args_parser.add_positional_argument(raw_urls, "URLs to open", "url", Core::ArgsParser::Required::No);
args_parser.add_option(webdriver_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path", Core::ArgsParser::OptionHideMode::CommandLineAndMarkdown);
args_parser.add_option(enable_callgrind_profiling, "Enable Callgrind profiling", "enable-callgrind-profiling", 'P');
args_parser.add_option(enable_sql_database, "Enable SQL database", "enable-sql-database", 0);
@ -103,11 +103,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto cookie_jar = database ? TRY(WebView::CookieJar::create(*database)) : WebView::CookieJar::create();
Optional<URL> initial_url;
if (auto url = TRY(get_formatted_url(raw_url)); url.is_valid())
initial_url = move(url);
Vector<URL> initial_urls;
Ladybird::BrowserWindow window(initial_url, cookie_jar, webdriver_content_ipc_path, enable_callgrind_profiling ? WebView::EnableCallgrindProfiling::Yes : WebView::EnableCallgrindProfiling::No, use_lagom_networking ? Ladybird::UseLagomNetworking::Yes : Ladybird::UseLagomNetworking::No);
for (auto const& raw_url : raw_urls) {
if (auto url = TRY(get_formatted_url(raw_url)); url.is_valid())
initial_urls.append(move(url));
}
Ladybird::BrowserWindow window(initial_urls, cookie_jar, webdriver_content_ipc_path, enable_callgrind_profiling ? WebView::EnableCallgrindProfiling::Yes : WebView::EnableCallgrindProfiling::No, use_lagom_networking ? Ladybird::UseLagomNetworking::Yes : Ladybird::UseLagomNetworking::No);
window.setWindowTitle("Ladybird");
if (Ladybird::Settings::the()->is_maximized()) {