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

PDFViewer: Use ArgsParser

This commit is contained in:
Matthew Olsson 2022-03-28 11:56:09 -07:00 committed by Andreas Kling
parent 468ceb1b48
commit 6bed20f456

View file

@ -6,18 +6,23 @@
*/
#include "PDFViewerWidget.h"
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/Application.h>
#include <LibGUI/Icon.h>
#include <LibGUI/Menubar.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Window.h>
#include <LibMain/Main.h>
ErrorOr<int> 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<int> 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());