diff --git a/Userland/Applications/HexEditor/main.cpp b/Userland/Applications/HexEditor/main.cpp index ade8c15f23..4ae7ffe91a 100644 --- a/Userland/Applications/HexEditor/main.cpp +++ b/Userland/Applications/HexEditor/main.cpp @@ -2,12 +2,14 @@ * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Mustafa Quraish * Copyright (c) 2021, Conor Byrne + * Copyright (c) 2024, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #include "HexEditorWidget.h" #include +#include #include #include #include @@ -24,6 +26,12 @@ ErrorOr serenity_main(Main::Arguments arguments) auto app = TRY(GUI::Application::create(arguments)); + StringView filename; + + Core::ArgsParser args_parser; + args_parser.add_positional_argument(filename, "File to open", "path", Core::ArgsParser::Required::No); + args_parser.parse(arguments); + TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme("/usr/share/man/man1/Applications/HexEditor.md") })); TRY(Desktop::Launcher::seal_allowlist()); @@ -54,9 +62,9 @@ ErrorOr serenity_main(Main::Arguments arguments) window->show(); window->set_icon(app_icon.bitmap_for_size(16)); - if (arguments.argc > 1) { + if (!filename.is_empty()) { // FIXME: Using `try_request_file_read_only_approved` doesn't work here since the file stored in the editor is only readable. - auto response = FileSystemAccessClient::Client::the().request_file(window, arguments.strings[1], Core::File::OpenMode::ReadWrite); + auto response = FileSystemAccessClient::Client::the().request_file(window, filename, Core::File::OpenMode::ReadWrite); if (!response.is_error()) hex_editor_widget->open_file(response.value().filename(), response.value().release_stream()); }