mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Use variable instead of global static method
1. introduce variable 2. part of #389 3. refactoring program suffix in program plugin 4. 全局变量一时爽,代码重构火葬场
This commit is contained in:
@@ -27,6 +27,8 @@ namespace Wox.Plugin.Program
|
||||
{"AppPathsProgramSource", typeof(AppPathsProgramSource)}
|
||||
};
|
||||
private PluginInitContext _context;
|
||||
private static ProgramCacheStorage _cache = ProgramCacheStorage.Instance;
|
||||
private static ProgramStorage _settings = ProgramStorage.Instance;
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
@@ -63,10 +65,12 @@ namespace Wox.Plugin.Program
|
||||
this._context = context;
|
||||
Stopwatch.Debug("Preload programs", () =>
|
||||
{
|
||||
programs = ProgramCacheStorage.Instance.Programs;
|
||||
programs = _cache.Programs;
|
||||
});
|
||||
Log.Info($"Preload {programs.Count} programs from cache");
|
||||
Stopwatch.Debug("Program Index", IndexPrograms);
|
||||
// happlebao todo fix this
|
||||
//Stopwatch.Debug("Program Index", IndexPrograms);
|
||||
IndexPrograms();
|
||||
}
|
||||
|
||||
public static void IndexPrograms()
|
||||
@@ -75,15 +79,18 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
List<ProgramSource> programSources = new List<ProgramSource>();
|
||||
programSources.AddRange(LoadDeaultProgramSources());
|
||||
if (ProgramStorage.Instance.ProgramSources != null &&
|
||||
ProgramStorage.Instance.ProgramSources.Count(o => o.Enabled) > 0)
|
||||
if (_settings.ProgramSources != null &&
|
||||
_settings.ProgramSources.Count(o => o.Enabled) > 0)
|
||||
{
|
||||
programSources.AddRange(ProgramStorage.Instance.ProgramSources);
|
||||
programSources.AddRange(_settings.ProgramSources);
|
||||
}
|
||||
|
||||
sources.Clear();
|
||||
foreach (var source in programSources.Where(o => o.Enabled))
|
||||
{
|
||||
// happlebao todo: temp hack for program suffixes
|
||||
source.Suffixes = _settings.ProgramSuffixes;
|
||||
|
||||
Type sourceClass;
|
||||
if (SourceTypes.TryGetValue(source.Type, out sourceClass))
|
||||
{
|
||||
@@ -112,8 +119,8 @@ namespace Wox.Plugin.Program
|
||||
programs = tempPrograms.GroupBy(x => new { x.ExecutePath, x.ExecuteName })
|
||||
.Select(g => g.First()).ToList();
|
||||
|
||||
ProgramCacheStorage.Instance.Programs = programs;
|
||||
ProgramCacheStorage.Instance.Save();
|
||||
_cache.Programs = programs;
|
||||
_cache.Save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,19 +133,19 @@ namespace Wox.Plugin.Program
|
||||
list.Add(new ProgramSource
|
||||
{
|
||||
BonusPoints = 0,
|
||||
Enabled = ProgramStorage.Instance.EnableStartMenuSource,
|
||||
Enabled = _settings.EnableStartMenuSource,
|
||||
Type = "CommonStartMenuProgramSource"
|
||||
});
|
||||
list.Add(new ProgramSource
|
||||
{
|
||||
BonusPoints = 0,
|
||||
Enabled = ProgramStorage.Instance.EnableStartMenuSource,
|
||||
Enabled = _settings.EnableStartMenuSource,
|
||||
Type = "UserStartMenuProgramSource"
|
||||
});
|
||||
list.Add(new ProgramSource
|
||||
{
|
||||
BonusPoints = -10,
|
||||
Enabled = ProgramStorage.Instance.EnableRegistrySource,
|
||||
Enabled = _settings.EnableRegistrySource,
|
||||
Type = "AppPathsProgramSource"
|
||||
});
|
||||
return list;
|
||||
@@ -163,7 +170,7 @@ namespace Wox.Plugin.Program
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
return new ProgramSetting(_context);
|
||||
return new ProgramSetting(_context, _settings);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user