1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:57:44 +00:00

LibGUI: Make Application's construction fallible

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.
This commit is contained in:
Lucas CHOLLET 2023-05-05 00:24:53 -04:00 committed by Sam Atkins
parent f132751fae
commit 1a97382305
93 changed files with 121 additions and 118 deletions

View file

@ -348,7 +348,7 @@ bool GLContextWidget::load_file(String const& filename, NonnullOwnPtr<Core::File
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::pledge("stdio thread recvfd sendfd rpath unix prot_exec map_fixed"));

View file

@ -14,7 +14,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::pledge("stdio recvfd sendfd rpath"));
TRY(Core::System::unveil("/res", "r"));

View file

@ -17,7 +17,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::pledge("stdio recvfd sendfd rpath"));
TRY(Core::System::unveil("/etc/timezone", "r"));

View file

@ -160,7 +160,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return 0;
}
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
auto window = GUI::Window::construct();
window->set_minimizable(false);

View file

@ -102,7 +102,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.parse(arguments);
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("Browser");
Config::monitor_domain("Browser");

View file

@ -18,7 +18,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath wpath cpath recvfd sendfd unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("Browser");
StringView selected_tab;

View file

@ -22,7 +22,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::pledge("stdio recvfd sendfd rpath"));
TRY(Core::System::unveil("/res", "r"));

View file

@ -25,7 +25,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath proc exec unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("Calendar");
Config::monitor_domain("Calendar");

View file

@ -17,7 +17,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath recvfd sendfd unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("Calendar");

View file

@ -17,7 +17,7 @@ ErrorOr<int> serenity_main(Main::Arguments args)
{
TRY(Core::System::pledge("stdio rpath wpath cpath recvfd sendfd unix"));
auto app = TRY(GUI::Application::try_create(args));
auto app = TRY(GUI::Application::create(args));
TRY(Core::System::unveil(TRY(String::formatted("{}/.config/certs.pem", Core::StandardPaths::home_directory())), "rwc"_short_string));
TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));

View file

@ -43,7 +43,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("CharacterMap");
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme("/usr/share/man/man1/Applications/CharacterMap.md") }));

View file

@ -18,7 +18,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath recvfd sendfd unix proc exec"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("Taskbar");

View file

@ -160,7 +160,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd cpath rpath unix proc exec thread"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
DeprecatedString coredump_path {};
bool unlink_on_exit = false;

View file

@ -24,7 +24,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath unix proc exec"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("WindowManager");
StringView selected_tab;

View file

@ -31,7 +31,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio recvfd sendfd thread cpath rpath wpath unix proc exec id"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
auto executable_path = FileSystem::resolve_executable_from_environment(command[0]);
if (executable_path.is_error()) {

View file

@ -89,7 +89,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_positional_argument(initial_location, "Path to open", "path", Core::ArgsParser::Required::No);
args_parser.parse(arguments);
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::pledge("stdio thread recvfd sendfd cpath rpath wpath fattr proc exec unix"));

View file

@ -21,7 +21,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd thread rpath unix cpath wpath"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme("/usr/share/man/man1/Applications/FontEditor.md") }));
TRY(Desktop::Launcher::seal_allowlist());

View file

@ -17,7 +17,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath recvfd sendfd unix thread"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("Games");
StringView selected_tab;

View file

@ -21,7 +21,7 @@ using namespace Help;
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
auto app = TRY(GUI::Application::try_create(arguments));
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.

View file

@ -22,7 +22,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix cpath wpath thread"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme("/usr/share/man/man1/Applications/HexEditor.md") }));
TRY(Desktop::Launcher::seal_allowlist());

View file

@ -41,7 +41,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath wpath cpath unix thread"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domains({ "ImageViewer", "WindowManager" });

View file

@ -25,7 +25,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio getkeymap thread rpath cpath wpath recvfd sendfd unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::pledge("stdio getkeymap thread rpath cpath wpath recvfd sendfd"));

View file

@ -16,7 +16,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath recvfd sendfd unix proc exec"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("KeyboardSettings");
StringView selected_tab;

View file

