mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
Fix for UWP icons not showing up (#4008)
* Added fix for UWP icons not showing up * updated comment and reversed the list of target sizes * find the icon closest in size to the appIcon size * Remove nlog reference that was added by mistake
This commit is contained in:
parent
a3c569137e
commit
d0e4dabe90
@ -20,8 +20,8 @@ using Wox.Plugin;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Runtime.InteropServices.ComTypes;
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
using Wox.Plugin.SharedCommands;
|
using Wox.Plugin.SharedCommands;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Microsoft.Plugin.Program.Programs
|
namespace Microsoft.Plugin.Program.Programs
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@ -542,6 +542,10 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
var prefix = path.Substring(0, end);
|
var prefix = path.Substring(0, end);
|
||||||
var paths = new List<string> { path };
|
var paths = new List<string> { path };
|
||||||
|
|
||||||
|
// TODO: This value must be set in accordance to the WPF theme (work in progress).
|
||||||
|
// Must be set to `contrast-white` for light theme and to `contrast-black` for dark theme to get an icon of the contrasting color.
|
||||||
|
var theme = "contrast-black";
|
||||||
|
|
||||||
var scaleFactors = new Dictionary<PackageVersion, List<int>>
|
var scaleFactors = new Dictionary<PackageVersion, List<int>>
|
||||||
{
|
{
|
||||||
// scale factors on win10: https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets#asset-size-tables,
|
// scale factors on win10: https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets#asset-size-tables,
|
||||||
@ -555,6 +559,8 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
foreach (var factor in scaleFactors[Package.Version])
|
foreach (var factor in scaleFactors[Package.Version])
|
||||||
{
|
{
|
||||||
paths.Add($"{prefix}.scale-{factor}{extension}");
|
paths.Add($"{prefix}.scale-{factor}{extension}");
|
||||||
|
paths.Add($"{prefix}.scale-{factor}_{theme}{extension}");
|
||||||
|
paths.Add($"{prefix}.{theme}_scale-{factor}{extension}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,9 +571,36 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException($"|UWP|LogoPathFromUri|{Package.Location}" +
|
int appIconSize = 36;
|
||||||
$"|{UserModelId} can't find logo uri for {uri} in package location: {Package.Location}", new FileNotFoundException());
|
var targetSizes = new List<int>{16, 24, 30, 36, 44, 60, 72, 96, 128, 180, 256}.AsParallel();
|
||||||
return string.Empty;
|
Dictionary<string, int> pathFactorPairs = new Dictionary<string, int>();
|
||||||
|
|
||||||
|
foreach (var factor in targetSizes)
|
||||||
|
{
|
||||||
|
string simplePath = $"{prefix}.targetsize-{factor}{extension}";
|
||||||
|
string suffixThemePath = $"{prefix}.targetsize-{factor}_{theme}{extension}";
|
||||||
|
string prefixThemePath = $"{prefix}.{theme}_targetsize-{factor}{extension}";
|
||||||
|
|
||||||
|
paths.Add(simplePath);
|
||||||
|
paths.Add(suffixThemePath);
|
||||||
|
paths.Add(prefixThemePath);
|
||||||
|
|
||||||
|
pathFactorPairs.Add(simplePath, factor);
|
||||||
|
pathFactorPairs.Add(suffixThemePath, factor);
|
||||||
|
pathFactorPairs.Add(prefixThemePath, factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectedIconPath = paths.OrderBy(x => Math.Abs(pathFactorPairs.GetValueOrDefault(x) - appIconSize)).FirstOrDefault(File.Exists);
|
||||||
|
if (!string.IsNullOrEmpty(selectedIconPath))
|
||||||
|
{
|
||||||
|
return selectedIconPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProgramLogger.LogException($"|UWP|LogoPathFromUri|{Package.Location}" +
|
||||||
|
$"|{UserModelId} can't find logo uri for {uri} in package location: {Package.Location}", new FileNotFoundException());
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -579,7 +612,6 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ImageSource Logo()
|
public ImageSource Logo()
|
||||||
{
|
{
|
||||||
var logo = ImageFromPath(LogoPath);
|
var logo = ImageFromPath(LogoPath);
|
||||||
|
Loading…
Reference in New Issue
Block a user