1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:17:34 +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

@ -15,4 +15,4 @@ set(SOURCES
) )
serenity_app(TextEditor ICON app-text-editor) serenity_app(TextEditor ICON app-text-editor)
target_link_libraries(TextEditor LibWeb LibMarkdown LibGUI LibShell LibRegex LibDesktop LibCpp LibJS LibSQL LibFileSystemAccessClient LibConfig) target_link_libraries(TextEditor LibWeb LibMarkdown LibGUI LibShell LibRegex LibDesktop LibCpp LibJS LibSQL LibFileSystemAccessClient LibConfig LibMain)

View file

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