1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:37:35 +00:00

TextEditor+LibGUI: Use unveil and FileSystemAccessServer

Making use of the new FileSystemAccessServer we are able to use
unveil without restricting our ability to open and save files.
A file argument will be unveiled automatically however all other files
require user action via the FileSystemAccessServer to gain access.
This commit is contained in:
Timothy 2021-06-30 06:13:06 -07:00 committed by Andreas Kling
parent 41ce2debda
commit 73ae5200a9
6 changed files with 109 additions and 18 deletions

View file

@ -8,22 +8,43 @@
#include <AK/Function.h>
#include <AK/LexicalPath.h>
#include <FileSystemAccessServer/ClientConnection.h>
#include <FileSystemAccessServer/FileSystemAccessClientEndpoint.h>
#include <FileSystemAccessServer/FileSystemAccessServerEndpoint.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Application.h>
#include <LibGUI/Icon.h>
#include <LibGUI/TextEditor.h>
#include <LibGUI/Widget.h>
#include <LibGUI/Window.h>
#include <LibIPC/ServerConnection.h>
#include <LibWeb/Forward.h>
namespace TextEditor {
class FileSystemAccessClient final
: public IPC::ServerConnection<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>
, public FileSystemAccessClientEndpoint {
C_OBJECT(FileSystemAccessClient)
public:
virtual void die() override
{
}
private:
explicit FileSystemAccessClient()
: IPC::ServerConnection<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>(*this, "/tmp/portal/filesystemaccess")
{
}
};
class MainWidget final : public GUI::Widget {
C_OBJECT(MainWidget);
public:
virtual ~MainWidget() override;
bool open_file(const String& path);
bool read_file_and_close(int fd, String const& path);
bool request_close();
GUI::TextEditor& editor() { return *m_editor; }
@ -53,6 +74,8 @@ private:
virtual void drop_event(GUI::DropEvent&) override;
NonnullRefPtr<FileSystemAccessClient> m_file_system_access_client;
RefPtr<GUI::TextEditor> m_editor;
String m_path;
String m_name;