mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:47:42 +00:00
LaunchServer+Help: Open help
urls with Help
This commit is contained in:
parent
79a2088a13
commit
85152d2f7f
4 changed files with 18 additions and 7 deletions
|
@ -30,3 +30,4 @@ directory=/bin/FileManager
|
|||
gemini=/bin/Browser
|
||||
http=/bin/Browser
|
||||
https=/bin/Browser
|
||||
help=/bin/Help
|
||||
|
|
|
@ -171,7 +171,7 @@ MainWidget::MainWidget()
|
|||
};
|
||||
}
|
||||
|
||||
void MainWidget::set_start_page(String const& start_page, int section)
|
||||
void MainWidget::set_start_page(StringView start_page, u32 section)
|
||||
{
|
||||
bool set_start_page = false;
|
||||
if (!start_page.is_null()) {
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
virtual ~MainWidget() override = default;
|
||||
|
||||
ErrorOr<void> initialize_fallibles(GUI::Window&);
|
||||
void set_start_page(String const& page, int section);
|
||||
void set_start_page(StringView page, u32 section);
|
||||
|
||||
private:
|
||||
MainWidget();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
#include "MainWidget.h"
|
||||
#include <AK/URL.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibGUI/Application.h>
|
||||
|
@ -16,6 +17,15 @@
|
|||
|
||||
using namespace Help;
|
||||
|
||||
static String parse_input(char const* input)
|
||||
{
|
||||
AK::URL url(input);
|
||||
if (url.is_valid())
|
||||
return url.basename();
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
|
||||
|
@ -27,8 +37,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::unveil("/tmp/portal/webcontent", "rw"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
char const* start_page = nullptr;
|
||||
unsigned section = 0;
|
||||
String start_page;
|
||||
u32 section = 0;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
// FIXME: These custom Args are a hack. What we want to do is have an optional int arg, then an optional string.
|
||||
|
@ -47,7 +57,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
|
||||
// Otherwise, use it as the start_page
|
||||
start_page = input;
|
||||
start_page = parse_input(input);
|
||||
return true;
|
||||
} });
|
||||
args_parser.add_positional_argument(Core::ArgsParser::Arg {
|
||||
|
@ -57,9 +67,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
.max_values = 1,
|
||||
.accept_value = [&](char const* input) {
|
||||
// If start_page was already set by our section arg, then it can't be set again
|
||||
if (start_page)
|
||||
if (start_page.is_empty())
|
||||
return false;
|
||||
start_page = input;
|
||||
start_page = parse_input(input);
|
||||
return true;
|
||||
} });
|
||||
args_parser.parse(arguments);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue