Skip to content

Commit d533c5e

Browse files
Try to find in Assets\ if logo doesn't exist
1 parent f806c23 commit d533c5e

File tree

1 file changed

+90
-87
lines changed
  • Plugins/Flow.Launcher.Plugin.Program/Programs

1 file changed

+90
-87
lines changed

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

Lines changed: 90 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -603,109 +603,112 @@ internal string LogoPathFromUri(string uri)
603603

604604
string path = Path.Combine(Package.Location, uri);
605605

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-
//}
616-
617-
var extension = Path.GetExtension(path);
618-
if (extension != null)
619-
{
620-
if (File.Exists(path))
621-
{
622-
return path; // shortcut, avoid enumerating files
623-
}
606+
var logoPath = TryToFindLogo(uri, path);
607+
if (String.IsNullOrEmpty(logoPath))
608+
{
609+
// TODO: Don't know why, just keep it at the moment
610+
// Maybe on older version of Windows 10?
611+
// for C:\Windows\MiracastView etc
612+
return TryToFindLogo(uri, Path.Combine(Package.Location, "Assets", uri));
613+
}
614+
return logoPath;
624615

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))
616+
string TryToFindLogo(string uri, string path)
617+
{
618+
var extension = Path.GetExtension(path);
619+
if (extension != null)
628620
{
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;
633-
}
621+
if (File.Exists(path))
622+
{
623+
return path; // shortcut, avoid enumerating files
624+
}
634625

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-
684-
if (!string.IsNullOrEmpty(selected))
685-
{
686-
return selected;
626+
var logoNamePrefix = Path.GetFileNameWithoutExtension(uri); // e.g Square44x44
627+
var logoDir = Path.GetDirectoryName(path); // e.g ..\..\Assets
628+
if (String.IsNullOrEmpty(logoNamePrefix) || String.IsNullOrEmpty(logoDir) || !Directory.Exists(logoDir))
629+
{
630+
// Known issue: Edge always triggers it since logo is not at uri
631+
ProgramLogger.LogException($"|UWP|LogoPathFromUri|{Package.Location}" +
632+
$"|{UserModelId} can't find logo uri for {uri} in package location (logo name or directory not found): {Package.Location}", new FileNotFoundException());
633+
return string.Empty;
634+
}
635+
636+
var files = Directory.EnumerateFiles(logoDir);
637+
638+
// Currently we don't care which one to choose
639+
// Just ignore all qualifiers
640+
// select like logo.[xxx_yyy].png
641+
// https://learn.microsoft.com/en-us/windows/uwp/app-resources/tailor-resources-lang-scale-contrast
642+
var selected = files.FirstOrDefault(file =>
643+
Path.GetFileName(file).StartsWith(logoNamePrefix) && extension == Path.GetExtension(file)
644+
);
645+
646+
//var scaleFactors = new Dictionary<PackageVersion, List<int>>
647+
//{
648+
// // scale factors on win10: https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets#asset-size-tables,
649+
// {
650+
// PackageVersion.Windows10, new List<int>
651+
// {
652+
// 100,
653+
// 125,
654+
// 150,
655+
// 200,
656+
// 400
657+
// }
658+
// },
659+
// {
660+
// PackageVersion.Windows81, new List<int>
661+
// {
662+
// 100,
663+
// 120,
664+
// 140,
665+
// 160,
666+
// 180
667+
// }
668+
// },
669+
// {
670+
// PackageVersion.Windows8, new List<int>
671+
// {
672+
// 100
673+
// }
674+
// }
675+
//};
676+
677+
//if (scaleFactors.ContainsKey(Package.Version))
678+
//{
679+
// foreach (var factor in scaleFactors[Package.Version])
680+
// {
681+
// // https://learn.microsoft.com/en-us/windows/uwp/app-resources/tailor-resources-lang-scale-contrast
682+
// suffixes.Add($"scale-{factor}{extension}"); // MS don't require scale as the last
683+
// }
684+
//}
685+
686+
if (!string.IsNullOrEmpty(selected))
687+
{
688+
return selected;
689+
}
690+
else
691+
{
692+
ProgramLogger.LogException($"|UWP|LogoPathFromUri|{Package.Location}" +
693+
$"|{UserModelId} can't find logo uri for {uri} in package location (can't find specified logo): {Package.Location}", new FileNotFoundException());
694+
return string.Empty;
695+
}
687696
}
688697
else
689698
{
690699
ProgramLogger.LogException($"|UWP|LogoPathFromUri|{Package.Location}" +
691-
$"|{UserModelId} can't find logo uri for {uri} in package location (can't find specified logo): {Package.Location}", new FileNotFoundException());
700+
$"|Unable to find extension from {uri} for {UserModelId} " +
701+
$"in package location {Package.Location}", new FileNotFoundException());
692702
return string.Empty;
693703
}
694704
}
695-
else
696-
{
697-
ProgramLogger.LogException($"|UWP|LogoPathFromUri|{Package.Location}" +
698-
$"|Unable to find extension from {uri} for {UserModelId} " +
699-
$"in package location {Package.Location}", new FileNotFoundException());
700-
return string.Empty;
701-
}
702705
}
703706

704707

705708
public ImageSource Logo()
706709
{
707710
var logo = ImageFromPath(LogoPath);
708-
var plated = PlatedImage(logo);
711+
var plated = PlatedImage(logo); // TODO: maybe get plated directly from app package?
709712

710713
// todo magic! temp fix for cross thread object
711714
plated.Freeze();

0 commit comments

Comments
 (0)