mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:48:12 +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
2 changed files with 20 additions and 16 deletions
|
@ -7,9 +7,7 @@
|
||||||
## Synopsis
|
## Synopsis
|
||||||
|
|
||||||
```**sh
|
```**sh
|
||||||
$ Browser
|
$ Browser [options] [urls]
|
||||||
$ Browser [options]
|
|
||||||
$ Browser [url]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
@ -23,7 +21,7 @@ $ Browser [url]
|
||||||
|
|
||||||
## Arguments
|
## 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
|
## Examples
|
||||||
|
|
||||||
|
@ -31,4 +29,5 @@ $ Browser [url]
|
||||||
$ Browser
|
$ Browser
|
||||||
$ Browser --help
|
$ Browser --help
|
||||||
$ Browser https://serenityos.org/
|
$ 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) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||||
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "AK/IterationDecision.h"
|
#include <AK/IterationDecision.h>
|
||||||
#include "LibCore/FileWatcher.h"
|
|
||||||
#include <AK/StringBuilder.h>
|
|
||||||
#include <Applications/Browser/Browser.h>
|
#include <Applications/Browser/Browser.h>
|
||||||
#include <Applications/Browser/BrowserWindow.h>
|
#include <Applications/Browser/BrowserWindow.h>
|
||||||
#include <Applications/Browser/CookieJar.h>
|
#include <Applications/Browser/CookieJar.h>
|
||||||
|
@ -15,6 +14,7 @@
|
||||||
#include <LibConfig/Client.h>
|
#include <LibConfig/Client.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
|
#include <LibCore/FileWatcher.h>
|
||||||
#include <LibCore/StandardPaths.h>
|
#include <LibCore/StandardPaths.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibDesktop/Launcher.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"));
|
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;
|
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);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
auto app = TRY(GUI::Application::try_create(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);
|
auto url_from_argument_string = [](String const& string) -> URL {
|
||||||
if (specified_url) {
|
if (Core::File::exists(string)) {
|
||||||
if (Core::File::exists(specified_url)) {
|
return URL::create_with_file_protocol(Core::File::real_path_for(string));
|
||||||
first_url = URL::create_with_file_protocol(Core::File::real_path_for(specified_url));
|
|
||||||
} else {
|
|
||||||
first_url = Browser::url_from_user_input(specified_url);
|
|
||||||
}
|
}
|
||||||
}
|
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;
|
Browser::CookieJar cookie_jar;
|
||||||
auto window = Browser::BrowserWindow::construct(cookie_jar, first_url);
|
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();
|
window->show();
|
||||||
|
|
||||||
return app->exec();
|
return app->exec();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue