Skip to content

Commit

Permalink
imp - Showing contact images is now optional
Browse files Browse the repository at this point in the history
---

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
  • Loading branch information
AptiviCEO committed Sep 7, 2024
1 parent ff40817 commit ff373c3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -107,6 +109,9 @@ internal class ContactsInit : IAddon

ReadOnlyDictionary<string, FieldInfo>? IAddon.PubliclyAvailableFields => null;

internal static ContactsConfig ContactsConfig =>
(ContactsConfig)Config.baseConfigurations[nameof(ContactsConfig)];

void IAddon.FinalizeAddon()
{
// Add homepage entries
Expand All @@ -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);
}
Expand All @@ -128,6 +135,7 @@ void IAddon.StopAddon()
foreach (var handler in handlers)
ExtensionHandlerTools.extensionHandlers.Remove(handler);
HomepageTools.UnregisterBuiltinAction("Contacts");
ConfigTools.UnregisterBaseSetting(nameof(ContactsConfig));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<DefineDebug>false</DefineDebug>
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<None Remove="Resources\ContactsSettings.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\ContactsSettings.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Nitrocid\Nitrocid.csproj" Private="false" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -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."
}
]
}
]
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
//

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
{
/// <summary>
/// Configuration instance for contacts
/// </summary>
public class ContactsConfig : BaseKernelConfig, IKernelConfig
{
/// <inheritdoc/>
[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.")));

/// <summary>
/// If enabled, shows contact images. Disabled by default to prevent misuse and for performance reasons.
/// </summary>
public bool ShowImages { get; set; }
}
}

0 comments on commit ff373c3

Please sign in to comment.