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

@ -11,7 +11,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath wpath cpath 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

@ -231,7 +231,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_domain("AudioApplet");
TRY(Core::System::unveil("/tmp/session/%sid/portal/audio", "rw"));
TRY(Core::System::unveil("/res", "r"));

View file

@ -18,7 +18,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("ClipboardHistory");
Config::monitor_domain("ClipboardHistory");

View file

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

View file

@ -164,7 +164,7 @@ private:
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));
TRY(Core::System::unveil("/tmp/session/%sid/portal/notify", "rw"));
TRY(Core::System::unveil("/res", "r"));

View file

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

View file

@ -17,7 +17,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));
app->set_quit_when_last_window_deleted(false);
// We need to obtain the WM connection here as well before the pledge shortening.

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");

View file

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

View file

@ -38,7 +38,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(Core::System::unveil("/tmp/session/%sid/portal/launch", "rw"));
TRY(Core::System::unveil("/res", "r"));

View file

@ -89,7 +89,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));
TRY(Core::System::pledge("stdio rpath recvfd sendfd"));
TRY(Core::System::unveil("/res", "r"));

View file

@ -185,7 +185,7 @@ void Canvas::draw()
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("/res", "r"));

View file

@ -105,7 +105,7 @@ void Canvas::draw(Gfx::Painter& painter)
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("/res", "r"));

View file

@ -396,7 +396,7 @@ ErrorOr<void> Mandelbrot::export_image(DeprecatedString const& export_path, Imag
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 wpath cpath"));

View file

@ -18,7 +18,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath wpath cpath 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

@ -66,7 +66,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

@ -161,7 +161,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_option(speed, "Speed (default = 1)", "speed", 's', "number");
args_parser.parse(arguments);
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

@ -22,7 +22,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_option(refresh_rate, "Refresh rate", "rate", 'r', "milliseconds");
args_parser.parse(arguments);
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::pledge("stdio recvfd sendfd rpath prot_exec map_fixed"));

View file

@ -15,7 +15,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix thread"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));
TRY(Core::System::unveil("/res", "r"));

View file

@ -66,7 +66,7 @@ void UnregisteredWidget::paint_event(GUI::PaintEvent& event)
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio thread recvfd sendfd cpath rpath wpath unix"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domains({ "GMLPlayground", "Calendar" });
app->set_config_domain(TRY("GMLPlayground"_string));

View file

@ -41,7 +41,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd tty rpath cpath wpath proc exec unix fattr thread ptrace"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domains({ "HackStudio", "Terminal", "FileManager" });
auto window = GUI::Window::construct();

View file

@ -58,7 +58,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return 1;
}
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-profiler"sv));
DeprecatedString perfcore_file;

View file

@ -21,7 +21,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_positional_argument(file_to_open, "Path to SQL script or DB", "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 app_icon = GUI::Icon::default_icon("app-sql-studio"sv);

View file

@ -33,7 +33,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
srand(time(nullptr));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-2048"sv));
auto window = TRY(GUI::Window::try_create());

View file

@ -23,7 +23,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));
auto const app_name = "BrickGame"sv;
auto const title = "Brick Game"sv;

View file

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

View file

@ -22,7 +22,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));
auto const app_name = "ColorLines"sv;
auto const title = "Color Lines"sv;

View file

@ -21,7 +21,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("FlappyBug");

View file

@ -56,7 +56,7 @@ static int get_number_of_moves_from_ai(Board const& board)
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));
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-flood"sv));
auto window = TRY(GUI::Window::try_create());

View file

@ -30,7 +30,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));
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme("/usr/share/man/man6/GameOfLife.md") }));
TRY(Desktop::Launcher::seal_allowlist());

View file

@ -29,7 +29,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-hearts"sv));
Config::pledge_domains({ "Games", "Hearts" });

View file

@ -25,7 +25,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("MasterWord");

View file

@ -29,7 +29,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("Minesweeper");

View file

@ -30,7 +30,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("Snake");
Config::monitor_domain("Snake");

View file

@ -29,7 +29,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));
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-solitaire"sv));
auto const man_file = "/usr/share/man/man6/Solitaire.md"sv;

View file

@ -42,7 +42,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));
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-spider"sv));
Config::pledge_domains({ "Games", "Spider" });

View file

