From 8e11026b15ab87f708745758db1b0d80360d31a3 Mon Sep 17 00:00:00 2001 From: Aptivi CEO Date: Thu, 15 Feb 2024 14:00:56 +0300 Subject: [PATCH] add - Added shutdown options to the modern login --- We've added shutdown options to the login handler. --- Type: add Breaking: False Doc Required: False Part: 1/1 --- .../Users/Login/Handlers/Logins/ModernLogin.cs | 18 +++++++++++++++++- public/Nitrocid/Users/Login/Login.cs | 4 ++++ .../Nitrocid/Users/Login/ModernLogonScreen.cs | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/public/Nitrocid/Users/Login/Handlers/Logins/ModernLogin.cs b/public/Nitrocid/Users/Login/Handlers/Logins/ModernLogin.cs index f58f33f31b..938cf38d27 100644 --- a/public/Nitrocid/Users/Login/Handlers/Logins/ModernLogin.cs +++ b/public/Nitrocid/Users/Login/Handlers/Logins/ModernLogin.cs @@ -29,6 +29,8 @@ using Terminaux.Colors; using Terminaux.Base; using Terminaux.Inputs; +using System; +using Nitrocid.Kernel.Power; namespace Nitrocid.Users.Login.Handlers.Logins { @@ -48,11 +50,25 @@ public override void LoginScreen() DebugWriter.WriteDebug(DebugLevel.I, "Rendering..."); SpinWait.SpinUntil(() => ModernLogonScreen.renderedFully); DebugWriter.WriteDebug(DebugLevel.I, "Rendered fully!"); - Input.DetectKeypress(); + var key = Input.DetectKeypress().Key; // Stop the thread ModernLogonScreen.DateTimeUpdateThread.Stop(); ModernLogonScreen.renderedFully = false; + + // Check to see if user requested power actions + if (key == ConsoleKey.Escape) + { + int answer = InfoBoxButtonsColor.WriteInfoBoxButtons([ + new InputChoiceInfo("shutdown", Translate.DoTranslation("Shut down")), + new InputChoiceInfo("reboot", Translate.DoTranslation("Restart")), + new InputChoiceInfo("login", Translate.DoTranslation("Login")), + ], Translate.DoTranslation("What do you want to do?")); + if (answer == 0) + PowerManager.PowerManage(PowerMode.Shutdown); + else if (answer == 1) + PowerManager.PowerManage(PowerMode.Reboot); + } } public override string UserSelector() diff --git a/public/Nitrocid/Users/Login/Login.cs b/public/Nitrocid/Users/Login/Login.cs index 590eb35352..6d6dcc9bde 100644 --- a/public/Nitrocid/Users/Login/Login.cs +++ b/public/Nitrocid/Users/Login/Login.cs @@ -95,6 +95,10 @@ public static void LoginPrompt() // Now, show the Login screen handler.LoginScreen(); + // The login screen may provide an option to perform power options. + if (PowerManager.RebootRequested || PowerManager.KernelShutdown) + continue; + // Prompt for username user = handler.UserSelector(); diff --git a/public/Nitrocid/Users/Login/ModernLogonScreen.cs b/public/Nitrocid/Users/Login/ModernLogonScreen.cs index 4720c8538a..6cde0506b9 100644 --- a/public/Nitrocid/Users/Login/ModernLogonScreen.cs +++ b/public/Nitrocid/Users/Login/ModernLogonScreen.cs @@ -149,7 +149,7 @@ static string UpdateHeadline() } // Print the instructions - string instStr = Translate.DoTranslation("Press any key to start..."); + string instStr = Translate.DoTranslation("Press any key to start, or ESC for more options..."); int consoleInstY = ConsoleWrapper.WindowHeight - 2; display.Append( CenteredTextColor.RenderCenteredOneLine(consoleInstY, instStr)