libui+apps: Change ui::App::init() to take the socket path directly instead of command-line arguments

This commit is contained in:
apio 2024-02-01 21:15:31 +01:00
parent f8a39ffeec
commit ca5b4de2d8
Signed by: apio
GPG Key ID: B8A7D06E42258954
9 changed files with 22 additions and 24 deletions

View File

@ -343,12 +343,12 @@ class GameWidget final : public ui::Widget
}
};
Result<int> luna_main(int argc, char** argv)
Result<int> luna_main(int, char**)
{
srand((unsigned)time(NULL));
ui::App app;
TRY(app.init(argc, argv));
TRY(app.init());
auto* window = TRY(ui::Window::create(ui::Rect { 300, 300, 400, 400 }));
app.set_main_window(window);

View File

@ -7,10 +7,10 @@
static constexpr ui::Color BACKGROUND_COLOR = ui::Color::from_rgb(89, 89, 89);
Result<int> luna_main(int argc, char** argv)
Result<int> luna_main(int, char**)
{
ui::App app;
TRY(app.init(argc, argv));
TRY(app.init());
auto* window = TRY(ui::Window::create(ui::Rect { 300, 300, 400, 300 }));
app.set_main_window(window);

View File

@ -18,10 +18,10 @@ void update_time()
ui::App::the().main_window()->draw();
}
Result<int> luna_main(int argc, char** argv)
Result<int> luna_main(int, char**)
{
ui::App app;
TRY(app.init(argc, argv));
TRY(app.init());
auto* window = TRY(ui::Window::create(ui::Rect { 500, 400, 100, 50 }));
app.set_main_window(window);

View File

@ -108,10 +108,10 @@ static void update()
draw_cells();
}
Result<int> luna_main(int argc, char** argv)
Result<int> luna_main(int, char**)
{
ui::App app;
TRY(app.init(argc, argv));
TRY(app.init());
g_window = TRY(ui::Window::create(ui::Rect { 200, 200, 600, 400 }));
g_window->set_title("Game of Life");

View File

@ -100,13 +100,16 @@ Result<int> luna_main(int argc, char** argv)
auto groups = TRY(read_supplementary_groups(username.chars()));
auto system_groups = TRY(groups.shallow_copy());
TRY(system_groups.try_append(3));
setsid();
// First of all, start the display server.
StringView wind_command[] = { "/usr/bin/wind" };
TRY(os::Process::spawn(wind_command[0], Slice<StringView>(wind_command, 1)));
TRY(wait_until_file_created("/tmp/wind.sock", 10000));
TRY(wait_until_file_created("/tmp/wsys.sock", 10000));
clearenv();
chdir(pw->pw_dir);
@ -117,7 +120,9 @@ Result<int> luna_main(int argc, char** argv)
// Next, start the required UI components.
StringView taskbar_command[] = { "/usr/bin/taskbar" };
TRY(spawn_process_as_user(Slice<StringView>(taskbar_command, 1), pw->pw_uid, pw->pw_gid, groups.slice()));
TRY(spawn_process_as_user(Slice<StringView>(taskbar_command, 1), pw->pw_uid, pw->pw_gid, system_groups.slice()));
TRY(wait_until_file_created("/tmp/wind.sock", 10000));
// Finally, start init in user mode to manage all configured optional services.
StringView init_command[] = { "/usr/bin/init", "--user" };

View File

@ -35,10 +35,10 @@ Result<void> create_widget_group_for_app(ui::HorizontalLayout& layout, Slice<Str
return {};
}
Result<int> luna_main(int argc, char** argv)
Result<int> luna_main(int, char**)
{
ui::App app;
TRY(app.init(argc, argv));
TRY(app.init());
TRY(os::EventLoop::the().register_signal_handler(SIGCHLD, sigchld_handler));

View File

@ -9,6 +9,7 @@
#pragma once
#include <luna/HashMap.h>
#include <luna/StringView.h>
#include <os/EventLoop.h>
#include <os/LocalClient.h>
#include <ui/Window.h>
@ -21,7 +22,7 @@ namespace ui
App();
~App();
Result<void> init(int, char**);
Result<void> init(StringView socket_path = "/tmp/wind.sock");
Result<int> run();
Rect screen_rect();

View File

@ -39,16 +39,8 @@ namespace ui
s_app = nullptr;
}
Result<void> App::init(int argc, char** argv)
Result<void> App::init(StringView socket_path)
{
StringView socket_path = "/tmp/wind.sock";
os::ArgumentParser parser;
parser.add_description("A UI application."_sv);
parser.add_system_program_info(argv[0]);
parser.add_value_argument(socket_path, 's', "socket"_sv, "the path for the local IPC socket"_sv);
parser.parse(argc, argv);
m_client = TRY(os::LocalClient::connect(socket_path, true));
fcntl(m_client->fd(), F_SETFL, O_NONBLOCK);

View File

@ -3,10 +3,10 @@
#include <ui/App.h>
#include <unistd.h>
Result<int> luna_main(int argc, char** argv)
Result<int> luna_main(int, char**)
{
ui::App app;
TRY(app.init(argc, argv));
TRY(app.init());
auto* window = TRY(ui::Window::create(ui::Rect { 150, 150, 640, 400 }));
app.set_main_window(window);