diff --git a/Userland/Applications/PDFViewer/main.cpp b/Userland/Applications/PDFViewer/main.cpp index 5fc41301cc..31be4ed46d 100644 --- a/Userland/Applications/PDFViewer/main.cpp +++ b/Userland/Applications/PDFViewer/main.cpp @@ -6,18 +6,23 @@ */ #include "PDFViewerWidget.h" +#include #include #include #include #include #include -#include #include #include ErrorOr serenity_main(Main::Arguments arguments) { - auto app = GUI::Application::construct(arguments); + const char* file_path = nullptr; + Core::ArgsParser args_parser; + 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_icon = GUI::Icon::default_icon("app-pdf-viewer"); auto window = GUI::Window::construct(); @@ -37,8 +42,8 @@ ErrorOr serenity_main(Main::Arguments arguments) window->show(); window->set_icon(app_icon.bitmap_for_size(16)); - if (arguments.argc >= 2) { - auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, arguments.argv[1]); + if (file_path) { + auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, file_path); if (response.is_error()) return 1; pdf_viewer_widget->open_file(*response.value());