Client.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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(i32 parent_window_id, String const& path, Core::OpenMode mode);
  25. Result open_file(i32 parent_window_id, String const& window_title = {}, StringView const& path = Core::StandardPaths::home_directory());
  26. Result save_file(i32 parent_window_id, String const& name, String const ext);
  27. static Client& the();
  28. protected:
  29. void die() override;
  30. private:
  31. explicit Client()
  32. : IPC::ServerConnection<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>(*this, "/tmp/portal/filesystemaccess")
  33. {
  34. }
  35. virtual void handle_prompt_end(i32 error, Optional<IPC::File> const& fd, Optional<String> const& chosen_file) override;
  36. RefPtr<Core::Promise<Result>> m_promise;
  37. };
  38. }