mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Rename the [Ee]xts dir to ext (#38852)
**WARNING:** This PR will probably blow up all in-flight PRs at some point in the early days of CmdPal, two of us created seperate `Exts` and `exts` dirs. Depending on what the casing was on the branch that you checked one of those out from, it'd get stuck like that on your PC forever. Windows didn't care, so we never noticed. But GitHub does care, and now browsing the source on GitHub is basically impossible. Closes #38081
This commit is contained in:
90
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppCache.cs
Normal file
90
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppCache.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CmdPal.Ext.Apps.Programs;
|
||||
using Microsoft.CmdPal.Ext.Apps.Storage;
|
||||
using Microsoft.CmdPal.Ext.Apps.Utils;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Apps;
|
||||
|
||||
public sealed class AppCache : IDisposable
|
||||
{
|
||||
private Win32ProgramFileSystemWatchers _win32ProgramRepositoryHelper;
|
||||
|
||||
private PackageRepository _packageRepository;
|
||||
|
||||
private Win32ProgramRepository _win32ProgramRepository;
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
public IList<Win32Program> Win32s => _win32ProgramRepository.Items;
|
||||
|
||||
public IList<UWPApplication> UWPs => _packageRepository.Items;
|
||||
|
||||
public static readonly Lazy<AppCache> Instance = new(() => new());
|
||||
|
||||
public AppCache()
|
||||
{
|
||||
_win32ProgramRepositoryHelper = new Win32ProgramFileSystemWatchers();
|
||||
_win32ProgramRepository = new Win32ProgramRepository(_win32ProgramRepositoryHelper.FileSystemWatchers.Cast<IFileSystemWatcherWrapper>().ToList(), AllAppsSettings.Instance, _win32ProgramRepositoryHelper.PathsToWatch);
|
||||
|
||||
_packageRepository = new PackageRepository(new PackageCatalogWrapper());
|
||||
|
||||
var a = Task.Run(() =>
|
||||
{
|
||||
_win32ProgramRepository.IndexPrograms();
|
||||
});
|
||||
|
||||
var b = Task.Run(() =>
|
||||
{
|
||||
_packageRepository.IndexPrograms();
|
||||
UpdateUWPIconPath(ThemeHelper.GetCurrentTheme());
|
||||
});
|
||||
|
||||
Task.WaitAll(a, b);
|
||||
|
||||
AllAppsSettings.Instance.LastIndexTime = DateTime.Today;
|
||||
}
|
||||
|
||||
private void UpdateUWPIconPath(Theme theme)
|
||||
{
|
||||
if (_packageRepository != null)
|
||||
{
|
||||
foreach (UWPApplication app in _packageRepository)
|
||||
{
|
||||
app.UpdateLogoPath(theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShouldReload() => _packageRepository.ShouldReload() || _win32ProgramRepository.ShouldReload();
|
||||
|
||||
public void ResetReloadFlag()
|
||||
{
|
||||
_packageRepository.ResetReloadFlag();
|
||||
_win32ProgramRepository.ResetReloadFlag();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_win32ProgramRepositoryHelper?.Dispose();
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user