mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Enable user selected program loading only
Update logic, add program source only loading
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
@@ -31,7 +31,7 @@ namespace Wox.Plugin.Program
|
||||
_settingsStorage = new PluginJsonStorage<Settings>();
|
||||
_settings = _settingsStorage.Load();
|
||||
|
||||
Stopwatch.Normal("|Wox.Plugin.Program.Main|Preload programs cost", () =>
|
||||
var preloadcost = Stopwatch.Normal("|Wox.Plugin.Program.Main|Preload programs cost", () =>
|
||||
{
|
||||
_win32Storage = new BinaryStorage<Win32[]>("Win32");
|
||||
_win32s = _win32Storage.TryLoad(new Win32[] { });
|
||||
@@ -40,10 +40,48 @@ namespace Wox.Plugin.Program
|
||||
});
|
||||
Log.Info($"|Wox.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>");
|
||||
Log.Info($"|Wox.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>");
|
||||
Task.Run(() =>
|
||||
|
||||
//########DELETE
|
||||
long win32indexcost = 0;
|
||||
long uwpindexcost = 0;
|
||||
|
||||
var a = Task.Run(() =>
|
||||
{
|
||||
Stopwatch.Normal("|Wox.Plugin.Program.Main|Program index cost", IndexPrograms);
|
||||
if (!_win32s.Any())
|
||||
win32indexcost = Stopwatch.Normal("|Wox.Plugin.Program.Main|Win32Program index cost", IndexWin32Programs);
|
||||
});
|
||||
|
||||
var b = Task.Run(() =>
|
||||
{
|
||||
if (!_uwps.Any())
|
||||
uwpindexcost = Stopwatch.Normal("|Wox.Plugin.Program.Main|Win32Program index cost", IndexUWPPrograms);
|
||||
});
|
||||
|
||||
Task.WaitAll(a, b);
|
||||
|
||||
//########DELETE
|
||||
/*
|
||||
* With roaming folder already
|
||||
Preload programs cost <24ms>
|
||||
Program index cost <3163ms>
|
||||
|
||||
no roaming yet (clean)
|
||||
Preload programs cost <79ms>
|
||||
Program index cost <2900ms>
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
long totalindexcost = win32indexcost + uwpindexcost;
|
||||
|
||||
if (preloadcost > 70 || totalindexcost > 4000)
|
||||
{
|
||||
#if DEBUG
|
||||
#else
|
||||
throw e
|
||||
#endif
|
||||
}
|
||||
//########DELETE
|
||||
}
|
||||
|
||||
public void Save()
|
||||
@@ -69,36 +107,36 @@ namespace Wox.Plugin.Program
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public static void IndexPrograms()
|
||||
public static void IndexWin32Programs()
|
||||
{
|
||||
Win32[] w = { };
|
||||
UWP.Application[] u = { };
|
||||
var t1 = Task.Run(() =>
|
||||
lock (IndexLock)
|
||||
{
|
||||
w = Win32.All(_settings);
|
||||
});
|
||||
var t2 = Task.Run(() =>
|
||||
{
|
||||
var windows10 = new Version(10, 0);
|
||||
var support = Environment.OSVersion.Version.Major >= windows10.Major;
|
||||
if (support)
|
||||
{
|
||||
u = UWP.All();
|
||||
}
|
||||
else
|
||||
{
|
||||
u = new UWP.Application[] { };
|
||||
}
|
||||
});
|
||||
Task.WaitAll(t1, t2);
|
||||
_win32s = Win32.All(_settings);
|
||||
}
|
||||
}
|
||||
|
||||
public static void IndexUWPPrograms()
|
||||
{
|
||||
var windows10 = new Version(10, 0);
|
||||
var support = Environment.OSVersion.Version.Major >= windows10.Major;
|
||||
|
||||
lock (IndexLock)
|
||||
{
|
||||
_win32s = w;
|
||||
_uwps = u;
|
||||
var allUWPs = support ? UWP.All() : new UWP.Application[] { };
|
||||
|
||||
_uwps = UWP.RetainApplications(allUWPs, _settings.ProgramSources, _settings.EnableProgramSourceOnly);
|
||||
}
|
||||
}
|
||||
|
||||
public static void IndexPrograms()
|
||||
{
|
||||
var t1 = Task.Run(() => { IndexWin32Programs(); });
|
||||
|
||||
var t2 = Task.Run(() => { IndexUWPPrograms(); });
|
||||
|
||||
Task.WaitAll(t1, t2);
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
return new ProgramSetting(_context, _settings);
|
||||
|
||||
@@ -202,6 +202,20 @@ namespace Wox.Plugin.Program.Programs
|
||||
}
|
||||
}
|
||||
|
||||
public static Application[] RetainApplications(Application[] applications, List<Settings.ProgramSource> applicationsToRetainPaths, bool enableProgramSourceOnly)
|
||||
{
|
||||
if(enableProgramSourceOnly)
|
||||
return applications
|
||||
.Where(t1 => applicationsToRetainPaths
|
||||
.Any(x => x.LocationFile == t1.Package.Location
|
||||
&& x.EnableIndexing))
|
||||
.Select(t1 => t1).ToArray();
|
||||
|
||||
// Do not return if the application is disabled for indexing
|
||||
return applications.Where(t1 => !applicationsToRetainPaths.Any(x => x.LocationFile == t1.Package.Location && !x.EnableIndexing))
|
||||
.Select(t1 => t1).ToArray();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return FamilyName;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
@@ -262,9 +262,19 @@ namespace Wox.Plugin.Program.Programs
|
||||
|
||||
private static ParallelQuery<Win32> UnregisteredPrograms(List<Settings.ProgramSource> sources, string[] suffixes)
|
||||
{
|
||||
var paths = sources.Where(s => Directory.Exists(s.Location))
|
||||
.SelectMany(s => ProgramPaths(s.Location, suffixes))
|
||||
.ToArray();
|
||||
var list = new List<string>();
|
||||
sources.Where(s => Directory.Exists(s.Location) && s.EnableIndexing)
|
||||
.SelectMany(s => ProgramPaths(s.Location, suffixes))
|
||||
.ToList()
|
||||
.ForEach(x => list.Add(x));
|
||||
|
||||
sources.Where(x=> File.Exists(x.LocationFile) && x.EnableIndexing)
|
||||
.Select(y => y.LocationFile)
|
||||
.ToList()
|
||||
.ForEach(z => list.Add(z));
|
||||
|
||||
var paths = list.ToArray();
|
||||
|
||||
var programs1 = paths.AsParallel().Where(p => Extension(p) == ExeExtension).Select(ExeProgram);
|
||||
var programs2 = paths.AsParallel().Where(p => Extension(p) == ShortcutExtension).Select(ExeProgram);
|
||||
var programs3 = from p in paths.AsParallel()
|
||||
@@ -384,18 +394,24 @@ namespace Wox.Plugin.Program.Programs
|
||||
public static Win32[] All(Settings settings)
|
||||
{
|
||||
ParallelQuery<Win32> programs = new List<Win32>().AsParallel();
|
||||
|
||||
var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes);
|
||||
programs = programs.Concat(unregistered);
|
||||
|
||||
if (settings.EnableProgramSourceOnly)
|
||||
return programs.ToArray();
|
||||
|
||||
if (settings.EnableRegistrySource)
|
||||
{
|
||||
var appPaths = AppPathsPrograms(settings.ProgramSuffixes);
|
||||
programs = programs.Concat(appPaths);
|
||||
}
|
||||
|
||||
if (settings.EnableStartMenuSource)
|
||||
{
|
||||
var startMenu = StartMenuPrograms(settings.ProgramSuffixes);
|
||||
programs = programs.Concat(startMenu);
|
||||
}
|
||||
var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes);
|
||||
programs = programs.Concat(unregistered);
|
||||
}
|
||||
//.Select(ScoreFilter);
|
||||
return programs.ToArray();
|
||||
}
|
||||
|
||||
@@ -12,11 +12,15 @@ namespace Wox.Plugin.Program
|
||||
|
||||
public bool EnableRegistrySource { get; set; } = true;
|
||||
|
||||
public bool EnableProgramSourceOnly { get; set; } = false;
|
||||
|
||||
internal const char SuffixSeperator = ';';
|
||||
|
||||
public class ProgramSource
|
||||
{
|
||||
public string Location { get; set; }
|
||||
public string LocationFile { get; set; }
|
||||
public bool EnableIndexing { get; set; } = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user