2021-07-11 15:16:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, timmot <tiwwot@protonmail.com>
|
2022-01-17 04:14:31 +00:00
|
|
|
* Copyright (c) 2022, Mustafa Quraish <mustafa@serenityos.org>
|
2021-07-11 15:16:26 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-02-26 16:24:22 +00:00
|
|
|
#include <AK/HashMap.h>
|
2021-07-11 15:16:26 +00:00
|
|
|
#include <FileSystemAccessServer/FileSystemAccessClientEndpoint.h>
|
|
|
|
#include <FileSystemAccessServer/FileSystemAccessServerEndpoint.h>
|
|
|
|
#include <LibCore/File.h>
|
|
|
|
#include <LibCore/Promise.h>
|
2021-08-06 01:34:14 +00:00
|
|
|
#include <LibCore/StandardPaths.h>
|
2022-01-16 06:56:38 +00:00
|
|
|
#include <LibGUI/Window.h>
|
2022-02-25 10:27:37 +00:00
|
|
|
#include <LibIPC/ConnectionToServer.h>
|
2021-07-11 15:16:26 +00:00
|
|
|
|
|
|
|
namespace FileSystemAccessClient {
|
|
|
|
|
2022-01-17 04:14:31 +00:00
|
|
|
using Result = ErrorOr<NonnullRefPtr<Core::File>>;
|
2022-01-16 06:56:38 +00:00
|
|
|
|
2021-07-11 15:16:26 +00:00
|
|
|
class Client final
|
2022-02-25 10:27:37 +00:00
|
|
|
: public IPC::ConnectionToServer<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>
|
2021-07-11 15:16:26 +00:00
|
|
|
, public FileSystemAccessClientEndpoint {
|
2022-09-06 06:04:06 +00:00
|
|
|
IPC_CLIENT_CONNECTION(Client, "/tmp/session/%sid/portal/filesystemaccess"sv)
|
2021-07-11 15:16:26 +00:00
|
|
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
Result try_request_file_read_only_approved(GUI::Window* parent_window, DeprecatedString const& path);
|
|
|
|
Result try_request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::OpenMode mode);
|
|
|
|
Result try_open_file(GUI::Window* parent_window, DeprecatedString const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::OpenMode requested_access = Core::OpenMode::ReadOnly);
|
|
|
|
Result try_save_file(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::OpenMode requested_access = Core::OpenMode::WriteOnly | Core::OpenMode::Truncate);
|
2022-01-16 06:56:38 +00:00
|
|
|
|
2021-07-11 15:16:26 +00:00
|
|
|
static Client& the();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void die() override;
|
|
|
|
|
|
|
|
private:
|
2022-01-14 13:12:49 +00:00
|
|
|
explicit Client(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
2022-02-25 10:27:37 +00:00
|
|
|
: IPC::ConnectionToServer<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>(*this, move(socket))
|
2021-07-11 15:16:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
virtual void handle_prompt_end(i32 request_id, i32 error, Optional<IPC::File> const& fd, Optional<DeprecatedString> const& chosen_file) override;
|
2021-07-11 15:16:26 +00:00
|
|
|
|
2022-02-26 16:24:22 +00:00
|
|
|
int get_new_id();
|
|
|
|
Result handle_promise(int);
|
|
|
|
|
|
|
|
struct PromiseAndWindow {
|
|
|
|
RefPtr<Core::Promise<Result>> promise {};
|
|
|
|
GUI::Window* parent_window { nullptr };
|
|
|
|
};
|
|
|
|
|
|
|
|
HashMap<int, PromiseAndWindow> m_promises {};
|
|
|
|
int m_last_id { 0 };
|
2021-07-11 15:16:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|