mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-23 23:20:05 +01:00
corrections in the snippet tool.
extending icon handling in the editor: for packaged apps look for the exe in the current path adding shortcut icon creation.
This commit is contained in:
@@ -12,8 +12,11 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media.Imaging;
|
||||
using ManagedCommon;
|
||||
using Windows.ApplicationModel.Core;
|
||||
using Windows.Management.Deployment;
|
||||
|
||||
namespace ProjectsEditor.Models
|
||||
{
|
||||
@@ -78,7 +81,18 @@ namespace ProjectsEditor.Models
|
||||
{
|
||||
try
|
||||
{
|
||||
_icon = Icon.ExtractAssociatedIcon(AppPath);
|
||||
if (!File.Exists(AppPath) && IsPackagedApp)
|
||||
{
|
||||
Task<AppListEntry> task = Task.Run<AppListEntry>(async () => await GetAppByPackageFamilyNameAsync());
|
||||
AppListEntry packApp = task.Result;
|
||||
string filename = Path.GetFileName(AppPath);
|
||||
string newExeLocation = Path.Combine(packApp.AppInfo.Package.InstalledPath, filename);
|
||||
_icon = Icon.ExtractAssociatedIcon(newExeLocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
_icon = Icon.ExtractAssociatedIcon(AppPath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -91,6 +105,31 @@ namespace ProjectsEditor.Models
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<AppListEntry> GetAppByPackageFamilyNameAsync()
|
||||
{
|
||||
var pkgManager = new PackageManager();
|
||||
var pkg = pkgManager.FindPackagesForUser(string.Empty, PackagedId).FirstOrDefault();
|
||||
|
||||
if (pkg == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var apps = await pkg.GetAppListEntriesAsync();
|
||||
if (apps == null || apps.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
AppListEntry firstApp = apps[0];
|
||||
|
||||
// RandomAccessStreamReference stream = firstApp.AppInfo.DisplayInfo.GetLogo(new Windows.Foundation.Size(64, 64));
|
||||
// IRandomAccessStreamWithContentType content = await stream.OpenReadAsync();
|
||||
// BitmapImage bitmapImage = new BitmapImage();
|
||||
// bitmapImage.StreamSource = (Stream)content;
|
||||
return firstApp;
|
||||
}
|
||||
|
||||
private BitmapImage _iconBitmapImage;
|
||||
|
||||
public BitmapImage IconBitmapImage
|
||||
|
||||
Reference in New Issue
Block a user