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

HexEditor: Port HexEditor to LibMain

This commit is contained in:
Conor Byrne 2021-12-31 21:49:55 +00:00 committed by Andreas Kling
parent ad57289307
commit e92b6047ad
2 changed files with 18 additions and 29 deletions

View file

@ -1,65 +1,54 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org>
* Copyright (c) 2021, Conor Byrne <conor@cbyrne.dev>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "HexEditorWidget.h"
#include <LibConfig/Client.h>
#include <LibCore/System.h>
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/Icon.h>
#include <LibGUI/Menubar.h>
#include <LibGUI/MessageBox.h>
#include <LibMain/Main.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv)
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
if (pledge("stdio recvfd sendfd rpath unix cpath wpath thread", nullptr) < 0) {
perror("pledge");
return 1;
}
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix cpath wpath thread"));
auto app = GUI::Application::construct(argc, argv);
auto app = TRY(GUI::Application::try_create(arguments));
Config::pledge_domains("HexEditor");
auto app_icon = GUI::Icon::default_icon("app-hex-editor");
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-hex-editor"));
auto window = GUI::Window::construct();
auto window = TRY(GUI::Window::try_create());
window->set_title("Hex Editor");
window->resize(640, 400);
auto& hex_editor_widget = window->set_main_widget<HexEditorWidget>();
auto hex_editor_widget = TRY(window->try_set_main_widget<HexEditorWidget>());
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
if (hex_editor_widget.request_close())
if (hex_editor_widget->request_close())
return GUI::Window::CloseRequestDecision::Close;
return GUI::Window::CloseRequestDecision::StayOpen;
};
if (unveil("/res", "r") < 0) {
perror("unveil");
return 1;
}
TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil("/tmp/portal/filesystemaccess", "rw"));
TRY(Core::System::unveil(nullptr, nullptr));
if (unveil("/tmp/portal/filesystemaccess", "rw") < 0) {
perror("unveil");
return 1;
}
if (unveil(nullptr, nullptr) < 0) {
perror("unveil");
return 1;
}
hex_editor_widget.initialize_menubar(*window);
hex_editor_widget->initialize_menubar(*window);
window->show();
window->set_icon(app_icon.bitmap_for_size(16));
if (argc > 1) {
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window->window_id(), argv[1]);
if (arguments.argc > 1) {
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window->window_id(), arguments.strings[1]);
if (response.error != 0) {
if (response.error != -1)
@ -67,7 +56,7 @@ int main(int argc, char** argv)
return 1;
}
hex_editor_widget.open_file(*response.fd, *response.chosen_file);
hex_editor_widget->open_file(*response.fd, *response.chosen_file);
}
return app->exec();