main.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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::unveil("/res", "r"));
  24. TRY(Core::System::unveil("/tmp/portal/filesystemaccess", "rw"));
  25. TRY(Core::System::unveil(nullptr, nullptr));
  26. auto& pdf_viewer_widget = window->set_main_widget<PDFViewerWidget>();
  27. pdf_viewer_widget.initialize_menubar(*window);
  28. window->show();
  29. window->set_icon(app_icon.bitmap_for_size(16));
  30. if (arguments.argc >= 2) {
  31. auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window->window_id(), arguments.argv[1]);
  32. if (response.error != 0) {
  33. if (response.error != -1)
  34. GUI::MessageBox::show_error(window, String::formatted("Opening \"{}\" failed: {}", *response.chosen_file, strerror(response.error)));
  35. return 1;
  36. }
  37. pdf_viewer_widget.open_file(*response.fd, *response.chosen_file);
  38. }
  39. return app->exec();
  40. }