@ -40,7 +40,7 @@ static ErrorOr<ByteBuffer> dump_bitmap(RefPtr<Gfx::Bitmap> bitmap, AK::StringVie
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio cpath rpath recvfd sendfd unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme("/usr/share/man/man1/Applications/Magnifier.md") }));
TRY(Desktop::Launcher::seal_allowlist());

View file

@ -20,7 +20,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix inet"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("Mail");

View file

@ -18,7 +18,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath recvfd sendfd unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("Mail");

View file

@ -22,7 +22,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio cpath rpath recvfd sendfd unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::pledge("stdio cpath rpath recvfd sendfd"));

View file

@ -33,7 +33,7 @@ ErrorOr<int> serenity_main(Main::Arguments args)
parser.add_positional_argument(adapter, "Adapter to display settings for", "adapter", Core::ArgsParser::Required::No);
parser.parse(args);
auto app = TRY(GUI::Application::try_create(args));
auto app = TRY(GUI::Application::create(args));
if (getuid() != 0) {
GUI::MessageBox::show_error(nullptr, "You need to be root to run Network Settings!"sv);

View file

@ -23,7 +23,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_positional_argument(file_path, "PDF file to open", "path", Core::ArgsParser::Required::No);
args_parser.parse(arguments);
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
auto app_icon = GUI::Icon::default_icon("app-pdf-viewer"sv);
Config::pledge_domain("PDFViewer");

View file

@ -41,7 +41,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::pledge("stdio recvfd sendfd rpath"));

View file

@ -31,7 +31,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio thread proc rpath cpath wpath recvfd sendfd unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TrackManager track_manager;

View file

@ -23,7 +23,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio thread recvfd sendfd rpath unix wpath cpath"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("PixelPaint");
app->set_config_domain(TRY(String::from_utf8("PixelPaint"sv)));

View file

@ -23,7 +23,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
argument_parser.add_positional_argument(file_to_load, "Presentation to load", "file", Core::ArgsParser::Required::No);
argument_parser.parse(arguments);
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
auto window = TRY(GUI::Window::try_create());
window->set_title("Presenter");
window->set_icon(GUI::Icon::default_icon("app-presenter"sv).bitmap_for_size(16));

View file

@ -14,7 +14,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd thread cpath rpath wpath unix proc exec"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
auto window = TRY(RunWindow::try_create());
window->move_to(16, GUI::Desktop::the().rect().bottom() - GUI::Desktop::the().taskbar_height() - 16 - window->height());

View file

@ -82,7 +82,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath unix proc exec"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath proc exec"));

View file

@ -36,7 +36,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_positional_argument(file_path, "Path to audio file to play", "file", Core::ArgsParser::Required::No);
args_parser.parse(arguments);
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
auto audio_client = TRY(Audio::ConnectionToServer::try_create());
auto decoder_client = TRY(ImageDecoderClient::Client::try_create());

View file

@ -43,7 +43,7 @@ static DeprecatedString get_absolute_path_to_selected_node(SpaceAnalyzer::TreeMa
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
// Configure application window.
auto app_icon = GUI::Icon::default_icon("app-space-analyzer"sv);

View file

@ -25,7 +25,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath fattr unix cpath wpath thread"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
StringView filename;

View file

@ -237,7 +237,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio thread proc recvfd sendfd rpath exec unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("SystemMonitor");

View file

@ -245,7 +245,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::sigaction(SIGCHLD, &act, nullptr));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::pledge("stdio tty rpath cpath wpath recvfd sendfd proc exec unix"));

View file

@ -16,7 +16,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath recvfd sendfd unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("Terminal");
StringView selected_tab;

View file

@ -20,7 +20,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd thread rpath cpath wpath unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("TextEditor");

View file

@ -25,7 +25,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd thread rpath cpath wpath unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
StringView file_to_edit;

View file

@ -19,7 +19,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_positional_argument(filename, "The video file to display.", "filename", Core::ArgsParser::Required::No);
args_parser.parse(arguments);
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
auto window = TRY(GUI::Window::try_create());
window->resize(640, 480);
window->set_resizable(true);

View file

@ -15,7 +15,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix proc exec"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domain("SystemServer");