Serenity Operating System
at master 56 lines 1.8 kB view raw
1/* 2 * Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org> 3 * Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org> 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#include "PDFViewerWidget.h" 9#include <LibConfig/Client.h> 10#include <LibCore/ArgsParser.h> 11#include <LibCore/System.h> 12#include <LibFileSystemAccessClient/Client.h> 13#include <LibGUI/Application.h> 14#include <LibGUI/Icon.h> 15#include <LibGUI/Menubar.h> 16#include <LibGUI/Window.h> 17#include <LibMain/Main.h> 18 19ErrorOr<int> serenity_main(Main::Arguments arguments) 20{ 21 StringView file_path; 22 Core::ArgsParser args_parser; 23 args_parser.add_positional_argument(file_path, "PDF file to open", "path", Core::ArgsParser::Required::No); 24 args_parser.parse(arguments); 25 26 auto app = TRY(GUI::Application::try_create(arguments)); 27 auto app_icon = GUI::Icon::default_icon("app-pdf-viewer"sv); 28 29 Config::pledge_domain("PDFViewer"); 30 31 auto window = TRY(GUI::Window::try_create()); 32 window->set_title("PDF Viewer"); 33 window->resize(640, 400); 34 35 TRY(Core::System::pledge("stdio recvfd sendfd rpath unix")); 36 37 TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw")); 38 TRY(Core::System::unveil("/res", "r")); 39 TRY(Core::System::unveil(nullptr, nullptr)); 40 41 auto pdf_viewer_widget = TRY(window->set_main_widget<PDFViewerWidget>()); 42 43 pdf_viewer_widget->initialize_menubar(*window); 44 45 window->show(); 46 window->set_icon(app_icon.bitmap_for_size(16)); 47 48 if (!file_path.is_empty()) { 49 auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, file_path); 50 if (response.is_error()) 51 return 1; 52 pdf_viewer_widget->open_file(response.value().filename(), response.value().release_stream()); 53 } 54 55 return app->exec(); 56}