mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-10 19:22:50 +08:00
Merging in Theme changes and moving win32Tests to Microsoft.Plugin.Program.UnitTests
This commit is contained in:
parent
3295ea84a4
commit
030dfc2370
@ -255,6 +255,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KeyboardManagerTest", "src\
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManagedCommon", "src\common\ManagedCommon\ManagedCommon.csproj", "{4AED67B6-55FD-486F-B917-E543DEE2CB3C}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManagedCommon", "src\common\ManagedCommon\ManagedCommon.csproj", "{4AED67B6-55FD-486F-B917-E543DEE2CB3C}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Plugin.Program.UnitTests", "src\modules\launcher\Plugins\Microsoft.Plugin.Program.UnitTests\Microsoft.Plugin.Program.UnitTests.csproj", "{42851751-CBC8-45A6-97F5-7A0753F7B4D1}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|x64 = Debug|x64
|
Debug|x64 = Debug|x64
|
||||||
@ -501,6 +503,10 @@ Global
|
|||||||
{4AED67B6-55FD-486F-B917-E543DEE2CB3C}.Debug|x64.Build.0 = Debug|x64
|
{4AED67B6-55FD-486F-B917-E543DEE2CB3C}.Debug|x64.Build.0 = Debug|x64
|
||||||
{4AED67B6-55FD-486F-B917-E543DEE2CB3C}.Release|x64.ActiveCfg = Release|x64
|
{4AED67B6-55FD-486F-B917-E543DEE2CB3C}.Release|x64.ActiveCfg = Release|x64
|
||||||
{4AED67B6-55FD-486F-B917-E543DEE2CB3C}.Release|x64.Build.0 = Release|x64
|
{4AED67B6-55FD-486F-B917-E543DEE2CB3C}.Release|x64.Build.0 = Release|x64
|
||||||
|
{42851751-CBC8-45A6-97F5-7A0753F7B4D1}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{42851751-CBC8-45A6-97F5-7A0753F7B4D1}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{42851751-CBC8-45A6-97F5-7A0753F7B4D1}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{42851751-CBC8-45A6-97F5-7A0753F7B4D1}.Release|x64.Build.0 = Release|x64
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -571,6 +577,7 @@ Global
|
|||||||
{E6410BFC-B341-498C-8C67-312C20CDD8D5} = {1AFB6476-670D-4E80-A464-657E01DFF482}
|
{E6410BFC-B341-498C-8C67-312C20CDD8D5} = {1AFB6476-670D-4E80-A464-657E01DFF482}
|
||||||
{62173D9A-6724-4C00-A1C8-FB646480A9EC} = {38BDB927-829B-4C65-9CD9-93FB05D66D65}
|
{62173D9A-6724-4C00-A1C8-FB646480A9EC} = {38BDB927-829B-4C65-9CD9-93FB05D66D65}
|
||||||
{4AED67B6-55FD-486F-B917-E543DEE2CB3C} = {1AFB6476-670D-4E80-A464-657E01DFF482}
|
{4AED67B6-55FD-486F-B917-E543DEE2CB3C} = {1AFB6476-670D-4E80-A464-657E01DFF482}
|
||||||
|
{42851751-CBC8-45A6-97F5-7A0753F7B4D1} = {4AFC9975-2456-4C70-94A4-84073C1CED93}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
|
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
|
||||||
|
<Platforms>x64</Platforms>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Moq" Version="4.14.3" />
|
||||||
|
<PackageReference Include="nunit" Version="3.12.0" />
|
||||||
|
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Microsoft.Plugin.Program\Microsoft.Plugin.Program.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||||
|
{
|
||||||
|
class PackageCatalogWrapperTests
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +1,17 @@
|
|||||||
using System;
|
using Moq;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Microsoft.Plugin.Program.Programs;
|
|
||||||
using Moq;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.Plugin.Program;
|
using Microsoft.Plugin.Program;
|
||||||
using System.IO.Packaging;
|
using System.IO.Packaging;
|
||||||
using Windows.ApplicationModel;
|
using Windows.ApplicationModel;
|
||||||
|
namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||||
namespace Wox.Test.Plugins
|
|
||||||
{
|
{
|
||||||
|
using Win32 = Microsoft.Plugin.Program.Programs.Win32;
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class Win32Tests
|
public class Win32Tests
|
||||||
{
|
{
|
||||||
@ -320,11 +318,11 @@ namespace Wox.Test.Plugins
|
|||||||
{
|
{
|
||||||
return twitter_pwa.FilterWebApplication(query);
|
return twitter_pwa.FilterWebApplication(query);
|
||||||
}
|
}
|
||||||
else if(Case == CASE_WEB_PAGE)
|
else if (Case == CASE_WEB_PAGE)
|
||||||
{
|
{
|
||||||
return pinned_webpage.FilterWebApplication(query);
|
return pinned_webpage.FilterWebApplication(query);
|
||||||
}
|
}
|
||||||
else if(Case == CASE_EDGE_NAMED_WEBPAGE)
|
else if (Case == CASE_EDGE_NAMED_WEBPAGE)
|
||||||
{
|
{
|
||||||
return edge_named_pinned_webpage.FilterWebApplication(query);
|
return edge_named_pinned_webpage.FilterWebApplication(query);
|
||||||
}
|
}
|
||||||
@ -338,7 +336,7 @@ namespace Wox.Test.Plugins
|
|||||||
[TestCase("ignoreQueryText")]
|
[TestCase("ignoreQueryText")]
|
||||||
public void Win32Applications_ShouldNotBeFiltered_WhenFilteringRunCommands(string query)
|
public void Win32Applications_ShouldNotBeFiltered_WhenFilteringRunCommands(string query)
|
||||||
{
|
{
|
||||||
// Even if there is an exact match in the name or exe name, applications should never be filtered
|
// Even if there is an exact match in the name or exe name, win32 applications should never be filtered
|
||||||
Assert.IsTrue(command_prompt.QueryEqualsNameForRunCommands(query));
|
Assert.IsTrue(command_prompt.QueryEqualsNameForRunCommands(query));
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
|||||||
|
using Microsoft.Plugin.Program.Storage;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Wox.Infrastructure.Storage;
|
||||||
|
|
||||||
|
namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
class ListRepositoryTests
|
||||||
|
{
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Contains_ShouldReturnTrue_WhenListIsInitializedWithItem()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var itemName = "originalItem1";
|
||||||
|
var mockStorage = new Mock<IStorage<IList<string>>>();
|
||||||
|
IRepository<string> repository = new ListRepository<string>(mockStorage.Object) { itemName };
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var result = repository.Contains(itemName);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.IsTrue(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Contains_ShouldReturnTrue_WhenListIsUpdatedWithAdd()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var mockStorage = new Mock<IStorage<IList<string>>>();
|
||||||
|
IRepository<string> repository = new ListRepository<string>(mockStorage.Object);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var itemName = "newItem";
|
||||||
|
repository.Add(itemName);
|
||||||
|
var result = repository.Contains(itemName);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.IsTrue(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Contains_ShouldReturnFalse_WhenListIsUpdatedWithRemove()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var itemName = "originalItem1";
|
||||||
|
var mockStorage = new Mock<IStorage<IList<string>>>();
|
||||||
|
IRepository<string> repository = new ListRepository<string>(mockStorage.Object) { itemName };
|
||||||
|
|
||||||
|
//Act
|
||||||
|
repository.Remove(itemName);
|
||||||
|
var result = repository.Contains(itemName);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.IsFalse(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,28 +13,26 @@ using Wox.Plugin;
|
|||||||
using Microsoft.Plugin.Program.Views;
|
using Microsoft.Plugin.Program.Views;
|
||||||
|
|
||||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||||
|
using Windows.ApplicationModel;
|
||||||
|
using Microsoft.Plugin.Program.Storage;
|
||||||
using Microsoft.Plugin.Program.Programs;
|
using Microsoft.Plugin.Program.Programs;
|
||||||
|
|
||||||
namespace Microsoft.Plugin.Program
|
namespace Microsoft.Plugin.Program
|
||||||
{
|
{
|
||||||
public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable, IDisposable
|
public class Main : IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable, IDisposable
|
||||||
{
|
{
|
||||||
private static readonly object IndexLock = new object();
|
private static readonly object IndexLock = new object();
|
||||||
internal static Programs.Win32[] _win32s { get; set; }
|
internal static Programs.Win32[] _win32s { get; set; }
|
||||||
internal static Programs.UWP.Application[] _uwps { get; set; }
|
|
||||||
internal static Settings _settings { get; set; }
|
internal static Settings _settings { get; set; }
|
||||||
|
|
||||||
FileSystemWatcher _watcher = null;
|
|
||||||
System.Timers.Timer _timer = null;
|
|
||||||
|
|
||||||
private static bool IsStartupIndexProgramsRequired => _settings.LastIndexTime.AddDays(3) < DateTime.Today;
|
private static bool IsStartupIndexProgramsRequired => _settings.LastIndexTime.AddDays(3) < DateTime.Today;
|
||||||
|
|
||||||
private static PluginInitContext _context;
|
private static PluginInitContext _context;
|
||||||
|
|
||||||
private static BinaryStorage<Programs.Win32[]> _win32Storage;
|
private static BinaryStorage<Programs.Win32[]> _win32Storage;
|
||||||
private static BinaryStorage<Programs.UWP.Application[]> _uwpStorage;
|
|
||||||
private readonly PluginJsonStorage<Settings> _settingsStorage;
|
private readonly PluginJsonStorage<Settings> _settingsStorage;
|
||||||
private bool _disposed = false;
|
private bool _disposed = false;
|
||||||
|
private PackageRepository _packageRepository = new PackageRepository(new PackageCatalogWrapper(), new BinaryStorage<IList<UWP.Application>>("UWP"));
|
||||||
|
|
||||||
public Main()
|
public Main()
|
||||||
{
|
{
|
||||||
@ -45,11 +43,10 @@ namespace Microsoft.Plugin.Program
|
|||||||
{
|
{
|
||||||
_win32Storage = new BinaryStorage<Programs.Win32[]>("Win32");
|
_win32Storage = new BinaryStorage<Programs.Win32[]>("Win32");
|
||||||
_win32s = _win32Storage.TryLoad(new Programs.Win32[] { });
|
_win32s = _win32Storage.TryLoad(new Programs.Win32[] { });
|
||||||
_uwpStorage = new BinaryStorage<Programs.UWP.Application[]>("UWP");
|
|
||||||
_uwps = _uwpStorage.TryLoad(new Programs.UWP.Application[] { });
|
_packageRepository.Load();
|
||||||
});
|
});
|
||||||
Log.Info($"|Microsoft.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>");
|
Log.Info($"|Microsoft.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>");
|
||||||
Log.Info($"|Microsoft.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>");
|
|
||||||
|
|
||||||
var a = Task.Run(() =>
|
var a = Task.Run(() =>
|
||||||
{
|
{
|
||||||
@ -59,42 +56,38 @@ namespace Microsoft.Plugin.Program
|
|||||||
|
|
||||||
var b = Task.Run(() =>
|
var b = Task.Run(() =>
|
||||||
{
|
{
|
||||||
if (IsStartupIndexProgramsRequired || !_uwps.Any())
|
if (IsStartupIndexProgramsRequired || !_packageRepository.Any())
|
||||||
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", IndexUWPPrograms);
|
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _packageRepository.IndexPrograms);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Task.WaitAll(a, b);
|
Task.WaitAll(a, b);
|
||||||
|
|
||||||
_settings.LastIndexTime = DateTime.Today;
|
_settings.LastIndexTime = DateTime.Today;
|
||||||
|
|
||||||
InitializeFileWatchers();
|
|
||||||
InitializeTimer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
_settingsStorage.Save();
|
_settingsStorage.Save();
|
||||||
_win32Storage.Save(_win32s);
|
_win32Storage.Save(_win32s);
|
||||||
_uwpStorage.Save(_uwps);
|
_packageRepository.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
Programs.Win32[] win32;
|
Programs.Win32[] win32;
|
||||||
Programs.UWP.Application[] uwps;
|
|
||||||
|
|
||||||
lock (IndexLock)
|
lock (IndexLock)
|
||||||
{
|
{
|
||||||
// just take the reference inside the lock to eliminate query time issues.
|
// just take the reference inside the lock to eliminate query time issues.
|
||||||
win32 = _win32s;
|
win32 = _win32s;
|
||||||
uwps = _uwps;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var results1 = win32.AsParallel()
|
var results1 = win32.AsParallel()
|
||||||
.Where(p => p.Enabled)
|
.Where(p => p.Enabled)
|
||||||
.Select(p => p.Result(query.Search, _context.API));
|
.Select(p => p.Result(query.Search, _context.API));
|
||||||
|
|
||||||
var results2 = uwps.AsParallel()
|
var results2 = _packageRepository.AsParallel()
|
||||||
.Where(p => p.Enabled)
|
.Where(p => p.Enabled)
|
||||||
.Select(p => p.Result(query.Search, _context.API));
|
.Select(p => p.Result(query.Search, _context.API));
|
||||||
|
|
||||||
@ -116,7 +109,7 @@ namespace Microsoft.Plugin.Program
|
|||||||
|
|
||||||
public void UpdateUWPIconPath(Theme theme)
|
public void UpdateUWPIconPath(Theme theme)
|
||||||
{
|
{
|
||||||
foreach (UWP.Application app in _uwps)
|
foreach (UWP.Application app in _packageRepository)
|
||||||
{
|
{
|
||||||
app.UpdatePath(theme);
|
app.UpdatePath(theme);
|
||||||
}
|
}
|
||||||
@ -131,33 +124,18 @@ namespace Microsoft.Plugin.Program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void IndexUWPPrograms()
|
|
||||||
{
|
|
||||||
var windows10 = new Version(10, 0);
|
|
||||||
var support = Environment.OSVersion.Version.Major >= windows10.Major;
|
|
||||||
|
|
||||||
var applications = support ? Programs.UWP.All() : new Programs.UWP.Application[] { };
|
|
||||||
lock (IndexLock)
|
|
||||||
{
|
|
||||||
_uwps = applications;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void IndexPrograms()
|
public void IndexPrograms()
|
||||||
{
|
{
|
||||||
var t1 = Task.Run(() => IndexWin32Programs());
|
var t1 = Task.Run(() => IndexWin32Programs());
|
||||||
var t2 = Task.Run(() => IndexUWPPrograms());
|
var t2 = Task.Run(() => _packageRepository.IndexPrograms());
|
||||||
|
|
||||||
Task.WaitAll(t1, t2);
|
Task.WaitAll(t1, t2);
|
||||||
|
|
||||||
_settings.LastIndexTime = DateTime.Today;
|
_settings.LastIndexTime = DateTime.Today;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Control CreateSettingPanel()
|
|
||||||
{
|
|
||||||
return new ProgramSetting(_context, _settings, _win32s, _uwps);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
{
|
{
|
||||||
return _context.API.GetTranslation("wox_plugin_program_plugin_name");
|
return _context.API.GetTranslation("wox_plugin_program_plugin_name");
|
||||||
@ -221,52 +199,5 @@ namespace Microsoft.Plugin.Program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeFileWatchers()
|
|
||||||
{
|
|
||||||
// Create a new FileSystemWatcher and set its properties.
|
|
||||||
_watcher = new FileSystemWatcher();
|
|
||||||
var resolvedPath = Environment.ExpandEnvironmentVariables("%ProgramFiles%");
|
|
||||||
_watcher.Path = resolvedPath;
|
|
||||||
|
|
||||||
//Filter to create and deletes of 'microsoft.system.package.metadata' directories.
|
|
||||||
_watcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName;
|
|
||||||
_watcher.IncludeSubdirectories = true;
|
|
||||||
|
|
||||||
// Add event handlers.
|
|
||||||
_watcher.Created += OnChanged;
|
|
||||||
_watcher.Deleted += OnChanged;
|
|
||||||
|
|
||||||
// Begin watching.
|
|
||||||
_watcher.EnableRaisingEvents = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeTimer()
|
|
||||||
{
|
|
||||||
//multiple file writes occur on install / uninstall. Adding a delay before actually indexing.
|
|
||||||
var delayInterval = 5000;
|
|
||||||
_timer = new System.Timers.Timer(delayInterval);
|
|
||||||
_timer.Enabled = true;
|
|
||||||
_timer.AutoReset = false;
|
|
||||||
_timer.Elapsed += FileWatchElapsedTimer;
|
|
||||||
_timer.Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
//When a watched directory changes then reset the timer.
|
|
||||||
private void OnChanged(object source, FileSystemEventArgs e)
|
|
||||||
{
|
|
||||||
Log.Debug($"|Microsoft.Plugin.Program.Main|Directory Changed: {e.FullPath} {e.ChangeType} - Resetting timer.");
|
|
||||||
_timer.Stop();
|
|
||||||
_timer.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FileWatchElapsedTimer(object sender, ElapsedEventArgs e)
|
|
||||||
{
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
Log.Debug($"|Microsoft.Plugin.Program.Main| ReIndexing UWP Programs");
|
|
||||||
IndexUWPPrograms();
|
|
||||||
Log.Debug($"|Microsoft.Plugin.Program.Main| Done ReIndexing");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Windows.ApplicationModel;
|
||||||
|
using Windows.Foundation;
|
||||||
|
|
||||||
|
namespace Microsoft.Plugin.Program.Programs
|
||||||
|
{
|
||||||
|
internal interface IPackageCatalog
|
||||||
|
{
|
||||||
|
event TypedEventHandler<PackageCatalog, PackageInstallingEventArgs> PackageInstalling;
|
||||||
|
event TypedEventHandler<PackageCatalog, PackageUninstallingEventArgs> PackageUninstalling;
|
||||||
|
event TypedEventHandler<PackageCatalog, PackageUpdatingEventArgs> PackageUpdating;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Windows.ApplicationModel;
|
||||||
|
using Windows.Foundation;
|
||||||
|
|
||||||
|
namespace Microsoft.Plugin.Program.Programs
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This is a simple wrapper class around the PackageCatalog to facilitate unit testing.
|
||||||
|
/// </summary>
|
||||||
|
internal class PackageCatalogWrapper : IPackageCatalog
|
||||||
|
{
|
||||||
|
PackageCatalog _packageCatalog;
|
||||||
|
|
||||||
|
public PackageCatalogWrapper()
|
||||||
|
{
|
||||||
|
//Opens the catalog of packages that is available for the current user.
|
||||||
|
_packageCatalog = PackageCatalog.OpenForCurrentUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Summary:
|
||||||
|
// Indicates that an app package is installing.
|
||||||
|
public event TypedEventHandler<PackageCatalog, PackageInstallingEventArgs> PackageInstalling
|
||||||
|
{
|
||||||
|
add
|
||||||
|
{
|
||||||
|
_packageCatalog.PackageInstalling += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove
|
||||||
|
{
|
||||||
|
_packageCatalog.PackageInstalling -= value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Summary:
|
||||||
|
// Indicates that an app package is installing.
|
||||||
|
public event TypedEventHandler<PackageCatalog, PackageUninstallingEventArgs> PackageUninstalling
|
||||||
|
{
|
||||||
|
add
|
||||||
|
{
|
||||||
|
_packageCatalog.PackageUninstalling += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove
|
||||||
|
{
|
||||||
|
_packageCatalog.PackageUninstalling -= value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Summary:
|
||||||
|
// Indicates that an app package is installing.
|
||||||
|
public event TypedEventHandler<PackageCatalog, PackageUpdatingEventArgs> PackageUpdating
|
||||||
|
{
|
||||||
|
add
|
||||||
|
{
|
||||||
|
_packageCatalog.PackageUpdating += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove
|
||||||
|
{
|
||||||
|
_packageCatalog.PackageUpdating -= value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -40,24 +40,17 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
|
|
||||||
public UWP(Package package)
|
public UWP(Package package)
|
||||||
{
|
{
|
||||||
Location = package.InstalledLocation.Path;
|
|
||||||
Name = package.Id.Name;
|
Name = package.Id.Name;
|
||||||
FullName = package.Id.FullName;
|
FullName = package.Id.FullName;
|
||||||
FamilyName = package.Id.FamilyName;
|
FamilyName = package.Id.FamilyName;
|
||||||
InitializeAppInfo();
|
|
||||||
Apps = Apps.Where(a =>
|
|
||||||
{
|
|
||||||
var valid =
|
|
||||||
!string.IsNullOrEmpty(a.UserModelId) &&
|
|
||||||
!string.IsNullOrEmpty(a.DisplayName);
|
|
||||||
return valid;
|
|
||||||
}).ToArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeAppInfo()
|
public void InitializeAppInfo(string installedLocation)
|
||||||
{
|
{
|
||||||
|
Location = installedLocation;
|
||||||
AppxPackageHelper _helper = new AppxPackageHelper();
|
AppxPackageHelper _helper = new AppxPackageHelper();
|
||||||
var path = Path.Combine(Location, "AppxManifest.xml");
|
var path = Path.Combine(installedLocation, "AppxManifest.xml");
|
||||||
|
|
||||||
var namespaces = XmlNamespaces(path);
|
var namespaces = XmlNamespaces(path);
|
||||||
InitPackageVersion(namespaces);
|
InitPackageVersion(namespaces);
|
||||||
@ -154,21 +147,14 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
u = new UWP(p);
|
u = new UWP(p);
|
||||||
|
u.InitializeAppInfo(p.InstalledLocation.Path);
|
||||||
}
|
}
|
||||||
#if !DEBUG
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException($"|UWP|All|{p.InstalledLocation}|An unexpected error occurred and "
|
ProgramLogger.LogException($"|UWP|All|{p.InstalledLocation}|An unexpected error occurred and "
|
||||||
+ $"unable to convert Package to UWP for {p.Id.FullName}", e);
|
+ $"unable to convert Package to UWP for {p.Id.FullName}", e);
|
||||||
return new Application[] { };
|
return new Application[] { };
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#if DEBUG //make developer aware and implement handling
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return u.Apps;
|
return u.Apps;
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|
||||||
|
@ -0,0 +1,86 @@
|
|||||||
|
using Microsoft.Plugin.Program.Logger;
|
||||||
|
using Microsoft.Plugin.Program.Programs;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Windows.ApplicationModel;
|
||||||
|
using Wox.Infrastructure.Storage;
|
||||||
|
|
||||||
|
namespace Microsoft.Plugin.Program.Storage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A repository for storing packaged applications such as UWP apps or appx packaged desktop apps.
|
||||||
|
/// This repository will also monitor for changes to the PackageCatelog and update the repository accordingly
|
||||||
|
/// </summary>
|
||||||
|
internal class PackageRepository : ListRepository<UWP.Application>, IRepository<UWP.Application>
|
||||||
|
{
|
||||||
|
IPackageCatalog _packageCatalog;
|
||||||
|
public PackageRepository(IPackageCatalog packageCatalog, IStorage<IList<UWP.Application>> storage) : base(storage)
|
||||||
|
{
|
||||||
|
_packageCatalog = packageCatalog ?? throw new ArgumentNullException("packageCatalog", "PackageRepository expects an interface to be able to subscribe to package events");
|
||||||
|
_packageCatalog.PackageInstalling += OnPackageInstalling;
|
||||||
|
_packageCatalog.PackageUninstalling += OnPackageUninstalling;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnPackageInstalling(PackageCatalog p, PackageInstallingEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.IsComplete)
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var uwp = new UWP(args.Package);
|
||||||
|
uwp.InitializeAppInfo(args.Package.InstalledLocation.Path);
|
||||||
|
foreach (var app in uwp.Apps)
|
||||||
|
{
|
||||||
|
Add(app);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//InitializeAppInfo will throw if there is no AppxManifest.xml for the package.
|
||||||
|
//Note there are sometimes multiple packages per application and this doesn't necessarily mean that we haven't found the app.
|
||||||
|
//eg. "Could not find file 'C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminalPreview_2020.616.45.0_neutral_~_8wekyb3d8bbwe\\AppxManifest.xml'."
|
||||||
|
|
||||||
|
catch ( System.IO.FileNotFoundException e)
|
||||||
|
{
|
||||||
|
ProgramLogger.LogException($"|UWP|OnPackageInstalling|{e.Message}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnPackageUninstalling(PackageCatalog p, PackageUninstallingEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.Progress == 0)
|
||||||
|
{
|
||||||
|
//find apps associated with this package.
|
||||||
|
var uwp = new UWP(args.Package);
|
||||||
|
var apps = _items.Where(a => a.Package.Equals(uwp)).ToArray();
|
||||||
|
foreach(var app in apps)
|
||||||
|
{
|
||||||
|
Remove(app);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void IndexPrograms()
|
||||||
|
{
|
||||||
|
var windows10 = new Version(10, 0);
|
||||||
|
var support = Environment.OSVersion.Version.Major >= windows10.Major;
|
||||||
|
|
||||||
|
var applications = support ? Programs.UWP.All() : new Programs.UWP.Application[] { };
|
||||||
|
Set(applications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
_storage.Save(_items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Load()
|
||||||
|
{
|
||||||
|
var items = _storage.TryLoad(new Programs.UWP.Application[] { });
|
||||||
|
Set(items);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -61,20 +61,6 @@ namespace Microsoft.Plugin.Program.Views.Commands
|
|||||||
Enabled = t1.Enabled
|
Enabled = t1.Enabled
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
Main._uwps
|
|
||||||
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
|
|
||||||
.ToList()
|
|
||||||
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList
|
|
||||||
.Add(
|
|
||||||
new ProgramSource
|
|
||||||
{
|
|
||||||
Name = t1.DisplayName,
|
|
||||||
Location = t1.Package.Location,
|
|
||||||
UniqueIdentifier = t1.UniqueIdentifier,
|
|
||||||
Enabled = t1.Enabled
|
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SetProgramSourcesStatus(this List<ProgramSource> list, List<ProgramSource> selectedProgramSourcesToDisable, bool status)
|
internal static void SetProgramSourcesStatus(this List<ProgramSource> list, List<ProgramSource> selectedProgramSourcesToDisable, bool status)
|
||||||
@ -88,11 +74,6 @@ namespace Microsoft.Plugin.Program.Views.Commands
|
|||||||
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
||||||
.ToList()
|
.ToList()
|
||||||
.ForEach(t1 => t1.Enabled = status);
|
.ForEach(t1 => t1.Enabled = status);
|
||||||
|
|
||||||
Main._uwps
|
|
||||||
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
|
||||||
.ToList()
|
|
||||||
.ForEach(t1 => t1.Enabled = status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void StoreDisabledInSettings(this List<ProgramSource> list)
|
internal static void StoreDisabledInSettings(this List<ProgramSource> list)
|
||||||
@ -133,7 +114,7 @@ namespace Microsoft.Plugin.Program.Views.Commands
|
|||||||
|
|
||||||
internal static bool IsReindexRequired(this List<ProgramSource> selectedItems)
|
internal static bool IsReindexRequired(this List<ProgramSource> selectedItems)
|
||||||
{
|
{
|
||||||
if (selectedItems.Where(t1 => t1.Enabled && !Main._uwps.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)).Count() > 0
|
if (selectedItems.Where(t1 => t1.Enabled).Count() > 0
|
||||||
&& selectedItems.Where(t1 => t1.Enabled && !Main._win32s.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)).Count() > 0)
|
&& selectedItems.Where(t1 => t1.Enabled && !Main._win32s.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)).Count() > 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -51,7 +51,6 @@ namespace Microsoft.Plugin.Program.Views
|
|||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Visible; });
|
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Visible; });
|
||||||
Main.IndexPrograms();
|
|
||||||
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Hidden; });
|
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Hidden; });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
/// Storage object using binary data
|
/// Storage object using binary data
|
||||||
/// Normally, it has better performance, but not readable
|
/// Normally, it has better performance, but not readable
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BinaryStorage<T>
|
public class BinaryStorage<T> : IStorage<T>
|
||||||
{
|
{
|
||||||
// This storage helper returns whether or not to delete the binary storage items
|
// This storage helper returns whether or not to delete the binary storage items
|
||||||
private static readonly int BINARY_STORAGE = 0;
|
private static readonly int BINARY_STORAGE = 0;
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Wox.Infrastructure.Storage
|
||||||
|
{
|
||||||
|
public interface IRepository<T>
|
||||||
|
{
|
||||||
|
void Add(T insertedItem);
|
||||||
|
void Remove(T removedItem);
|
||||||
|
bool Contains(T item);
|
||||||
|
void Set(IList<T> list);
|
||||||
|
bool Any();
|
||||||
|
}
|
||||||
|
}
|
23
src/modules/launcher/Wox.Infrastructure/Storage/IStorage.cs
Normal file
23
src/modules/launcher/Wox.Infrastructure/Storage/IStorage.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Wox.Infrastructure.Storage
|
||||||
|
{
|
||||||
|
public interface IStorage<T>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Saves the data
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
void Save(T data);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to load data, otherwise it will return the default provided
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="defaultData"></param>
|
||||||
|
/// <returns>The loaded data or default</returns>
|
||||||
|
T TryLoad(T defaultData);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
using NLog.Filters;
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Wox.Infrastructure;
|
||||||
|
|
||||||
|
namespace Wox.Infrastructure.Storage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The intent of this class is to provide a basic subset of 'list' like operations, without exposing callers to the internal representation
|
||||||
|
/// of the data structure. Currently this is implemented as a list for it's simplicity.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
public class ListRepository<T> : IRepository<T>, IEnumerable<T>
|
||||||
|
{
|
||||||
|
protected IList<T> _items = new List<T>();
|
||||||
|
protected IStorage<IList<T>> _storage;
|
||||||
|
|
||||||
|
public ListRepository(IStorage<IList<T>> storage)
|
||||||
|
{
|
||||||
|
_storage = storage ?? throw new ArgumentNullException("storage", "StorageRepository requires an initialized storage interface");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set(IList<T> items)
|
||||||
|
{
|
||||||
|
//enforce that internal representation
|
||||||
|
_items = items.ToList<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Any()
|
||||||
|
{
|
||||||
|
return _items.Any();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Add(T insertedItem)
|
||||||
|
{
|
||||||
|
_items.Add(insertedItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(T removedItem)
|
||||||
|
{
|
||||||
|
_items.Remove(removedItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParallelQuery<T> AsParallel()
|
||||||
|
{
|
||||||
|
return _items.AsParallel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Contains(T item)
|
||||||
|
{
|
||||||
|
return _items.Contains(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerator<T> GetEnumerator()
|
||||||
|
{
|
||||||
|
return _items.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return _items.GetEnumerator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,8 +2,10 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using static Wox.Infrastructure.StringMatcher;
|
using static Wox.Infrastructure.StringMatcher;
|
||||||
|
|
||||||
|
[assembly: InternalsVisibleToAttribute("Microsoft.Plugin.Program.UnitTests")]
|
||||||
namespace Wox.Infrastructure
|
namespace Wox.Infrastructure
|
||||||
{
|
{
|
||||||
public class StringMatcher
|
public class StringMatcher
|
||||||
|
Loading…
Reference in New Issue
Block a user