Theme aware plugin (#4499)

* Migrate theme manager to infrastructure and added it as input to public API instance

* Working event-delegate for PublicAPIInstance

* Theme aware UWP applications

* Theme aware program plugin

* Update query icon on theme change

* Theme aware calculator plugin

* Fix issue with query running before theme change

* Theme based changes in ImageLoader

* Removed ErrorIcon direct references and added references from ImageLoader

* Nit fixes

* Removed unnecessary TODO in UWP.cs

* Added preference to theme based icons

* Added IDisposable interfaces to unsubscribe events
This commit is contained in:
Divyansh Srivastava
2020-06-26 17:42:06 -07:00
committed by GitHub
parent d9597d5ad5
commit d3b10d0d4d
15 changed files with 255 additions and 41 deletions

View File

@@ -13,11 +13,11 @@ using Wox.Plugin;
using Microsoft.Plugin.Program.Views;
using Stopwatch = Wox.Infrastructure.Stopwatch;
using Microsoft.Plugin.Program.Programs;
namespace Microsoft.Plugin.Program
{
public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable
public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable, IDisposable
{
private static readonly object IndexLock = new object();
internal static Programs.Win32[] _win32s { get; set; }
@@ -34,6 +34,7 @@ namespace Microsoft.Plugin.Program
private static BinaryStorage<Programs.Win32[]> _win32Storage;
private static BinaryStorage<Programs.UWP.Application[]> _uwpStorage;
private readonly PluginJsonStorage<Settings> _settingsStorage;
private bool _disposed = false;
public Main()
{
@@ -104,6 +105,21 @@ namespace Microsoft.Plugin.Program
public void Init(PluginInitContext context)
{
_context = context;
_context.API.ThemeChanged += OnThemeChanged;
UpdateUWPIconPath(_context.API.GetCurrentTheme());
}
public void OnThemeChanged(Theme _, Theme currentTheme)
{
UpdateUWPIconPath(currentTheme);
}
public void UpdateUWPIconPath(Theme theme)
{
foreach (UWP.Application app in _uwps)
{
app.UpdatePath(theme);
}
}
public static void IndexWin32Programs()
@@ -186,6 +202,25 @@ namespace Microsoft.Plugin.Program
public void UpdateSettings(PowerLauncherSettings settings)
{
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_context.API.ThemeChanged -= OnThemeChanged;
_disposed = true;
}
}
}
void InitializeFileWatchers()
{
// Create a new FileSystemWatcher and set its properties.