using System; using System.Collections.Generic; using System.Globalization; using System.Reflection; using Flow.Launcher.Plugin.WindowsSettings.Classes; using Flow.Launcher.Plugin.WindowsSettings.Helper; using Flow.Launcher.Plugin.WindowsSettings.Properties; namespace Flow.Launcher.Plugin.WindowsSettings { /// /// Main class of this plugin that implement all used interfaces. /// public sealed class Main : IPlugin, IContextMenu, IPluginI18n, IDisposable { /// /// The name of this assembly. /// private readonly string _assemblyName; /// /// The initial context for this plugin (contains API and meta-data). /// private PluginInitContext? _context; /// /// The path to the icon for windows setting result. /// private const string windowSettingsIconPath = "Images/WindowsSettings.light.png"; /// /// The path to the icon for control panel result. /// private const string controlPanelIconPath = "Images/ControlPanel_Small.png"; /// /// Indicate that the plugin is disposed. /// private bool _disposed; /// /// List that contain all settings. /// private IEnumerable? _settingsList; /// /// List that contains translated string /// private IEnumerable _translatedSettingList = new List(); /// /// Initializes a new instance of the class. /// public Main() { _assemblyName = Assembly.GetExecutingAssembly().GetName().Name ?? Name; } /// /// Gets the localized name. /// public string Name => Resources.PluginTitle; /// /// Gets the localized description. /// public string Description => Resources.PluginDescription; /// /// Initialize the plugin with the given . /// /// The for this plugin. public void Init(PluginInitContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); _settingsList = JsonSettingsListHelper.ReadAllPossibleSettings(); _settingsList = UnsupportedSettingsHelper.FilterByBuild(_settingsList); Log.Init(_context.API); ResultHelper.Init(_context.API); _translatedSettingList = TranslationHelper.TranslateAllSettings(_settingsList); } /// /// Return a filtered list, based on the given query. /// /// The query to filter the list. /// A filtered list, can be empty when nothing was found. public List Query(Query query) { var newList = ResultHelper.GetResultList(_translatedSettingList, query, windowSettingsIconPath, controlPanelIconPath); return newList; } public void OnCultureInfoChanged(CultureInfo newCulture) { _translatedSettingList = TranslationHelper.TranslateAllSettings(_settingsList); } /// /// Return a list context menu entries for a given (shown at the right side of the result). /// /// The for the list with context menu entries. /// A list context menu entries. public List LoadContextMenus(Result selectedResult) { return ContextMenuHelper.GetContextMenu(selectedResult, _assemblyName); } /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// Wrapper method for that dispose additional objects and events form the plugin itself. /// /// Indicate that the plugin is disposed. private void Dispose(bool disposing) { if (_disposed || !disposing) { return; } _disposed = true; } /// /// Gets the localized name. /// public string GetTranslatedPluginTitle() { return Name; } /// /// Gets the localized description. /// public string GetTranslatedPluginDescription() { return Description; } } }