-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--- 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
Showing
17 changed files
with
530 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
public/Nitrocid.Addons/Nitrocid.Extras.Docking/AddonMetadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
public/Nitrocid.Addons/Nitrocid.Extras.Docking/Commands/Dock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
133
public/Nitrocid.Addons/Nitrocid.Extras.Docking/Dock/DockTools.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
164 changes: 164 additions & 0 deletions
164
public/Nitrocid.Addons/Nitrocid.Extras.Docking/Dock/Docks/DigitalClock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.