Browse Source

LaunchServer+Help: Open `help` urls with Help

ForLoveOfCats 3 years ago
parent
commit
85152d2f7f

+ 1 - 0
Base/home/anon/.config/LaunchServer.ini

@@ -30,3 +30,4 @@ directory=/bin/FileManager
 gemini=/bin/Browser
 gemini=/bin/Browser
 http=/bin/Browser
 http=/bin/Browser
 https=/bin/Browser
 https=/bin/Browser
+help=/bin/Help

+ 1 - 1
Userland/Applications/Help/MainWidget.cpp

@@ -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;
     bool set_start_page = false;
     if (!start_page.is_null()) {
     if (!start_page.is_null()) {

+ 1 - 1
Userland/Applications/Help/MainWidget.h

@@ -20,7 +20,7 @@ public:
     virtual ~MainWidget() override = default;
     virtual ~MainWidget() override = default;
 
 
     ErrorOr<void> initialize_fallibles(GUI::Window&);
     ErrorOr<void> initialize_fallibles(GUI::Window&);
-    void set_start_page(String const& page, int section);
+    void set_start_page(StringView page, u32 section);
 
 
 private:
 private:
     MainWidget();
     MainWidget();

+ 15 - 5
Userland/Applications/Help/main.cpp

@@ -7,6 +7,7 @@
  */
  */
 
 
 #include "MainWidget.h"
 #include "MainWidget.h"
+#include <AK/URL.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/System.h>
 #include <LibCore/System.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
@@ -16,6 +17,15 @@
 
 
 using namespace Help;
 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)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
     TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
     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("/tmp/portal/webcontent", "rw"));
     TRY(Core::System::unveil(nullptr, nullptr));
     TRY(Core::System::unveil(nullptr, nullptr));
 
 
-    char const* start_page = nullptr;
-    unsigned section = 0;
+    String start_page;
+    u32 section = 0;
 
 
     Core::ArgsParser args_parser;
     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.
     // 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
             // Otherwise, use it as the start_page
-            start_page = input;
+            start_page = parse_input(input);
             return true;
             return true;
         } });
         } });
     args_parser.add_positional_argument(Core::ArgsParser::Arg {
     args_parser.add_positional_argument(Core::ArgsParser::Arg {
@@ -57,9 +67,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         .max_values = 1,
         .max_values = 1,
         .accept_value = [&](char const* input) {
         .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 was already set by our section arg, then it can't be set again
-            if (start_page)
+            if (start_page.is_empty())
                 return false;
                 return false;
-            start_page = input;
+            start_page = parse_input(input);
             return true;
             return true;
         } });
         } });
     args_parser.parse(arguments);
     args_parser.parse(arguments);