Skip to content

Commit

Permalink
add - doc - Added docking addon
Browse files Browse the repository at this point in the history
---

We've added screen docking addon that allows you to dock your screen.

---

Type: add
Breaking: False
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Nov 28, 2023
1 parent 5b43e09 commit d900762
Show file tree
Hide file tree
Showing 17 changed files with 530 additions and 4 deletions.
11 changes: 9 additions & 2 deletions Nitrocid.sln
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Extras.ChatGpt", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Legacy.InxiNet", "public\Nitrocid.Addons\Nitrocid.Legacy.InxiNet\Nitrocid.Legacy.InxiNet.csproj", "{AA1B126D-557F-4A23-8F09-875078BE700D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nitrocid.Extras.SqlShell", "public\Nitrocid.Addons\Nitrocid.Extras.SqlShell\Nitrocid.Extras.SqlShell.csproj", "{0206B299-10B2-4FD4-B21A-14395AEE2E64}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Extras.SqlShell", "public\Nitrocid.Addons\Nitrocid.Extras.SqlShell\Nitrocid.Extras.SqlShell.csproj", "{0206B299-10B2-4FD4-B21A-14395AEE2E64}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nitrocid.Extras.JsonShell", "public\Nitrocid.Addons\Nitrocid.Extras.JsonShell\Nitrocid.Extras.JsonShell.csproj", "{71F19E75-8C3A-4224-94AD-6419E77F8670}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Extras.JsonShell", "public\Nitrocid.Addons\Nitrocid.Extras.JsonShell\Nitrocid.Extras.JsonShell.csproj", "{71F19E75-8C3A-4224-94AD-6419E77F8670}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nitrocid.Extras.Docking", "public\Nitrocid.Addons\Nitrocid.Extras.Docking\Nitrocid.Extras.Docking.csproj", "{C83EB703-1DE7-48C9-9406-1CFA5140235F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -336,6 +338,10 @@ Global
{71F19E75-8C3A-4224-94AD-6419E77F8670}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71F19E75-8C3A-4224-94AD-6419E77F8670}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71F19E75-8C3A-4224-94AD-6419E77F8670}.Release|Any CPU.Build.0 = Release|Any CPU
{C83EB703-1DE7-48C9-9406-1CFA5140235F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C83EB703-1DE7-48C9-9406-1CFA5140235F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C83EB703-1DE7-48C9-9406-1CFA5140235F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C83EB703-1DE7-48C9-9406-1CFA5140235F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -394,6 +400,7 @@ Global
{AA1B126D-557F-4A23-8F09-875078BE700D} = {B60F276A-FE12-4001-916E-080344ED1FD9}
{0206B299-10B2-4FD4-B21A-14395AEE2E64} = {B60F276A-FE12-4001-916E-080344ED1FD9}
{71F19E75-8C3A-4224-94AD-6419E77F8670} = {B60F276A-FE12-4001-916E-080344ED1FD9}
{C83EB703-1DE7-48C9-9406-1CFA5140235F} = {B60F276A-FE12-4001-916E-080344ED1FD9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {424D8E7A-CFEB-40AE-A79C-437D603177FD}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"DllPath": "Nitrocid.Extras.Docking.dll"
}
46 changes: 46 additions & 0 deletions public/Nitrocid.Addons/Nitrocid.Extras.Docking/Commands/Dock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Nitrocid KS Copyright (C) 2018-2023 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using KS.ConsoleBase.Colors;
using KS.ConsoleBase.Writers.ConsoleWriters;
using KS.Languages;
using KS.Shell.ShellBase.Commands;
using Nitrocid.Extras.Docking.Dock;

namespace Nitrocid.Extras.Docking.Commands
{
class DockCommand : BaseCommand, ICommand
{

public override int Execute(CommandParameters parameters, ref string variableValue)
{
// Check the dock screen for existence
if (!DockTools.DoesDockScreenExist(parameters.ArgumentsList[0], out IDock dock))
{
TextWriterColor.WriteKernelColor(Translate.DoTranslation("There is no dock screen by this name."), KernelColorType.Error);
return 34;
}

// Now, dock the screen
DockTools.DockScreen(dock);
return 0;
}

}
}
133 changes: 133 additions & 0 deletions public/Nitrocid.Addons/Nitrocid.Extras.Docking/Dock/DockTools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// Nitrocid KS Copyright (C) 2018-2023 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using KS.ConsoleBase.Colors;
using KS.ConsoleBase.Inputs.Styles.Infobox;
using KS.Kernel.Debugging;
using KS.Kernel.Exceptions;
using KS.Languages;
using KS.Misc.Screensaver;
using Nitrocid.Extras.Docking.Dock.Docks;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Nitrocid.Extras.Docking.Dock
{
/// <summary>
/// Screen dock tools
/// </summary>
public static class DockTools
{
private static readonly Dictionary<string, IDock> docks = new()
{
{ nameof(DigitalClock), new DigitalClock() }
};

/// <summary>
/// Docks the screen using the given screen dock name
/// </summary>
/// <param name="dockName">Screen dock class name</param>
/// <exception cref="KernelException"></exception>
public static void DockScreen(string dockName)
{
// Check to see if there is a dock by this name
if (!DoesDockScreenExist(dockName, out IDock dock))
throw new KernelException(KernelExceptionType.Docking, Translate.DoTranslation("There is no screen dock by this name."));

// Now, dock the screen
DebugWriter.WriteDebug(DebugLevel.I, $"Docking screen with name: {dockName}");
DockScreen(dock);
}

/// <summary>
/// Docks the screen using the given screen dock
/// </summary>
/// <param name="dockInstance">Screen dock instance</param>
/// <exception cref="KernelException"></exception>
public static void DockScreen(IDock dockInstance)
{
// Check to see if there is a dock
if (dockInstance is null)
throw new KernelException(KernelExceptionType.Docking, Translate.DoTranslation("There is no screen dock."));

// Now, dock the screen
try
{
DebugWriter.WriteDebug(DebugLevel.I, $"Docking screen with name: [{dockInstance.DockName}]");

// We need to prevent locking to avoid interference, because, most of the time, when you're docking your
// screen, you're essentially idling because you've successfully converted your device to the information
// center that displays continuously, and we don't want screensavers to interfere with the operation.
ScreensaverManager.PreventLock();
dockInstance.ScreenDock();
}
catch (Exception ex)
{
KernelColorTools.LoadBack();
DebugWriter.WriteDebug(DebugLevel.E, $"Screen dock crashed [{dockInstance.DockName}]: {ex.Message}");
DebugWriter.WriteDebugStackTrace(ex);
InfoBoxColor.WriteInfoBoxKernelColor(Translate.DoTranslation("Screen dock has crashed") + $": {ex.Message}", KernelColorType.Error);
}
finally
{
KernelColorTools.LoadBack();
ScreensaverManager.AllowLock();
}
}

/// <summary>
/// Checks to see if the dock screen by a specified dock class name exists
/// </summary>
/// <param name="dockName">Screen dock class name</param>
/// <param name="dockInstance">Screen dock instance output</param>
/// <returns>True if found; false otherwise.</returns>
public static bool DoesDockScreenExist(string dockName, out IDock dockInstance)
{
bool result = docks.TryGetValue(dockName, out IDock dock);
DebugWriter.WriteDebug(DebugLevel.I, $"Result: {dockName}, {result}");
if (result)
DebugWriter.WriteDebug(DebugLevel.I, $"Got dock: {dock.DockName}");
dockInstance = dock;
return result;
}

/// <summary>
/// Gets the dock screen names
/// </summary>
/// <returns>An array containing dock screen class names that you can use with all the <see cref="DockTools"/> functions.</returns>
public static string[] GetDockScreenNames()
{
string[] names = [.. docks.Keys];
DebugWriter.WriteDebug(DebugLevel.I, $"Got {names.Length} docks: [{string.Join(", ", names)}]");
return names;
}

/// <summary>
/// Gets the dock screens
/// </summary>
/// <returns>A read-only dictionary containing dock screen names and their <see cref="IDock"/> instances</returns>
public static ReadOnlyDictionary<string, IDock> GetDockScreens()
{
var dockScreens = new ReadOnlyDictionary<string, IDock>(docks);
DebugWriter.WriteDebug(DebugLevel.I, $"Got {dockScreens.Count} docks");
return dockScreens;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
//
// Nitrocid KS Copyright (C) 2018-2023 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using Figletize;
using KS.ConsoleBase;
using KS.ConsoleBase.Buffered;
using KS.ConsoleBase.Colors;
using KS.ConsoleBase.Inputs;
using KS.ConsoleBase.Writers.FancyWriters;
using KS.Kernel.Debugging;
using KS.Kernel.Exceptions;
using KS.Kernel.Extensions;
using KS.Kernel.Threading;
using KS.Kernel.Time;
using KS.Kernel.Time.Renderers;
using KS.Languages;
using KS.Misc.Text;
using KS.Misc.Text.Probers.Motd;
using KS.Network.RSS;
using KS.Users.Login;
using System;
using System.Text;
using Terminaux.Sequences.Builder.Types;

namespace Nitrocid.Extras.Docking.Dock.Docks
{
internal class DigitalClock : IDock
{
/// <inheritdoc/>
public string DockName =>
Translate.DoTranslation("Digital Clock");

/// <inheritdoc/>
public void ScreenDock()
{
// Make a screen
var screen = new Screen();
ScreenTools.SetCurrent(screen);

// Now, do the job
string cachedTimeStr = "";

// First, get the headline
static string UpdateHeadline()
{
try
{
if (!RSSTools.ShowHeadlineOnLogin)
return "";
var Feed = InterAddonTools.ExecuteCustomAddonFunction(KnownAddons.ExtrasRssShell, "GetFirstArticle", RSSTools.RssHeadlineUrl);
if (Feed is (string feedTitle, string articleTitle))
return Translate.DoTranslation("From") + $" {feedTitle}: {articleTitle}";
return Translate.DoTranslation("No feed.");
}
catch (KernelException ex) when (ex.ExceptionType == KernelExceptionType.AddonManagement)
{
DebugWriter.WriteDebug(DebugLevel.E, "Failed to get latest news: {0}", ex.Message);
DebugWriter.WriteDebugStackTrace(ex);
return Translate.DoTranslation("Install the RSS Shell Extras addon!");
}
catch (Exception ex)
{
DebugWriter.WriteDebug(DebugLevel.E, "Failed to get latest news: {0}", ex.Message);
DebugWriter.WriteDebugStackTrace(ex);
return Translate.DoTranslation("Failed to get the latest news.");
}
}

string headlineStr = UpdateHeadline();
while (!ConsoleWrapper.KeyAvailable)
{
// Print the time
string timeStr = TimeDateRenderers.RenderTime(FormatType.Short);
if (timeStr != cachedTimeStr)
{
screen.RemoveBufferedParts();
var part = new ScreenPart();
part.AddDynamicText(() =>
{
var display = new StringBuilder();

// Clear the console and write the time using figlet
display.Append(CsiSequences.GenerateCsiEraseInDisplay(2));
cachedTimeStr = TimeDateRenderers.RenderTime(FormatType.Short);
var figFont = FigletTools.GetFigletFont(TextTools.DefaultFigletFontName);
int figHeight = FigletTools.GetFigletHeight(timeStr, figFont) / 2;
display.Append(
KernelColorTools.GetColor(KernelColorType.Stage).VTSequenceForeground +
CenteredFigletTextColor.RenderCenteredFiglet(figFont, timeStr)
);

// Print the date
string dateStr = $"{TimeDateRenderers.RenderDate()}";
int consoleInfoY = (ConsoleWrapper.WindowHeight / 2) + figHeight + 2;
display.Append(
CenteredTextColor.RenderCenteredOneLine(consoleInfoY, dateStr) +
KernelColorTools.GetColor(KernelColorType.NeutralText).VTSequenceForeground
);

// Print the headline
if (RSSTools.ShowHeadlineOnLogin)
{
int consoleHeadlineInfoY =
ModernLogonScreen.MotdHeadlineBottom ?
(ConsoleWrapper.WindowHeight / 2) + figHeight + 3 :
(ConsoleWrapper.WindowHeight / 2) - figHeight - 2;
display.Append(
CenteredTextColor.RenderCenteredOneLine(consoleHeadlineInfoY, headlineStr)
);
}

// Print the MOTD
string[] motdStrs = TextTools.GetWrappedSentences(MotdParse.MotdMessage, ConsoleWrapper.WindowWidth - 4);
for (int i = 0; i < motdStrs.Length && i < 2; i++)
{
string motdStr = motdStrs[i];
int consoleMotdInfoY =
ModernLogonScreen.MotdHeadlineBottom ?
(ConsoleWrapper.WindowHeight / 2) + figHeight + 4 + i :
(ConsoleWrapper.WindowHeight / 2) - figHeight - (RSSTools.ShowHeadlineOnLogin ? 4 : 2) + i;
display.Append(
CenteredTextColor.RenderCenteredOneLine(consoleMotdInfoY, motdStr)
);
}

// Print the instructions
string instStr = Translate.DoTranslation("Press any key to go back to the kernel...");
int consoleInstY = ConsoleWrapper.WindowHeight - 2;
display.Append(
CenteredTextColor.RenderCenteredOneLine(consoleInstY, instStr)
);

// Print everything
return display.ToString();
});
screen.AddBufferedPart(part);

// Render it now
ScreenTools.Render();
}
ThreadManager.SleepNoBlock(1);
}
if (ConsoleWrapper.KeyAvailable)
Input.DetectKeypress();
ScreenTools.UnsetCurrent(screen);
}
}
}
Loading

0 comments on commit d900762

Please sign in to comment.