Skip to content

Commit

Permalink
add - Added shutdown options to the modern login
Browse files Browse the repository at this point in the history
---

We've added shutdown options to the login handler.

---

Type: add
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Feb 15, 2024
1 parent 1d58569 commit 8e11026
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
18 changes: 17 additions & 1 deletion public/Nitrocid/Users/Login/Handlers/Logins/ModernLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions public/Nitrocid/Users/Login/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion public/Nitrocid/Users/Login/ModernLogonScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8e11026

Please sign in to comment.