mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
* Merging in Theme changes and moving win32Tests to Microsoft.Plugin.Program.UnitTests * Fixing message format for exception * Changing test structure. Need to add unit tests. * Updating packagerepository comment based on pr feedback * Fixing potential race condition in ListRepository. Now internally implemented as a concurrent dictionary. * Removing unecessary implementation of IRepository interface as this is implemented by the base class. * Restoring checks for invalid uwp apps based on PR feedback. This was accidentally removed when moving the initialize outside the constructor. * Fixing comments * Adding newline to end of file for IProgramRepository
This commit is contained in:
committed by
GitHub
parent
12d9d59d85
commit
b1d662a5b1
@@ -0,0 +1,11 @@
|
||||
using Windows.ApplicationModel;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Storage
|
||||
{
|
||||
internal interface IProgramRepository
|
||||
{
|
||||
void IndexPrograms();
|
||||
void Load();
|
||||
void Save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
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>, IProgramRepository
|
||||
{
|
||||
private IStorage<IList<UWP.Application>> _storage;
|
||||
|
||||
private IPackageCatalog _packageCatalog;
|
||||
public PackageRepository(IPackageCatalog packageCatalog, IStorage<IList<UWP.Application>> storage)
|
||||
{
|
||||
_storage = storage ?? throw new ArgumentNullException("storage", "StorageRepository requires an initialized storage interface");
|
||||
_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 product 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|{args.Package.InstalledLocation}|{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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user