From d0e4dabe90605138585c62fb05bb35a17a4cb7da Mon Sep 17 00:00:00 2001 From: Alekhya Date: Fri, 5 Jun 2020 15:05:00 -0700 Subject: [PATCH] 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 --- .../Microsoft.Plugin.Program/Programs/UWP.cs | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWP.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWP.cs index bd288cb9c9..9057e0a978 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWP.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWP.cs @@ -20,8 +20,8 @@ using Wox.Plugin; using System.Windows.Input; using System.Runtime.InteropServices.ComTypes; using Wox.Plugin.SharedCommands; -using System.Reflection; - +using System.Reflection; + namespace Microsoft.Plugin.Program.Programs { [Serializable] @@ -542,6 +542,10 @@ namespace Microsoft.Plugin.Program.Programs var prefix = path.Substring(0, end); var paths = new List { 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> { // 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]) { 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 { - ProgramLogger.LogException($"|UWP|LogoPathFromUri|{Package.Location}" + - $"|{UserModelId} can't find logo uri for {uri} in package location: {Package.Location}", new FileNotFoundException()); - return string.Empty; + int appIconSize = 36; + var targetSizes = new List{16, 24, 30, 36, 44, 60, 72, 96, 128, 180, 256}.AsParallel(); + Dictionary pathFactorPairs = new Dictionary(); + + 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 @@ -579,7 +612,6 @@ namespace Microsoft.Plugin.Program.Programs } } - public ImageSource Logo() { var logo = ImageFromPath(LogoPath);