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

TextEditor: Port to LibMain :^)

This opens up using TRY() for syscalls and Core::Object creation.
This commit is contained in:
Andreas Kling 2021-11-23 14:21:27 +01:00
parent 5a3f5582ba
commit 6536198693
2 changed files with 13 additions and 33 deletions

View file

@ -8,22 +8,19 @@
#include "MainWidget.h"
#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <LibCore/StandardPaths.h>
#include <LibCore/System.h>
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/Menubar.h>
#include <LibGUI/MessageBox.h>
#include <LibMain/Main.h>
using namespace TextEditor;
int main(int argc, char** argv)
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
if (pledge("stdio recvfd sendfd thread rpath cpath wpath unix", nullptr) < 0) {
perror("pledge");
return 1;
}
TRY(Core::System::pledge("stdio recvfd sendfd thread rpath cpath wpath unix", nullptr));
auto app = GUI::Application::construct(argc, argv);
auto app = TRY(GUI::Application::try_create(arguments));
Config::pledge_domains("TextEditor");
@ -32,36 +29,19 @@ int main(int argc, char** argv)
Core::ArgsParser parser;
parser.add_option(preview_mode, "Preview mode, one of 'none', 'html', 'markdown', 'auto'", "preview-mode", '\0', "mode");
parser.add_positional_argument(file_to_edit, "File to edit, with optional starting line and column number", "file[:line[:column]]", Core::ArgsParser::Required::No);
parser.parse(arguments);
parser.parse(argc, argv);
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);
TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil("/tmp/portal/launch", "rw"));
TRY(Core::System::unveil("/tmp/portal/webcontent", "rw"));
TRY(Core::System::unveil("/tmp/portal/filesystemaccess", "rw"));
TRY(Core::System::unveil(nullptr, nullptr));
StringView preview_mode_view = preview_mode;
auto app_icon = GUI::Icon::default_icon("app-text-editor");
auto window = GUI::Window::construct();
auto window = TRY(GUI::Window::try_create());
window->resize(640, 400);
auto& text_widget = window->set_main_widget<MainWidget>();