mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 06:02:44 +00:00 
			
		
		
		
	 1a97382305
			
		
	
	
		1a97382305
		
	
	
	
	
		
			
			The pattern to construct `Application` was to use the `try_create` method from the `C_OBJECT` macro. While being safe from an OOM perspective, this method doesn't propagate errors from the constructor. This patch make `Application` use the `C_OBJECT_ABSTRACT` and manually define a `create` method that can bubble up errors from the construction stage. This commit also removes the ability to use `argc` and `argv` to create an `Application`, only `Main`'s `Arguments` can be used. From a user point of view, the patch renames `try_create` => `create`, hence the huge number of modified files.
		
			
				
	
	
		
			70 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
 | |
|  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 | |
|  * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
 | |
|  * Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include "MainWidget.h"
 | |
| #include <AK/URL.h>
 | |
| #include <LibCore/ArgsParser.h>
 | |
| #include <LibCore/System.h>
 | |
| #include <LibGUI/Application.h>
 | |
| #include <LibGUI/Icon.h>
 | |
| #include <LibGUI/Window.h>
 | |
| #include <LibMain/Main.h>
 | |
| 
 | |
| using namespace Help;
 | |
| 
 | |
| ErrorOr<int> serenity_main(Main::Arguments arguments)
 | |
| {
 | |
|     TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
 | |
|     auto app = TRY(GUI::Application::create(arguments));
 | |
| 
 | |
|     TRY(Core::System::unveil("/res", "r"));
 | |
|     // We specifically don't want to load this path from a library, as that can be hijacked with LD_PRELOAD.
 | |
|     TRY(Core::System::unveil("/usr/share/man", "r"));
 | |
|     TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));
 | |
|     TRY(Core::System::unveil("/tmp/session/%sid/portal/launch", "rw"));
 | |
|     TRY(Core::System::unveil("/tmp/session/%sid/portal/webcontent", "rw"));
 | |
|     TRY(Core::System::unveil(nullptr, nullptr));
 | |
| 
 | |
|     DeprecatedString first_query_parameter;
 | |
|     DeprecatedString second_query_parameter;
 | |
| 
 | |
|     Core::ArgsParser args_parser;
 | |
|     // The actual "page query" parsing happens when we set the main widget's start page.
 | |
|     args_parser.add_positional_argument(
 | |
|         first_query_parameter,
 | |
|         "Section of the man page",
 | |
|         "section",
 | |
|         Core::ArgsParser::Required::No);
 | |
|     args_parser.add_positional_argument(
 | |
|         second_query_parameter,
 | |
|         "Help page to open. Either an absolute path to the markdown file, or a search query",
 | |
|         "page",
 | |
|         Core::ArgsParser::Required::No);
 | |
|     args_parser.parse(arguments);
 | |
|     Vector<StringView, 2> query_parameters;
 | |
|     if (!first_query_parameter.is_empty())
 | |
|         query_parameters.append(first_query_parameter);
 | |
|     if (!second_query_parameter.is_empty())
 | |
|         query_parameters.append(second_query_parameter);
 | |
| 
 | |
|     auto app_icon = GUI::Icon::default_icon("app-help"sv);
 | |
| 
 | |
|     auto window = TRY(GUI::Window::try_create());
 | |
|     window->set_icon(app_icon.bitmap_for_size(16));
 | |
|     window->set_title("Help");
 | |
|     window->resize(570, 500);
 | |
| 
 | |
|     auto main_widget = TRY(window->set_main_widget<MainWidget>());
 | |
|     TRY(main_widget->initialize_fallibles(window));
 | |
|     TRY(main_widget->set_start_page(query_parameters));
 | |
| 
 | |
|     window->show();
 | |
| 
 | |
|     return app->exec();
 | |
| }
 |