Files
ladybird/Userland/Services/SpiceAgent/main.cpp
Shannon Booth e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00

48 lines
1.5 KiB
C++

/*
* Copyright (c) 2021, Kyle Pereira <kyle@xylepereira.me>
* Copyright (c) 2023, Caoimhe Byrne <caoimhebyrne06@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "SpiceAgent.h"
#include <LibCore/StandardPaths.h>
#include <LibCore/System.h>
#include <LibDesktop/Launcher.h>
#include <LibFileSystem/FileSystem.h>
#include <LibGUI/Application.h>
#include <LibGUI/Clipboard.h>
#include <LibIPC/ConnectionToServer.h>
#include <LibMain/Main.h>
#include <LibURL/URL.h>
#include <fcntl.h>
static constexpr auto SPICE_DEVICE = "/dev/hvc0p1"sv;
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
if (!FileSystem::exists(SPICE_DEVICE)) {
return Error::from_string_literal("Failed to find spice device file!");
}
// We use the application to be able to easily write to the user's clipboard.
auto app = TRY(GUI::Application::create(arguments));
TRY(Desktop::Launcher::add_allowed_url(URL::create_with_file_scheme(Core::StandardPaths::downloads_directory())));
TRY(Desktop::Launcher::seal_allowlist());
TRY(Core::System::pledge("unix rpath wpath cpath stdio sendfd recvfd"));
TRY(Core::System::unveil(SPICE_DEVICE, "rw"sv));
TRY(Core::System::unveil(Core::StandardPaths::downloads_directory(), "rwc"sv));
TRY(Core::System::unveil(nullptr, nullptr));
auto agent = TRY(SpiceAgent::SpiceAgent::create(SPICE_DEVICE));
agent->on_disconnected_from_spice_server = [&]() {
app->quit();
};
TRY(agent->start());
return app->exec();
}