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
This commit is contained in:
@@ -1,207 +1,185 @@
|
||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
using Microsoft.Plugin.Program.Views;
|
||||
|
||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
using Microsoft.Plugin.Program.Programs;
|
||||
|
||||
namespace Microsoft.Plugin.Program
|
||||
{
|
||||
public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable, IDisposable
|
||||
{
|
||||
private static readonly object IndexLock = new object();
|
||||
internal static Programs.Win32[] _win32s { get; set; }
|
||||
internal static Programs.UWP.Application[] _uwps { 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 PluginInitContext _context;
|
||||
|
||||
private static BinaryStorage<Programs.Win32[]> _win32Storage;
|
||||
private static BinaryStorage<Programs.UWP.Application[]> _uwpStorage;
|
||||
private readonly PluginJsonStorage<Settings> _settingsStorage;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
using Microsoft.Plugin.Program.Views;
|
||||
|
||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
using Windows.ApplicationModel;
|
||||
using Microsoft.Plugin.Program.Storage;
|
||||
using Microsoft.Plugin.Program.Programs;
|
||||
|
||||
namespace Microsoft.Plugin.Program
|
||||
{
|
||||
public class Main : IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable, IDisposable
|
||||
{
|
||||
private static readonly object IndexLock = new object();
|
||||
internal static Programs.Win32[] _win32s { get; set; }
|
||||
internal static Settings _settings { get; set; }
|
||||
|
||||
private static bool IsStartupIndexProgramsRequired => _settings.LastIndexTime.AddDays(3) < DateTime.Today;
|
||||
|
||||
private static PluginInitContext _context;
|
||||
|
||||
private static BinaryStorage<Programs.Win32[]> _win32Storage;
|
||||
private readonly PluginJsonStorage<Settings> _settingsStorage;
|
||||
private bool _disposed = false;
|
||||
|
||||
public Main()
|
||||
{
|
||||
_settingsStorage = new PluginJsonStorage<Settings>();
|
||||
_settings = _settingsStorage.Load();
|
||||
|
||||
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Preload programs cost", () =>
|
||||
{
|
||||
_win32Storage = new BinaryStorage<Programs.Win32[]>("Win32");
|
||||
_win32s = _win32Storage.TryLoad(new Programs.Win32[] { });
|
||||
_uwpStorage = new BinaryStorage<Programs.UWP.Application[]>("UWP");
|
||||
_uwps = _uwpStorage.TryLoad(new Programs.UWP.Application[] { });
|
||||
});
|
||||
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(() =>
|
||||
{
|
||||
if (IsStartupIndexProgramsRequired || !_win32s.Any())
|
||||
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", IndexWin32Programs);
|
||||
});
|
||||
|
||||
var b = Task.Run(() =>
|
||||
{
|
||||
if (IsStartupIndexProgramsRequired || !_uwps.Any())
|
||||
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", IndexUWPPrograms);
|
||||
});
|
||||
|
||||
Task.WaitAll(a, b);
|
||||
|
||||
_settings.LastIndexTime = DateTime.Today;
|
||||
|
||||
InitializeFileWatchers();
|
||||
InitializeTimer();
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
_settingsStorage.Save();
|
||||
_win32Storage.Save(_win32s);
|
||||
_uwpStorage.Save(_uwps);
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
Programs.Win32[] win32;
|
||||
Programs.UWP.Application[] uwps;
|
||||
|
||||
lock (IndexLock)
|
||||
{
|
||||
// just take the reference inside the lock to eliminate query time issues.
|
||||
win32 = _win32s;
|
||||
uwps = _uwps;
|
||||
}
|
||||
|
||||
var results1 = win32.AsParallel()
|
||||
.Where(p => p.Enabled)
|
||||
.Select(p => p.Result(query.Search, _context.API));
|
||||
|
||||
var results2 = uwps.AsParallel()
|
||||
.Where(p => p.Enabled)
|
||||
.Select(p => p.Result(query.Search, _context.API));
|
||||
|
||||
var result = results1.Concat(results2).Where(r => r != null && r.Score > 0).ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
_context = context;
|
||||
_context.API.ThemeChanged += OnThemeChanged;
|
||||
UpdateUWPIconPath(_context.API.GetCurrentTheme());
|
||||
}
|
||||
|
||||
public void OnThemeChanged(Theme _, Theme currentTheme)
|
||||
{
|
||||
UpdateUWPIconPath(currentTheme);
|
||||
}
|
||||
|
||||
public void UpdateUWPIconPath(Theme theme)
|
||||
{
|
||||
foreach (UWP.Application app in _uwps)
|
||||
{
|
||||
app.UpdatePath(theme);
|
||||
}
|
||||
}
|
||||
|
||||
public static void IndexWin32Programs()
|
||||
{
|
||||
var win32S = Programs.Win32.All(_settings);
|
||||
lock (IndexLock)
|
||||
{
|
||||
_win32s = win32S;
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
var t1 = Task.Run(() => IndexWin32Programs());
|
||||
var t2 = Task.Run(() => IndexUWPPrograms());
|
||||
|
||||
Task.WaitAll(t1, t2);
|
||||
|
||||
_settings.LastIndexTime = DateTime.Today;
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
return new ProgramSetting(_context, _settings, _win32s, _uwps);
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginTitle()
|
||||
{
|
||||
return _context.API.GetTranslation("wox_plugin_program_plugin_name");
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginDescription()
|
||||
{
|
||||
return _context.API.GetTranslation("wox_plugin_program_plugin_description");
|
||||
}
|
||||
|
||||
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
var menuOptions = new List<ContextMenuResult>();
|
||||
var program = selectedResult.ContextData as Programs.IProgram;
|
||||
if (program != null)
|
||||
{
|
||||
menuOptions = program.ContextMenus(_context.API);
|
||||
}
|
||||
|
||||
return menuOptions;
|
||||
}
|
||||
|
||||
public static void StartProcess(Func<ProcessStartInfo, Process> runProcess, ProcessStartInfo info)
|
||||
{
|
||||
try
|
||||
{
|
||||
runProcess(info);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
var name = "Plugin: Program";
|
||||
var message = $"Unable to start: {info.FileName}";
|
||||
_context.API.ShowMsg(name, message, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReloadData()
|
||||
{
|
||||
IndexPrograms();
|
||||
}
|
||||
|
||||
public void UpdateSettings(PowerLauncherSettings settings)
|
||||
{
|
||||
}
|
||||
private PackageRepository _packageRepository = new PackageRepository(new PackageCatalogWrapper(), new BinaryStorage<IList<UWP.Application>>("UWP"));
|
||||
|
||||
public Main()
|
||||
{
|
||||
_settingsStorage = new PluginJsonStorage<Settings>();
|
||||
_settings = _settingsStorage.Load();
|
||||
|
||||
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Preload programs cost", () =>
|
||||
{
|
||||
_win32Storage = new BinaryStorage<Programs.Win32[]>("Win32");
|
||||
_win32s = _win32Storage.TryLoad(new Programs.Win32[] { });
|
||||
|
||||
_packageRepository.Load();
|
||||
});
|
||||
Log.Info($"|Microsoft.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>");
|
||||
|
||||
var a = Task.Run(() =>
|
||||
{
|
||||
if (IsStartupIndexProgramsRequired || !_win32s.Any())
|
||||
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", IndexWin32Programs);
|
||||
});
|
||||
|
||||
var b = Task.Run(() =>
|
||||
{
|
||||
if (IsStartupIndexProgramsRequired || !_packageRepository.Any())
|
||||
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _packageRepository.IndexPrograms);
|
||||
});
|
||||
|
||||
|
||||
Task.WaitAll(a, b);
|
||||
|
||||
_settings.LastIndexTime = DateTime.Today;
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
_settingsStorage.Save();
|
||||
_win32Storage.Save(_win32s);
|
||||
_packageRepository.Save();
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
Programs.Win32[] win32;
|
||||
|
||||
lock (IndexLock)
|
||||
{
|
||||
// just take the reference inside the lock to eliminate query time issues.
|
||||
win32 = _win32s;
|
||||
}
|
||||
|
||||
var results1 = win32.AsParallel()
|
||||
.Where(p => p.Enabled)
|
||||
.Select(p => p.Result(query.Search, _context.API));
|
||||
|
||||
var results2 = _packageRepository.AsParallel()
|
||||
.Where(p => p.Enabled)
|
||||
.Select(p => p.Result(query.Search, _context.API));
|
||||
|
||||
var result = results1.Concat(results2).Where(r => r != null && r.Score > 0).ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
_context = context;
|
||||
_context.API.ThemeChanged += OnThemeChanged;
|
||||
UpdateUWPIconPath(_context.API.GetCurrentTheme());
|
||||
}
|
||||
|
||||
public void OnThemeChanged(Theme _, Theme currentTheme)
|
||||
{
|
||||
UpdateUWPIconPath(currentTheme);
|
||||
}
|
||||
|
||||
public void UpdateUWPIconPath(Theme theme)
|
||||
{
|
||||
foreach (UWP.Application app in _packageRepository)
|
||||
{
|
||||
app.UpdatePath(theme);
|
||||
}
|
||||
}
|
||||
|
||||
public static void IndexWin32Programs()
|
||||
{
|
||||
var win32S = Programs.Win32.All(_settings);
|
||||
lock (IndexLock)
|
||||
{
|
||||
_win32s = win32S;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void IndexPrograms()
|
||||
{
|
||||
var t1 = Task.Run(() => IndexWin32Programs());
|
||||
var t2 = Task.Run(() => _packageRepository.IndexPrograms());
|
||||
|
||||
Task.WaitAll(t1, t2);
|
||||
|
||||
_settings.LastIndexTime = DateTime.Today;
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginTitle()
|
||||
{
|
||||
return _context.API.GetTranslation("wox_plugin_program_plugin_name");
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginDescription()
|
||||
{
|
||||
return _context.API.GetTranslation("wox_plugin_program_plugin_description");
|
||||
}
|
||||
|
||||
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
var menuOptions = new List<ContextMenuResult>();
|
||||
var program = selectedResult.ContextData as Programs.IProgram;
|
||||
if (program != null)
|
||||
{
|
||||
menuOptions = program.ContextMenus(_context.API);
|
||||
}
|
||||
|
||||
return menuOptions;
|
||||
}
|
||||
|
||||
public static void StartProcess(Func<ProcessStartInfo, Process> runProcess, ProcessStartInfo info)
|
||||
{
|
||||
try
|
||||
{
|
||||
runProcess(info);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
var name = "Plugin: Program";
|
||||
var message = $"Unable to start: {info.FileName}";
|
||||
_context.API.ShowMsg(name, message, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReloadData()
|
||||
{
|
||||
IndexPrograms();
|
||||
}
|
||||
|
||||
public void UpdateSettings(PowerLauncherSettings settings)
|
||||
{
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
public string Name { get; }
|
||||
public string FullName { get; }
|
||||
public string FamilyName { get; }
|
||||
public string FamilyName { get; }
|
||||
public string Location { get; set; }
|
||||
|
||||
public Application[] Apps { get; set; }
|
||||
@@ -40,24 +40,17 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
|
||||
public UWP(Package package)
|
||||
{
|
||||
Location = package.InstalledLocation.Path;
|
||||
|
||||
Name = package.Id.Name;
|
||||
FullName = package.Id.FullName;
|
||||
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();
|
||||
var path = Path.Combine(Location, "AppxManifest.xml");
|
||||
var path = Path.Combine(installedLocation, "AppxManifest.xml");
|
||||
|
||||
var namespaces = XmlNamespaces(path);
|
||||
InitPackageVersion(namespaces);
|
||||
@@ -154,21 +147,14 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
try
|
||||
{
|
||||
u = new UWP(p);
|
||||
u.InitializeAppInfo(p.InstalledLocation.Path);
|
||||
}
|
||||
#if !DEBUG
|
||||
catch (Exception e)
|
||||
{
|
||||
ProgramLogger.LogException($"|UWP|All|{p.InstalledLocation}|An unexpected error occurred and "
|
||||
+ $"unable to convert Package to UWP for {p.Id.FullName}", e);
|
||||
return new Application[] { };
|
||||
}
|
||||
#endif
|
||||
#if DEBUG //make developer aware and implement handling
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
return u.Apps;
|
||||
}).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
|
||||
}
|
||||
));
|
||||
|
||||
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)
|
||||
@@ -88,11 +74,6 @@ namespace Microsoft.Plugin.Program.Views.Commands
|
||||
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
||||
.ToList()
|
||||
.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)
|
||||
@@ -133,7 +114,7 @@ namespace Microsoft.Plugin.Program.Views.Commands
|
||||
|
||||
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)
|
||||
return true;
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ namespace Microsoft.Plugin.Program.Views
|
||||
Task.Run(() =>
|
||||
{
|
||||
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Visible; });
|
||||
Main.IndexPrograms();
|
||||
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Hidden; });
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user