mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:44:58 +00:00

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.
38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2021, Hunter Salyer <thefalsehonesty@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibCore/ArgsParser.h>
|
|
#include <LibGUI/Application.h>
|
|
#include <LibGUI/Icon.h>
|
|
#include <LibGUI/Window.h>
|
|
#include <LibMain/Main.h>
|
|
|
|
#include "VideoPlayerWidget.h"
|
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|
{
|
|
StringView filename = ""sv;
|
|
Core::ArgsParser args_parser;
|
|
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::create(arguments));
|
|
auto window = TRY(GUI::Window::try_create());
|
|
window->resize(640, 480);
|
|
window->set_resizable(true);
|
|
|
|
auto main_widget = TRY(window->set_main_widget<VideoPlayer::VideoPlayerWidget>());
|
|
main_widget->update_title();
|
|
TRY(main_widget->initialize_menubar(window));
|
|
|
|
if (!filename.is_empty())
|
|
main_widget->open_file(filename);
|
|
|
|
window->show();
|
|
window->set_icon(GUI::Icon::default_icon("app-video-player"sv).bitmap_for_size(16));
|
|
|
|
return app->exec();
|
|
}
|