From 3a7e42ba73b77d87cea38fa9e9dc4493a2db072f Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Mon, 6 Sep 2021 01:45:53 -0400 Subject: [PATCH] TextEditor: Remove unveil() for CLI file, use FileSystemAccessServer Previously we unveiled the file specified through the command-line interface. Now, we just make the request through the FileSystemAccessServer instead. --- Userland/Applications/TextEditor/main.cpp | 38 +++++------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/Userland/Applications/TextEditor/main.cpp b/Userland/Applications/TextEditor/main.cpp index 732bbf5ebbb..880dcf04a3c 100644 --- a/Userland/Applications/TextEditor/main.cpp +++ b/Userland/Applications/TextEditor/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -34,22 +35,6 @@ int main(int argc, char** argv) parser.parse(argc, argv); - String file_to_edit_full_path; - - if (file_to_edit) { - FileArgument parsed_argument(file_to_edit); - - file_to_edit_full_path = Core::File::absolute_path(parsed_argument.filename()); - VERIFY(!file_to_edit_full_path.is_empty()); - if (Core::File::exists(parsed_argument.filename())) { - dbgln("unveil for: {}", file_to_edit_full_path); - if (unveil(file_to_edit_full_path.characters(), "r") < 0) { - perror("unveil"); - return 1; - } - } - } - if (unveil("/res", "r") < 0) { perror("unveil"); return 1; @@ -104,29 +89,22 @@ int main(int argc, char** argv) text_widget.initialize_menubar(*window); + window->show(); + window->set_icon(app_icon.bitmap_for_size(16)); + if (file_to_edit) { - // A file name was passed, parse any possible line and column numbers included. FileArgument parsed_argument(file_to_edit); - if (Core::File::exists(file_to_edit_full_path)) { - auto file = Core::File::open(file_to_edit_full_path, Core::OpenMode::ReadOnly); + auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window->window_id(), parsed_argument.filename()); - if (file.is_error()) { - GUI::MessageBox::show_error(window, String::formatted("Opening \"{}\" failed: {}", file_to_edit_full_path, file.error())); + if (response.error == 0) { + if (!text_widget.read_file_and_close(*response.fd, *response.chosen_file)) return 1; - } - - if (!text_widget.read_file_and_close(file.value()->leak_fd(), file_to_edit_full_path)) - return 1; - text_widget.editor().set_cursor_and_focus_line(parsed_argument.line().value_or(1) - 1, parsed_argument.column().value_or(0)); } else { - text_widget.open_nonexistent_file(file_to_edit_full_path); + text_widget.open_nonexistent_file(parsed_argument.filename()); } } text_widget.update_title(); - window->show(); - window->set_icon(app_icon.bitmap_for_size(16)); - return app->exec(); }