From ff373c3b954a3d31e7dcfb4fe7aba0934b1bdf76 Mon Sep 17 00:00:00 2001 From: Aptivi CEO Date: Sat, 7 Sep 2024 23:29:12 +0300 Subject: [PATCH] imp - Showing contact images is now optional --- We've added a configuration option to the contacts addon that controls how to display profile picture. This is done in order to improve performance and to prevent misuse. --- Type: imp Breaking: False Doc Required: False Backport Required: False Part: 1/1 --- .../Interactives/ContactsManagerCli.cs | 13 ++++-- .../Nitrocid.Extras.Contacts/ContactsInit.cs | 8 ++++ .../Nitrocid.Extras.Contacts.csproj | 6 +++ .../Resources/ContactsSettings.json | 14 ++++++ .../Settings/ContactsConfig.cs | 46 +++++++++++++++++++ 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Resources/ContactsSettings.json create mode 100644 public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Settings/ContactsConfig.cs diff --git a/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Contacts/Interactives/ContactsManagerCli.cs b/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Contacts/Interactives/ContactsManagerCli.cs index 12a835f55..6e31fd6bd 100644 --- a/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Contacts/Interactives/ContactsManagerCli.cs +++ b/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Contacts/Interactives/ContactsManagerCli.cs @@ -59,7 +59,10 @@ public override string GetInfoFromItem(Card item) return Translate.DoTranslation("There is no contact. If you'd like to import contacts, please use the import options using the keystrokes defined at the bottom of the screen."); // Generate the rendered text - string finalRenderedContactPicture = GetContactPictureFinal(selectedContact, (ConsoleWrapper.WindowWidth / 2) - 4, ConsoleWrapper.WindowHeight / 2, KernelColorTools.GetColor(KernelColorType.TuiBackground)); + string finalRenderedContactPicture = + ContactsInit.ContactsConfig.ShowImages ? + GetContactPictureFinal(selectedContact, (ConsoleWrapper.WindowWidth / 2) - 4, ConsoleWrapper.WindowHeight / 2, KernelColorTools.GetColor(KernelColorType.TuiBackground)) : + ""; string finalRenderedContactName = GetContactNameFinal(selectedContact); string finalRenderedContactAddress = GetContactAddressFinal(selectedContact); string finalRenderedContactMail = GetContactMailFinal(selectedContact); @@ -191,12 +194,16 @@ internal void ShowContactInfo(int index) string finalRenderedContactNotes = GetContactNotesFinal(index); finalInfoRendered.AppendLine(finalRenderedContactNotes); - // If there is a profile picture, print it - string picture = GetContactPictureFinal(index, ConsoleWrapper.WindowWidth - 8, ConsoleWrapper.WindowHeight, KernelColorTools.GetColor(KernelColorType.TuiBoxBackground)); + // If there is a profile picture and preview is enabled, print it + string picture = + ContactsInit.ContactsConfig.ShowImages ? + GetContactPictureFinal(index, ConsoleWrapper.WindowWidth - 8, ConsoleWrapper.WindowHeight, KernelColorTools.GetColor(KernelColorType.TuiBoxBackground)) : + ""; if (!string.IsNullOrEmpty(picture)) { finalInfoRendered.AppendLine("\n"); finalInfoRendered.AppendLine(picture); + finalInfoRendered.Append(ColorTools.RenderSetConsoleColor(KernelColorTools.GetColor(KernelColorType.TuiBoxBackground), true)); } // Add a prompt to close diff --git a/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/ContactsInit.cs b/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/ContactsInit.cs index e77e76b81..3e792b266 100644 --- a/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/ContactsInit.cs +++ b/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/ContactsInit.cs @@ -34,6 +34,8 @@ using Nitrocid.Shell.ShellBase.Switches; using VisualCard.Parts; using Nitrocid.Shell.Homepage; +using Nitrocid.Extras.Contacts.Settings; +using Nitrocid.Kernel.Configuration; namespace Nitrocid.Extras.Contacts { @@ -107,6 +109,9 @@ internal class ContactsInit : IAddon ReadOnlyDictionary? IAddon.PubliclyAvailableFields => null; + internal static ContactsConfig ContactsConfig => + (ContactsConfig)Config.baseConfigurations[nameof(ContactsConfig)]; + void IAddon.FinalizeAddon() { // Add homepage entries @@ -115,6 +120,8 @@ void IAddon.FinalizeAddon() void IAddon.StartAddon() { + var config = new ContactsConfig(); + ConfigTools.RegisterBaseSetting(config); CommandManager.RegisterAddonCommands(ShellType.Shell, [.. addonCommands]); ExtensionHandlerTools.extensionHandlers.AddRange(handlers); } @@ -128,6 +135,7 @@ void IAddon.StopAddon() foreach (var handler in handlers) ExtensionHandlerTools.extensionHandlers.Remove(handler); HomepageTools.UnregisterBuiltinAction("Contacts"); + ConfigTools.UnregisterBaseSetting(nameof(ContactsConfig)); } } } diff --git a/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Nitrocid.Extras.Contacts.csproj b/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Nitrocid.Extras.Contacts.csproj index 8a5cba22c..9c44ab745 100644 --- a/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Nitrocid.Extras.Contacts.csproj +++ b/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Nitrocid.Extras.Contacts.csproj @@ -26,6 +26,12 @@ false true + + + + + + diff --git a/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Resources/ContactsSettings.json b/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Resources/ContactsSettings.json new file mode 100644 index 000000000..0810ad848 --- /dev/null +++ b/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Resources/ContactsSettings.json @@ -0,0 +1,14 @@ +[ + { + "Name": "Contacts", + "Desc": "This section lets you configure how the contacts addon works.", + "Keys": [ + { + "Name": "Show profile pictures", + "Type": "SBoolean", + "Variable": "ShowImages", + "Description": "If enabled, shows contact images. Disabled by default to prevent misuse and for performance reasons." + } + ] + } +] diff --git a/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Settings/ContactsConfig.cs b/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Settings/ContactsConfig.cs new file mode 100644 index 000000000..6c238ad74 --- /dev/null +++ b/public/Nitrocid.Addons/Nitrocid.Extras.Contacts/Settings/ContactsConfig.cs @@ -0,0 +1,46 @@ +// +// Nitrocid KS Copyright (C) 2018-2024 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 . +// + +using Newtonsoft.Json; +using Nitrocid.Kernel.Configuration; +using Nitrocid.Kernel.Configuration.Instances; +using Nitrocid.Kernel.Configuration.Settings; +using Nitrocid.Kernel.Exceptions; +using Nitrocid.Languages; +using Nitrocid.Misc.Reflection.Internal; + +namespace Nitrocid.Extras.Contacts.Settings +{ + /// + /// Configuration instance for contacts + /// + public class ContactsConfig : BaseKernelConfig, IKernelConfig + { + /// + [JsonIgnore] + public override SettingsEntry[] SettingsEntries => + ConfigTools.GetSettingsEntries(ResourcesManager.GetData("ContactsSettings.json", ResourcesType.Misc, typeof(ContactsConfig).Assembly) ?? + throw new KernelException(KernelExceptionType.Config, Translate.DoTranslation("Failed to obtain settings entries."))); + + /// + /// If enabled, shows contact images. Disabled by default to prevent misuse and for performance reasons. + /// + public bool ShowImages { get; set; } + } +}