@ -68,37 +68,43 @@ Application* Application::the()
return *s_the;
}
Application::Application(int argc, char** argv)
ErrorOr<NonnullRefPtr<Application>> Application::create(Main::Arguments const& arguments)
{
VERIFY(!*s_the);
*s_the = *this;
m_event_loop = make<Core::EventLoop>();
if (*s_the)
return Error::from_string_literal("An Application has already been created for this process!");
auto application = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Application {}));
*s_the = *application;
application->m_event_loop = TRY(try_make<Core::EventLoop>());
ConnectionToWindowServer::the();
Clipboard::initialize({});
if (argc > 0)
m_invoked_as = argv[0];
if (arguments.argc > 0)
application->m_invoked_as = arguments.argv[0];
if (getenv("GUI_FOCUS_DEBUG"))
m_focus_debugging_enabled = true;
application->m_focus_debugging_enabled = true;
if (getenv("GUI_HOVER_DEBUG"))
m_hover_debugging_enabled = true;
application->m_hover_debugging_enabled = true;
if (getenv("GUI_DND_DEBUG"))
m_dnd_debugging_enabled = true;
application->m_dnd_debugging_enabled = true;
for (int i = 1; i < argc; i++) {
DeprecatedString arg(argv[i]);
m_args.append(move(arg));
}
for (auto arg : arguments.strings.slice(1))
TRY(application->m_args.try_append(arg));
m_tooltip_show_timer = Core::Timer::create_single_shot(700, [this] {
request_tooltip_show();
}).release_value_but_fixme_should_propagate_errors();
application->m_tooltip_show_timer = TRY(Core::Timer::create_single_shot(700, [weak_application = application->make_weak_ptr<Application>()] {
weak_application->request_tooltip_show();
}));
m_tooltip_hide_timer = Core::Timer::create_single_shot(50, [this] {
tooltip_hide_timer_did_fire();
}).release_value_but_fixme_should_propagate_errors();
application->m_tooltip_hide_timer = TRY(Core::Timer::create_single_shot(50, [weak_application = application->make_weak_ptr<Application>()] {
weak_application->tooltip_hide_timer_did_fire();
}));
return application;
}
static bool s_in_teardown;

View file

@ -22,11 +22,13 @@
namespace GUI {
class Application : public Core::Object {
C_OBJECT(Application);
C_OBJECT_ABSTRACT(Application);
public:
static Application* the();
static ErrorOr<NonnullRefPtr<Application>> create(Main::Arguments const& arguments);
~Application();
static bool in_teardown();
@ -97,11 +99,7 @@ public:
void register_recent_file_actions(Badge<GUI::Menu>, Vector<NonnullRefPtr<GUI::Action>>);
private:
Application(int argc, char** argv);
Application(Main::Arguments const& arguments)
: Application(arguments.argc, arguments.argv)
{
}
Application() = default;
virtual void event(Core::Event&) override;

View file

@ -10,11 +10,11 @@
#include <LibIPC/SingleServer.h>
#include <LibMain/Main.h>
ErrorOr<int> serenity_main(Main::Arguments)
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd rpath cpath wpath unix thread"));
auto app = TRY(GUI::Application::try_create(0, nullptr));
auto app = TRY(GUI::Application::create(arguments));
app->set_quit_when_last_window_deleted(false);
auto client = TRY(IPC::take_over_accepted_client_from_system_server<FileSystemAccessServer::ConnectionFromClient>());

View file

@ -61,7 +61,7 @@ static void login(Core::Account const& account, LoginWindow& window)
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 cpath chown rpath exec proc id"));
TRY(Core::System::unveil("/home", "r"));

View file

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

View file

@ -41,7 +41,7 @@ static ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu(GUI::Window&);
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd proc exec rpath unix sigaction"));
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Config::pledge_domains({ "Taskbar", "Calendar" });
Config::monitor_domain("Taskbar");
Config::monitor_domain("Calendar");

View file

@ -25,8 +25,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.parse(arguments);
// A Core::EventLoop is all we need, but ConnectionToWindowServer needs a full Application object.
char* dummy_argv[] = { arguments.argv[0] };
auto app = TRY(GUI::Application::try_create(1, dummy_argv));
auto app = TRY(GUI::Application::create(arguments));
auto screen_layout = GUI::ConnectionToWindowServer::the().get_screen_layout();
if (screen < 0 || (size_t)screen >= screen_layout.screens.size()) {
warnln("invalid screen index: {}", screen);

View file

@ -59,7 +59,7 @@ static ErrorOr<Options> parse_options(Main::Arguments arguments)
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Options options = TRY(parse_options(arguments));

View file

@ -12,7 +12,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Core::ArgsParser args_parser;
StringView title {};

View file

@ -62,7 +62,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_positional_argument(watch_command, "Command to run in watch mode", "command", Core::ArgsParser::Required::No);
args_parser.parse(arguments);
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
auto& clipboard = GUI::Clipboard::the();

View file

@ -112,7 +112,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
output_path = Core::DateTime::now().to_deprecated_string("screenshot-%Y-%m-%d-%H-%M-%S.png"sv);
}
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
Optional<Gfx::IntRect> crop_region;
if (select_region) {
auto window = GUI::Window::construct();

View file

@ -31,7 +31,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_positional_argument(path, "Wallpaper to set", "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 rpath unix sendfd"));

View file

@ -10,7 +10,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
auto app = TRY(GUI::Application::try_create(arguments));
auto app = TRY(GUI::Application::create(arguments));
int flash_flush = -1;
Core::ArgsParser args_parser;