main.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "PDFViewerWidget.h"
  8. #include <LibCore/System.h>
  9. #include <LibFileSystemAccessClient/Client.h>
  10. #include <LibGUI/Application.h>
  11. #include <LibGUI/Icon.h>
  12. #include <LibGUI/Menubar.h>
  13. #include <LibGUI/MessageBox.h>
  14. #include <LibGUI/Window.h>
  15. #include <LibMain/Main.h>
  16. ErrorOr<int> serenity_main(Main::Arguments arguments)
  17. {
  18. auto app = GUI::Application::construct(arguments);
  19. auto app_icon = GUI::Icon::default_icon("app-pdf-viewer");
  20. auto window = GUI::Window::construct();
  21. window->set_title("PDF Viewer");
  22. window->resize(640, 400);
  23. TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
  24. TRY(Core::System::unveil("/res", "r"));
  25. TRY(Core::System::unveil("/tmp/portal/filesystemaccess", "rw"));
  26. TRY(Core::System::unveil(nullptr, nullptr));
  27. auto pdf_viewer_widget = TRY(window->try_set_main_widget<PDFViewerWidget>());
  28. pdf_viewer_widget->initialize_menubar(*window);
  29. window->show();
  30. window->set_icon(app_icon.bitmap_for_size(16));
  31. if (arguments.argc >= 2) {
  32. auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, arguments.argv[1]);
  33. if (response.is_error())
  34. return 1;
  35. pdf_viewer_widget->open_file(*response.value());
  36. }
  37. return app->exec();
  38. }