2020-08-22 03:51:32 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
2022-09-12 11:06:24 -03:00
|
|
|
* Copyright (c) 2021, networkException <networkexception@serenityos.org>
|
2022-04-28 13:13:48 -03:00
|
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
2021-12-17 19:59:01 -03:00
|
|
|
* Copyright (c) 2021, Antonio Di Stefano <tonio9681@gmail.com>
|
2022-01-01 15:19:10 -03:00
|
|
|
* Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
|
2020-08-22 03:51:32 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-22 03:51:32 -03:00
|
|
|
*/
|
|
|
|
|
|
2022-05-10 10:54:43 -03:00
|
|
|
#include "MainWidget.h"
|
2020-08-21 14:36:20 -03:00
|
|
|
#include "PreviewWidget.h"
|
2021-09-05 08:23:38 -03:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2021-11-27 09:34:52 -03:00
|
|
|
#include <LibCore/System.h>
|
2021-08-18 19:07:39 -03:00
|
|
|
#include <LibFileSystemAccessClient/Client.h>
|
2020-08-21 14:36:20 -03:00
|
|
|
#include <LibGUI/Application.h>
|
2020-11-02 16:30:17 -03:00
|
|
|
#include <LibGUI/Icon.h>
|
2021-07-16 06:05:21 -03:00
|
|
|
#include <LibGUI/Menu.h>
|
|
|
|
|
#include <LibGUI/Menubar.h>
|
2022-08-13 16:11:11 -03:00
|
|
|
#include <LibGUI/MessageBox.h>
|
2020-08-21 14:36:20 -03:00
|
|
|
#include <LibGUI/Window.h>
|
2021-11-27 09:34:52 -03:00
|
|
|
#include <LibMain/Main.h>
|
2020-08-21 14:36:20 -03:00
|
|
|
|
2021-11-27 09:34:52 -03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2020-08-21 14:36:20 -03:00
|
|
|
{
|
2022-04-03 20:13:41 -03:00
|
|
|
TRY(Core::System::pledge("stdio recvfd sendfd thread rpath cpath wpath unix"));
|
2020-11-02 18:34:29 -03:00
|
|
|
|
2022-04-16 13:17:39 -03:00
|
|
|
auto app = TRY(GUI::Application::try_create(arguments));
|
2020-08-21 14:36:20 -03:00
|
|
|
|
2022-08-13 16:11:11 -03:00
|
|
|
StringView file_to_edit;
|
2021-09-05 08:23:38 -03:00
|
|
|
|
|
|
|
|
Core::ArgsParser parser;
|
|
|
|
|
parser.add_positional_argument(file_to_edit, "Theme file to edit", "file", Core::ArgsParser::Required::No);
|
2021-11-27 09:34:52 -03:00
|
|
|
parser.parse(arguments);
|
2021-09-05 08:23:38 -03:00
|
|
|
|
|
|
|
|
Optional<String> path = {};
|
|
|
|
|
|
2022-08-13 16:11:11 -03:00
|
|
|
if (!file_to_edit.is_empty())
|
2021-09-05 08:23:38 -03:00
|
|
|
path = Core::File::absolute_path(file_to_edit);
|
|
|
|
|
|
2022-04-03 20:13:41 -03:00
|
|
|
TRY(Core::System::pledge("stdio recvfd sendfd thread rpath unix"));
|
2022-07-24 10:28:42 -03:00
|
|
|
TRY(Core::System::unveil("/tmp/user/%uid/portal/filesystemaccess", "rw"));
|
2021-11-27 09:34:52 -03:00
|
|
|
TRY(Core::System::unveil("/res", "r"));
|
|
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
2020-11-02 18:34:29 -03:00
|
|
|
|
2022-07-11 14:32:29 -03:00
|
|
|
auto app_icon = GUI::Icon::default_icon("app-theme-editor"sv);
|
2020-08-21 14:36:20 -03:00
|
|
|
auto window = GUI::Window::construct();
|
2021-10-27 13:32:09 -03:00
|
|
|
|
2022-05-10 12:10:15 -03:00
|
|
|
auto main_widget = TRY(window->try_set_main_widget<ThemeEditor::MainWidget>());
|
2022-08-13 16:11:11 -03:00
|
|
|
|
|
|
|
|
if (path.has_value()) {
|
|
|
|
|
// Note: This is deferred to ensure that the window has already popped and thus proper window stealing can be performed.
|
|
|
|
|
app->event_loop().deferred_invoke(
|
|
|
|
|
[&window, &path, &main_widget]() {
|
|
|
|
|
auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, path.value());
|
|
|
|
|
if (response.is_error())
|
|
|
|
|
GUI::MessageBox::show_error(window, String::formatted("Opening \"{}\" failed: {}", path.value(), response.error()));
|
|
|
|
|
else
|
|
|
|
|
main_widget->load_from_file(response.release_value());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 10:54:43 -03:00
|
|
|
TRY(main_widget->initialize_menubar(window));
|
|
|
|
|
main_widget->update_title();
|
2021-09-11 15:29:34 -03:00
|
|
|
|
2022-04-29 07:49:22 -03:00
|
|
|
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
|
2022-05-10 10:54:43 -03:00
|
|
|
return main_widget->request_close();
|
2022-04-29 07:49:22 -03:00
|
|
|
};
|
|
|
|
|
|
2022-05-11 08:56:16 -03:00
|
|
|
window->resize(820, 520);
|
2021-07-16 06:21:18 -03:00
|
|
|
window->set_resizable(false);
|
2020-08-21 14:36:20 -03:00
|
|
|
window->show();
|
2020-11-02 16:30:17 -03:00
|
|
|
window->set_icon(app_icon.bitmap_for_size(16));
|
2020-08-21 14:36:20 -03:00
|
|
|
return app->exec();
|
|
|
|
|
}
|