Skip to content

Commit

Permalink
✨ Add exit command + network button context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinbreiz committed Mar 4, 2024
1 parent 9d11866 commit 5ae8a09
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 19 deletions.
2 changes: 1 addition & 1 deletion SRC/Aura_OS/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace Aura_OS
{
public class VersionInfo
{
public static string revision = "040320241613";
public static string revision = "040320241809";
}
}
18 changes: 18 additions & 0 deletions SRC/Aura_OS/System/Graphics/UI/GUI/Taskbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Aura_OS.System.Graphics.UI.GUI.Components;
using Aura_OS.System.Processing.Processes;
using System;
using Aura_OS.System.Network;

namespace Aura_OS.System.Graphics.UI.GUI
{
Expand Down Expand Up @@ -72,6 +73,23 @@ public Taskbar() : base(Kernel.Gray, 0, (int)Kernel.ScreenHeight - taskbarHeight
int networkButtonY = (taskbarHeight / 2) - (networkButtonHeight / 2);
NetworkButton = new Button(Kernel.ResourceManager.GetIcon("16-network-offline.bmp"), netoworkButtonX, networkButtonY, networkButtonWidth, networkButtonHeight);
NetworkButton.NoBackground = true;
NetworkButton.RightClick = new RightClick((int)MouseManager.X, (int)MouseManager.Y - (1 * RightClickEntry.ConstHeight), 200, 2 * RightClickEntry.ConstHeight);

RightClickEntry entry = new("ipconfig /ask", NetworkButton.RightClick.Width, NetworkButton.RightClick);
entry.Click = new Action(() =>
{
Dhcp.Ask();
});

RightClickEntry entry2 = new("ipconfig /release", NetworkButton.RightClick.Width, NetworkButton.RightClick);
entry2.Click = new Action(() =>
{
Dhcp.Release();
});

NetworkButton.RightClick.AddEntry(entry);
NetworkButton.RightClick.AddEntry(entry2);

AddChild(NetworkButton);

Buttons = new Dictionary<uint, Button>();
Expand Down
53 changes: 53 additions & 0 deletions SRC/Aura_OS/System/Network/Dhcp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* PROJECT: Aura Operating System Development
* CONTENT: Dhcp utils class
* PROGRAMMER(S): Valentin Charbonnier <[email protected]>
*/

using Cosmos.System.Network.Config;
using Cosmos.System.Network.IPv4.UDP.DNS;
using Cosmos.System.Network.IPv4;
using CosmosHttp.Client;
using System.Net;
using System.Text;
using Aura_OS.System.Processing.Processes;
using Cosmos.System.Network.IPv4.UDP.DHCP;
using Aura_OS.System.Processing.Interpreter.Commands;
using System;

namespace Aura_OS.System.Network
{
public static class Dhcp
{
public static void Release()
{
var xClient = new DHCPClient();
xClient.SendReleasePacket();
xClient.Close();

NetworkConfiguration.ClearConfigs();

Kernel.NetworkConnected = false;
Explorer.Taskbar.MarkDirty();
}

public static bool Ask()
{
var xClient = new DHCPClient();
if (xClient.SendDiscoverPacket() != -1)
{
xClient.Close();
Console.WriteLine("Configuration applied! Your local IPv4 Address is " + NetworkConfiguration.CurrentAddress + ".");
Kernel.NetworkConnected = true;
return true;
}
else
{
NetworkConfiguration.ClearConfigs();

xClient.Close();
return false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void RegisterAllCommands()
_commands.Add(new CommandShutdown(new string[] { "shutdown", "sd" }));

_commands.Add(new CommandClear(new string[] { "clear", "clr" }, _terminal));
_commands.Add(new CommandExit(new string[] { "exit" }, _terminal));
_commands.Add(new CommandKeyboardMap(new string[] { "setkeyboardmap", "setkeyboard" }));
_commands.Add(new CommandEnv(new string[] { "export", "set" }));
_commands.Add(new CommandEcho(new string[] { "echo" }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/


using Aura_OS.System.Network;
using Aura_OS.System.Processing.Processes;
using Cosmos.HAL;
using Cosmos.System.Network;
Expand Down Expand Up @@ -77,30 +78,17 @@ public override ReturnInfo Execute(List<string> arguments)
{
if (arguments[0] == "/release")
{
var xClient = new DHCPClient();
xClient.SendReleasePacket();
xClient.Close();

NetworkConfiguration.ClearConfigs();

Kernel.NetworkConnected = false;
Explorer.Taskbar.MarkDirty();
Dhcp.Release();
}
else if (arguments[0] == "/ask")
{
var xClient = new DHCPClient();
if (xClient.SendDiscoverPacket() != -1)
if (Dhcp.Ask())
{
xClient.Close();
Console.WriteLine("Configuration applied! Your local IPv4 Address is " + NetworkConfiguration.CurrentAddress + ".");
Kernel.NetworkConnected = true;
return new ReturnInfo(this, ReturnCode.OK);
}
else
{
NetworkConfiguration.ClearConfigs();

xClient.Close();
return new ReturnInfo(this, ReturnCode.ERROR, "DHCP Discover failed. Can't apply dynamic IPv4 address.");
new ReturnInfo(this, ReturnCode.ERROR, "DHCP Discover failed. Can't apply dynamic IPv4 address.");
}
}
else if (arguments[0] == "/listnic")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* PROJECT: Aura Operating System Development
* CONTENT: Command Interpreter - Clear
* PROGRAMMER(S): John Welsh <[email protected]>
* PROGRAMMER(S): John Welsh <[email protected]>
*/

using Aura_OS.System.Graphics.UI.GUI;
Expand All @@ -12,6 +12,7 @@ namespace Aura_OS.System.Processing.Interpreter.Commands.c_Console
class CommandClear : ICommand
{
private TerminalApp _terminal;

/// <summary>
/// Empty constructor.
/// </summary>
Expand All @@ -30,6 +31,10 @@ public override ReturnInfo Execute()
{
_terminal.Console.ClearText();
}
else
{
Cosmos.System.Power.Shutdown();
}

return new ReturnInfo(this, ReturnCode.OK);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* PROJECT: Aura Operating System Development
* CONTENT: Command Interpreter - Exit
* PROGRAMMER(S): John Welsh <[email protected]>
* Valentin Charbonnier <[email protected]>
*/

using Aura_OS.System.Graphics.UI.GUI;
using Aura_OS.System.Processing.Applications.Terminal;

namespace Aura_OS.System.Processing.Interpreter.Commands.c_Console
{
class CommandExit : ICommand
{
private TerminalApp _terminal;

/// <summary>
/// Empty constructor.
/// </summary>
public CommandExit(string[] commandvalues, Application terminal) : base(commandvalues)
{
Description = "to exit the console";
_terminal = terminal as TerminalApp;
}

/// <summary>
/// CommandClear
/// </summary>
public override ReturnInfo Execute()
{
if (_terminal != null)
{
_terminal.Window.Close.Click();
}

return new ReturnInfo(this, ReturnCode.OK);
}
}
}

0 comments on commit 5ae8a09

Please sign in to comment.