main.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
  3. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  4. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  5. * Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #include "MainWidget.h"
  10. #include <LibCore/ArgsParser.h>
  11. #include <LibCore/System.h>
  12. #include <LibGUI/Application.h>
  13. #include <LibGUI/Icon.h>
  14. #include <LibGUI/Window.h>
  15. #include <LibMain/Main.h>
  16. #include <LibURL/URL.h>
  17. using namespace Help;
  18. ErrorOr<int> serenity_main(Main::Arguments arguments)
  19. {
  20. TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
  21. auto app = TRY(GUI::Application::create(arguments));
  22. TRY(Core::System::unveil("/res", "r"));
  23. // We specifically don't want to load this path from a library, as that can be hijacked with LD_PRELOAD.
  24. TRY(Core::System::unveil("/usr/share/man", "r"));
  25. TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));
  26. TRY(Core::System::unveil("/tmp/session/%sid/portal/launch", "rw"));
  27. TRY(Core::System::unveil("/tmp/session/%sid/portal/webcontent", "rw"));
  28. TRY(Core::System::unveil(nullptr, nullptr));
  29. ByteString first_query_parameter;
  30. ByteString second_query_parameter;
  31. Core::ArgsParser args_parser;
  32. // The actual "page query" parsing happens when we set the main widget's start page.
  33. args_parser.add_positional_argument(
  34. first_query_parameter,
  35. "Section of the man page",
  36. "section",
  37. Core::ArgsParser::Required::No);
  38. args_parser.add_positional_argument(
  39. second_query_parameter,
  40. "Help page to open. Either an absolute path to the markdown file, or a search query",
  41. "page",
  42. Core::ArgsParser::Required::No);
  43. args_parser.parse(arguments);
  44. Vector<StringView, 2> query_parameters;
  45. if (!first_query_parameter.is_empty())
  46. query_parameters.append(first_query_parameter);
  47. if (!second_query_parameter.is_empty())
  48. query_parameters.append(second_query_parameter);
  49. auto app_icon = GUI::Icon::default_icon("app-help"sv);
  50. auto window = GUI::Window::construct();
  51. window->set_icon(app_icon.bitmap_for_size(16));
  52. window->set_title("Help");
  53. window->resize(570, 500);
  54. auto main_widget = TRY(MainWidget::try_create());
  55. window->set_main_widget(main_widget);
  56. TRY(main_widget->initialize(window));
  57. TRY(main_widget->set_start_page(query_parameters));
  58. window->show();
  59. return app->exec();
  60. }