mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Query themes every time
This commit is contained in:
parent
468c0b23c0
commit
bad304b38f
2 changed files with 5 additions and 57 deletions
|
|
@ -7,7 +7,6 @@ using System.Windows;
|
|||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin.SharedCommands;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.Security;
|
||||
|
|
@ -17,7 +16,7 @@ using Control = System.Windows.Controls.Control;
|
|||
|
||||
namespace Flow.Launcher.Plugin.Sys
|
||||
{
|
||||
public class Main : IPlugin, ISettingProvider, IPluginI18n, IDisposable
|
||||
public class Main : IPlugin, ISettingProvider, IPluginI18n
|
||||
{
|
||||
private PluginInitContext context;
|
||||
private ThemeSelector themeSelector;
|
||||
|
|
@ -486,10 +485,5 @@ namespace Flow.Launcher.Plugin.Sys
|
|||
{
|
||||
return context.API.GetTranslation("flowlauncher_plugin_sys_plugin_description");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
themeSelector.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,26 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Sys
|
||||
{
|
||||
public class ThemeSelector : IDisposable
|
||||
public class ThemeSelector
|
||||
{
|
||||
public const string Keyword = "fltheme";
|
||||
|
||||
private readonly Theme _theme;
|
||||
private readonly PluginInitContext _context;
|
||||
|
||||
private IEnumerable<string> themes;
|
||||
|
||||
public ThemeSelector(PluginInitContext context)
|
||||
{
|
||||
_context = context;
|
||||
_theme = Ioc.Default.GetRequiredService<Theme>();
|
||||
context.API.VisibilityChanged += OnVisibilityChanged;
|
||||
}
|
||||
|
||||
~ThemeSelector()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
if (query.IsReQuery)
|
||||
{
|
||||
LoadThemes();
|
||||
}
|
||||
var themes = _theme.LoadAvailableThemes().Select(x => x.FileNameWithoutExtension);
|
||||
|
||||
string search = query.SecondToEndSearch;
|
||||
|
||||
|
|
@ -50,17 +38,6 @@ namespace Flow.Launcher.Plugin.Sys
|
|||
.ToList();
|
||||
}
|
||||
|
||||
private void OnVisibilityChanged(object sender, VisibilityChangedEventArgs args)
|
||||
{
|
||||
if (args.IsVisible && !_context.CurrentPluginMetadata.Disabled)
|
||||
{
|
||||
LoadThemes();
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadThemes()
|
||||
=> themes = _theme.LoadAvailableThemes().Select(x => x.FileNameWithoutExtension);
|
||||
|
||||
private Result CreateThemeResult(string theme) => CreateThemeResult(theme, 0, null);
|
||||
|
||||
private Result CreateThemeResult(string theme, int score, IList<int> highlightData)
|
||||
|
|
@ -69,6 +46,7 @@ namespace Flow.Launcher.Plugin.Sys
|
|||
if (theme == _theme.CurrentTheme)
|
||||
{
|
||||
title = $"{theme} ★";
|
||||
// Set current theme to the top
|
||||
score = 2000;
|
||||
}
|
||||
else
|
||||
|
|
@ -92,29 +70,5 @@ namespace Flow.Launcher.Plugin.Sys
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources
|
||||
if (_context?.API != null)
|
||||
{
|
||||
_context.API.VisibilityChanged -= OnVisibilityChanged;
|
||||
}
|
||||
}
|
||||
// Free unmanaged resources
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue