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

Applets/Network: 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:25:12 +01:00
parent 6536198693
commit b03f8d18c5
2 changed files with 13 additions and 34 deletions

View file

@ -9,4 +9,4 @@ set(SOURCES
) )
serenity_app(Network.Applet ICON network) serenity_app(Network.Applet ICON network)
target_link_libraries(Network.Applet LibGUI LibCore LibGfx) target_link_libraries(Network.Applet LibGUI LibCore LibGfx LibMain)

View file

@ -6,6 +6,7 @@
#include <LibCore/ArgsParser.h> #include <LibCore/ArgsParser.h>
#include <LibCore/File.h> #include <LibCore/File.h>
#include <LibCore/System.h>
#include <LibGUI/Action.h> #include <LibGUI/Action.h>
#include <LibGUI/Application.h> #include <LibGUI/Application.h>
#include <LibGUI/ImageWidget.h> #include <LibGUI/ImageWidget.h>
@ -13,6 +14,7 @@
#include <LibGUI/Notification.h> #include <LibGUI/Notification.h>
#include <LibGUI/Window.h> #include <LibGUI/Window.h>
#include <LibGfx/Bitmap.h> #include <LibGfx/Bitmap.h>
#include <LibMain/Main.h>
#include <serenity.h> #include <serenity.h>
#include <spawn.h> #include <spawn.h>
#include <stdio.h> #include <stdio.h>
@ -155,51 +157,28 @@ private:
RefPtr<Gfx::Bitmap> m_disconnected_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network-disconnected.png").release_value_but_fixme_should_propagate_errors(); RefPtr<Gfx::Bitmap> m_disconnected_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network-disconnected.png").release_value_but_fixme_should_propagate_errors();
}; };
int main(int argc, char* argv[]) ErrorOr<int> serenity_main(Main::Arguments arguments)
{ {
if (pledge("stdio recvfd sendfd rpath unix proc exec", nullptr) < 0) { TRY(Core::System::pledge("stdio recvfd sendfd rpath unix proc exec", nullptr));
perror("pledge"); auto app = TRY(GUI::Application::try_create(arguments));
return 1;
}
auto app = GUI::Application::construct(argc, argv); TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil("/tmp/portal/notify", "rw"));
if (unveil("/res", "r") < 0) { TRY(Core::System::unveil("/proc/net/adapters", "r"));
perror("unveil"); TRY(Core::System::unveil("/bin/SystemMonitor", "x"));
return 1; TRY(Core::System::unveil(nullptr, nullptr));
}
if (unveil("/tmp/portal/notify", "rw") < 0) {
perror("unveil");
return 1;
}
if (unveil("/proc/net/adapters", "r") < 0) {
perror("unveil");
return 1;
}
if (unveil("/bin/SystemMonitor", "x") < 0) {
perror("unveil");
return 1;
}
if (unveil(nullptr, nullptr) < 0) {
perror("unveil");
return 1;
}
bool display_notifications = false; bool display_notifications = false;
const char* name = nullptr; const char* name = nullptr;
Core::ArgsParser args_parser; Core::ArgsParser args_parser;
args_parser.add_option(display_notifications, "Display notifications", "display-notifications", 'd'); args_parser.add_option(display_notifications, "Display notifications", "display-notifications", 'd');
args_parser.add_option(name, "Applet name used by WindowServer.ini to set the applet order", "name", 'n', "name"); args_parser.add_option(name, "Applet name used by WindowServer.ini to set the applet order", "name", 'n', "name");
args_parser.parse(argc, argv); args_parser.parse(arguments);
if (name == nullptr) if (name == nullptr)
name = "Network"; name = "Network";
auto window = GUI::Window::construct(); auto window = TRY(GUI::Window::try_create());
window->set_title(name); window->set_title(name);
window->set_window_type(GUI::WindowType::Applet); window->set_window_type(GUI::WindowType::Applet);
window->set_has_alpha_channel(true); window->set_has_alpha_channel(true);