2021-07-12 01:16:26 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, timmot <tiwwot@protonmail.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <FileSystemAccessServer/FileSystemAccessClientEndpoint.h>
|
|
|
|
|
#include <FileSystemAccessServer/FileSystemAccessServerEndpoint.h>
|
|
|
|
|
#include <LibCore/File.h>
|
|
|
|
|
#include <LibCore/Promise.h>
|
2021-08-06 11:34:14 +10:00
|
|
|
#include <LibCore/StandardPaths.h>
|
2021-07-12 01:16:26 +10:00
|
|
|
#include <LibIPC/ServerConnection.h>
|
|
|
|
|
|
|
|
|
|
namespace FileSystemAccessClient {
|
|
|
|
|
|
|
|
|
|
struct Result {
|
|
|
|
|
i32 error;
|
|
|
|
|
Optional<i32> fd;
|
|
|
|
|
Optional<String> chosen_file;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Client final
|
|
|
|
|
: public IPC::ServerConnection<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>
|
|
|
|
|
, public FileSystemAccessClientEndpoint {
|
2022-01-14 13:12:49 +00:00
|
|
|
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/filesystemaccess")
|
2021-07-12 01:16:26 +10:00
|
|
|
|
|
|
|
|
public:
|
2021-09-06 00:51:32 -04:00
|
|
|
Result request_file_read_only_approved(i32 parent_window_id, String const& path);
|
2021-07-12 01:16:26 +10:00
|
|
|
Result request_file(i32 parent_window_id, String const& path, Core::OpenMode mode);
|
2021-11-12 19:33:45 +01:00
|
|
|
Result open_file(i32 parent_window_id, String const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::OpenMode requested_access = Core::OpenMode::ReadOnly);
|
|
|
|
|
Result save_file(i32 parent_window_id, String const& name, String const ext, Core::OpenMode requested_access = Core::OpenMode::WriteOnly | Core::OpenMode::Truncate);
|
2021-07-12 01:16:26 +10:00
|
|
|
|
|
|
|
|
static Client& the();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void die() override;
|
|
|
|
|
|
|
|
|
|
private:
|
2022-01-14 13:12:49 +00:00
|
|
|
explicit Client(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
|
|
|
|
: IPC::ServerConnection<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>(*this, move(socket))
|
2021-07-12 01:16:26 +10:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void handle_prompt_end(i32 error, Optional<IPC::File> const& fd, Optional<String> const& chosen_file) override;
|
|
|
|
|
|
|
|
|
|
RefPtr<Core::Promise<Result>> m_promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|