mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +00:00
Browser+Base: Allow opening multiple URLs at once from command line
This lets you run `br example.com wikipedia.org some/local/file.html` in one go and have them all opened as tabs.
This commit is contained in:
parent
9df81e20d7
commit
913412e0c5
Notes:
sideshowbarker
2024-07-17 08:42:05 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/913412e0c5 Pull-request: https://github.com/SerenityOS/serenity/pull/14846
2 changed files with 20 additions and 16 deletions
|
@ -7,9 +7,7 @@
|
|||
## Synopsis
|
||||
|
||||
```**sh
|
||||
$ Browser
|
||||
$ Browser [options]
|
||||
$ Browser [url]
|
||||
$ Browser [options] [urls]
|
||||
```
|
||||
|
||||
## Description
|
||||
|
@ -23,7 +21,7 @@ $ Browser [url]
|
|||
|
||||
## Arguments
|
||||
|
||||
* `url`: URL to open
|
||||
* `urls`: A list of urls to open, one per tab. If none are specified, then the homepage will be opened instead.
|
||||
|
||||
## Examples
|
||||
|
||||
|
@ -31,4 +29,5 @@ $ Browser [url]
|
|||
$ Browser
|
||||
$ Browser --help
|
||||
$ Browser https://serenityos.org/
|
||||
$ Browser https://serenityos.org/ /res/html/misc/welcome.html github.com/serenityos/serenity
|
||||
```
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "AK/IterationDecision.h"
|
||||
#include "LibCore/FileWatcher.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/IterationDecision.h>
|
||||
#include <Applications/Browser/Browser.h>
|
||||
#include <Applications/Browser/BrowserWindow.h>
|
||||
#include <Applications/Browser/CookieJar.h>
|
||||
|
@ -15,6 +14,7 @@
|
|||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/FileWatcher.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibDesktop/Launcher.h>
|
||||
|
@ -63,10 +63,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
TRY(Core::System::pledge("stdio recvfd sendfd unix cpath rpath wpath proc exec"));
|
||||
|
||||
char const* specified_url = nullptr;
|
||||
Vector<String> specified_urls;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_positional_argument(specified_url, "URL to open", "url", Core::ArgsParser::Required::No);
|
||||
args_parser.add_positional_argument(specified_urls, "URLs to open", "url", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto app = TRY(GUI::Application::try_create(arguments));
|
||||
|
@ -118,14 +118,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
}
|
||||
|
||||
URL first_url = Browser::url_from_user_input(Browser::g_home_url);
|
||||
if (specified_url) {
|
||||
if (Core::File::exists(specified_url)) {
|
||||
first_url = URL::create_with_file_protocol(Core::File::real_path_for(specified_url));
|
||||
} else {
|
||||
first_url = Browser::url_from_user_input(specified_url);
|
||||
auto url_from_argument_string = [](String const& string) -> URL {
|
||||
if (Core::File::exists(string)) {
|
||||
return URL::create_with_file_protocol(Core::File::real_path_for(string));
|
||||
}
|
||||
}
|
||||
return Browser::url_from_user_input(string);
|
||||
};
|
||||
|
||||
URL first_url = Browser::url_from_user_input(Browser::g_home_url);
|
||||
if (!specified_urls.is_empty())
|
||||
first_url = url_from_argument_string(specified_urls.first());
|
||||
|
||||
Browser::CookieJar cookie_jar;
|
||||
auto window = Browser::BrowserWindow::construct(cookie_jar, first_url);
|
||||
|
@ -160,6 +162,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
};
|
||||
|
||||
for (size_t i = 1; i < specified_urls.size(); ++i)
|
||||
window->create_new_tab(url_from_argument_string(specified_urls[i]), false);
|
||||
|
||||
window->show();
|
||||
|
||||
return app->exec();
|
||||
|
|
Loading…
Reference in a new issue