Client.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2021, timmot <tiwwot@protonmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <FileSystemAccessServer/FileSystemAccessClientEndpoint.h>
  8. #include <FileSystemAccessServer/FileSystemAccessServerEndpoint.h>
  9. #include <LibCore/File.h>
  10. #include <LibCore/Promise.h>
  11. #include <LibCore/StandardPaths.h>
  12. #include <LibIPC/ServerConnection.h>
  13. namespace FileSystemAccessClient {
  14. struct Result {
  15. i32 error;
  16. Optional<i32> fd;
  17. Optional<String> chosen_file;
  18. };
  19. class Client final
  20. : public IPC::ServerConnection<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>
  21. , public FileSystemAccessClientEndpoint {
  22. C_OBJECT(Client)
  23. public:
  24. Result request_file_read_only_approved(i32 parent_window_id, String const& path);
  25. Result request_file(i32 parent_window_id, String const& path, Core::OpenMode mode);
  26. Result open_file(i32 parent_window_id, String const& window_title = {}, StringView const& path = Core::StandardPaths::home_directory());
  27. Result save_file(i32 parent_window_id, String const& name, String const ext);
  28. static Client& the();
  29. protected:
  30. void die() override;
  31. private:
  32. explicit Client()
  33. : IPC::ServerConnection<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>(*this, "/tmp/portal/filesystemaccess")
  34. {
  35. }
  36. virtual void handle_prompt_end(i32 error, Optional<IPC::File> const& fd, Optional<String> const& chosen_file) override;
  37. RefPtr<Core::Promise<Result>> m_promise;
  38. };
  39. }