mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +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:
parent
41ce2debda
commit
73ae5200a9
6 changed files with 109 additions and 18 deletions
|
@ -7,6 +7,8 @@
|
|||
#include "FileArgument.h"
|
||||
#include "MainWidget.h"
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibGUI/Menubar.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
@ -30,6 +32,43 @@ int main(int argc, char** argv)
|
|||
|
||||
parser.parse(argc, argv);
|
||||
|
||||
if (file_to_edit) {
|
||||
FileArgument parsed_argument(file_to_edit);
|
||||
|
||||
auto path_to_unveil = Core::File::real_path_for(parsed_argument.filename());
|
||||
if (unveil(path_to_unveil.characters(), "rwc") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (unveil(Core::StandardPaths::config_directory().characters(), "rw") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unveil("/res", "r") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unveil("/tmp/portal/launch", "rw") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unveil("/tmp/portal/webcontent", "rw") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unveil("/tmp/portal/filesystemaccess", "rw") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
unveil(nullptr, nullptr);
|
||||
|
||||
StringView preview_mode_view = preview_mode;
|
||||
|
||||
auto app_icon = GUI::Icon::default_icon("app-text-editor");
|
||||
|
@ -67,8 +106,15 @@ int main(int argc, char** argv)
|
|||
if (file_to_edit) {
|
||||
// A file name was passed, parse any possible line and column numbers included.
|
||||
FileArgument parsed_argument(file_to_edit);
|
||||
if (!text_widget.open_file(parsed_argument.filename()))
|
||||
auto absolute_path = Core::File::real_path_for(parsed_argument.filename());
|
||||
auto file = Core::File::open(absolute_path, Core::OpenMode::ReadWrite);
|
||||
|
||||
if (file.is_error())
|
||||
return 1;
|
||||
|
||||
if (!text_widget.read_file_and_close(file.value()->leak_fd(), absolute_path))
|
||||
return 1;
|
||||
|
||||
text_widget.editor().set_cursor_and_focus_line(parsed_argument.line().value_or(1) - 1, parsed_argument.column().value_or(0));
|
||||
}
|
||||
text_widget.update_title();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue