diff --git a/README.md b/README.md index f2b35511..e813211e 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ If you have no toolchain set up, `run.sh` will build it automatically, which mea For development convenience, the system automatically starts a GUI session as the default user, without prompting for a password. -Despite this, Luna does have a login window built-in. If you'd like to try this feature out or start a GUI session as a different user, you'll need to edit [base/etc/init/99-login](base/etc/init/99-login) and change the line that says `Command=/usr/bin/loginui --autologin=selene` to `Command=/usr/bin/loginui`. +Despite this, Luna does have a login window built-in. If you'd like to try this feature out or start a GUI session as a different user, you'll need to edit [base/etc/loginui.conf](base/etc/loginui.conf) and change the line that says `Autologin=true` to `Autologin=false`. ## Prebuilt images diff --git a/base/etc/init/99-login b/base/etc/init/99-login index 227367be..7889362b 100644 --- a/base/etc/init/99-login +++ b/base/etc/init/99-login @@ -1,6 +1,6 @@ Name=login Description=Start a graphical user session. -Command=/usr/bin/loginui --autologin=selene +Command=/usr/bin/loginui StandardOutput=/dev/uart0 StandardError=/dev/uart0 Restart=true diff --git a/base/etc/loginui.conf b/base/etc/loginui.conf new file mode 100644 index 00000000..d8fc61ae --- /dev/null +++ b/base/etc/loginui.conf @@ -0,0 +1,2 @@ +Autologin=true +AutologinUser=selene diff --git a/gui/loginui.cpp b/gui/loginui.cpp index 81f17dc1..66d69818 100644 --- a/gui/loginui.cpp +++ b/gui/loginui.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -33,16 +34,9 @@ static constexpr ui::Color BACKGROUND_COLOR = ui::Color::from_rgb(89, 89, 89); Result luna_main(int argc, char** argv) { - StringView username; - os::ArgumentParser parser; parser.add_description("Login prompt for a graphical UI session."); parser.add_system_program_info("loginui"_sv); - // FIXME: Make this a config option instead of a switch. - // Also, calling "loginui --autologin=user" is functionally identical to calling "startui --user=user", the only - // difference is that it makes the init config easier to change (only adding or removing the autologin flag, instead - // of changing the program to use) - parser.add_value_argument(username, ' ', "autologin", "login as a specific user without prompting"); parser.parse(argc, argv); if (geteuid() != 0) @@ -66,13 +60,20 @@ Result luna_main(int argc, char** argv) return 1; } - if (!username.is_empty()) - { - auto flag = String::format("--user=%s"_sv, username.chars()).release_value(); + auto config = TRY(os::ConfigFile::open("/etc/loginui.conf")); - StringView startui_command[] = { "/usr/bin/startui", flag.view() }; - os::Process::exec(startui_command[0], Slice(startui_command, 2)); - unreachable(); + if (config->read_boolean_or("Autologin", false)) + { + StringView username = config->read_string_or("AutologinUser", ""); + + if (!username.is_empty()) + { + auto flag = String::format("--user=%s"_sv, username.chars()).release_value(); + + StringView startui_command[] = { "/usr/bin/startui", flag.view() }; + os::Process::exec(startui_command[0], Slice(startui_command, 2)); + unreachable(); + } } ui::App app;