mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Remove instance logic for BinaryStorage and JsonStorage, part 1
1. part of #389 2. huge refactoring
This commit is contained in:
@@ -5,10 +5,10 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin.Program.ProgramSources;
|
||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
|
||||
@@ -27,8 +27,25 @@ namespace Wox.Plugin.Program
|
||||
{"AppPathsProgramSource", typeof(AppPathsProgramSource)}
|
||||
};
|
||||
private PluginInitContext _context;
|
||||
private static ProgramCacheStorage _cache = ProgramCacheStorage.Instance;
|
||||
private static ProgramStorage _settings = ProgramStorage.Instance;
|
||||
|
||||
private static ProgramIndexCache _cache;
|
||||
private static BinaryStorage<ProgramIndexCache> _cacheStorage;
|
||||
private static Settings _settings ;
|
||||
private readonly PluginSettingsStorage<Settings> _settingsStorage;
|
||||
|
||||
public Programs()
|
||||
{
|
||||
_settingsStorage = new PluginSettingsStorage<Settings>();
|
||||
_settings = _settingsStorage.Load();
|
||||
_cacheStorage = new BinaryStorage<ProgramIndexCache>();
|
||||
_cache = _cacheStorage.Load();
|
||||
}
|
||||
|
||||
~Programs()
|
||||
{
|
||||
_settingsStorage.Save();
|
||||
_cacheStorage.Save();
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
@@ -62,15 +79,13 @@ namespace Wox.Plugin.Program
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
this._context = context;
|
||||
_context = context;
|
||||
Stopwatch.Debug("Preload programs", () =>
|
||||
{
|
||||
programs = _cache.Programs;
|
||||
});
|
||||
Log.Info($"Preload {programs.Count} programs from cache");
|
||||
// happlebao todo fix this
|
||||
//Stopwatch.Debug("Program Index", IndexPrograms);
|
||||
IndexPrograms();
|
||||
Stopwatch.Debug("Program Index", IndexPrograms);
|
||||
}
|
||||
|
||||
public static void IndexPrograms()
|
||||
@@ -120,7 +135,6 @@ namespace Wox.Plugin.Program
|
||||
.Select(g => g.First()).ToList();
|
||||
|
||||
_cache.Programs = programs;
|
||||
_cache.Save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user