Skip to content

Commit f806c23

Browse files
Fix UWP icon missing issue
1 parent d646380 commit f806c23

File tree

1 file changed

+72
-53
lines changed
  • Plugins/Flow.Launcher.Plugin.Program/Programs

1 file changed

+72
-53
lines changed

Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs

Lines changed: 72 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -601,75 +601,94 @@ internal string LogoPathFromUri(string uri)
601601
// windows 8.1 https://msdn.microsoft.com/en-us/library/windows/apps/hh965372.aspx#target_size
602602
// windows 8 https://msdn.microsoft.com/en-us/library/windows/apps/br211475.aspx
603603

604-
string path;
605-
if (uri.Contains("\\"))
606-
{
607-
path = Path.Combine(Package.Location, uri);
608-
}
609-
else
610-
{
611-
// for C:\Windows\MiracastView etc
612-
path = Path.Combine(Package.Location, "Assets", uri);
613-
}
604+
string path = Path.Combine(Package.Location, uri);
605+
606+
// TODO: NOT sure why we needed this? Maybe for Windows 8?
607+
//if (uri.Contains("\\"))
608+
//{
609+
// path = Path.Combine(Package.Location, uri);
610+
//}
611+
//else
612+
//{
613+
// // for C:\Windows\MiracastView etc
614+
// path = Path.Combine(Package.Location, "Assets", uri);
615+
//}
614616

615617
var extension = Path.GetExtension(path);
616618
if (extension != null)
617619
{
618-
var end = path.Length - extension.Length;
619-
var prefix = path.Substring(0, end);
620-
var paths = new List<string>
621-
{
622-
path
623-
};
624-
625-
var scaleFactors = new Dictionary<PackageVersion, List<int>>
620+
if (File.Exists(path))
626621
{
627-
// scale factors on win10: https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets#asset-size-tables,
628-
{
629-
PackageVersion.Windows10, new List<int>
630-
{
631-
100,
632-
125,
633-
150,
634-
200,
635-
400
636-
}
637-
},
638-
{
639-
PackageVersion.Windows81, new List<int>
640-
{
641-
100,
642-
120,
643-
140,
644-
160,
645-
180
646-
}
647-
},
648-
{
649-
PackageVersion.Windows8, new List<int>
650-
{
651-
100
652-
}
653-
}
654-
};
622+
return path; // shortcut, avoid enumerating files
623+
}
655624

656-
if (scaleFactors.ContainsKey(Package.Version))
625+
var logoNamePrefix = Path.GetFileNameWithoutExtension(uri); // e.g Square44x44
626+
var logoDir = Path.GetDirectoryName(path); // e.g ..\..\Assets
627+
if (String.IsNullOrEmpty(logoNamePrefix) || String.IsNullOrEmpty(logoDir) || !Directory.Exists(logoDir))
657628
{
658-
foreach (var factor in scaleFactors[Package.Version])
659-
{
660-
paths.Add($"{prefix}.scale-{factor}{extension}");
661-
}
629+
// Known issue: Edge always triggers it since logo is not at uri
630+
ProgramLogger.LogException($"|UWP|LogoPathFromUri|{Package.Location}" +
631+
$"|{UserModelId} can't find logo uri for {uri} in package location (logo name or directory not found): {Package.Location}", new FileNotFoundException());
632+
return string.Empty;
662633
}
663634

664-
var selected = paths.FirstOrDefault(File.Exists);
635+
var files = Directory.EnumerateFiles(logoDir);
636+
637+
// Just ignore all qulifiers
638+
// select like logo[xxx].png
639+
// https://learn.microsoft.com/en-us/windows/uwp/app-resources/tailor-resources-lang-scale-contrast
640+
var selected = files.FirstOrDefault(file =>
641+
Path.GetFileName(file).StartsWith(logoNamePrefix) && extension == Path.GetExtension(file)
642+
);
643+
644+
//var scaleFactors = new Dictionary<PackageVersion, List<int>>
645+
//{
646+
// // scale factors on win10: https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets#asset-size-tables,
647+
// {
648+
// PackageVersion.Windows10, new List<int>
649+
// {
650+
// 100,
651+
// 125,
652+
// 150,
653+
// 200,
654+
// 400
655+
// }
656+
// },
657+
// {
658+
// PackageVersion.Windows81, new List<int>
659+
// {
660+
// 100,
661+
// 120,
662+
// 140,
663+
// 160,
664+
// 180
665+
// }
666+
// },
667+
// {
668+
// PackageVersion.Windows8, new List<int>
669+
// {
670+
// 100
671+
// }
672+
// }
673+
//};
674+
675+
//if (scaleFactors.ContainsKey(Package.Version))
676+
//{
677+
// foreach (var factor in scaleFactors[Package.Version])
678+
// {
679+
// // https://learn.microsoft.com/en-us/windows/uwp/app-resources/tailor-resources-lang-scale-contrast
680+
// suffixes.Add($"scale-{factor}{extension}"); // MS don't require scale as the last
681+
// }
682+
//}
683+
665684
if (!string.IsNullOrEmpty(selected))
666685
{
667686
return selected;
668687
}
669688
else
670689
{
671690
ProgramLogger.LogException($"|UWP|LogoPathFromUri|{Package.Location}" +
672-
$"|{UserModelId} can't find logo uri for {uri} in package location: {Package.Location}", new FileNotFoundException());
691+
$"|{UserModelId} can't find logo uri for {uri} in package location (can't find specified logo): {Package.Location}", new FileNotFoundException());
673692
return string.Empty;
674693
}
675694
}

0 commit comments

Comments
 (0)