Repository navigation
feat: show the launchers' official logos on the console Home tiles #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b38f719
feat: show the launchers' official logos on the console Home tiles
lippdev 359bf5c
docs: changelog for the official launcher logos
lippdev 2a52534
fix: keep a stale launcher logo from replacing the current one
lippdev 1745994
Merge remote-tracking branch 'origin/main' into feat/official-launche…
lippdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| using System.Xml.Linq; | ||
| using ConsoleMode.Services; | ||
|
|
||
| namespace ConsoleMode.Native; | ||
|
|
||
| /// <summary>The app-list logo file of an installed Store app, at the biggest size it ships.</summary> | ||
| internal static class PackageLogos | ||
| { | ||
| /// <summary>Never throws: null when the app isn't installed or its logo can't be found.</summary> | ||
| public static string? Find(string appUserModelId) | ||
| { | ||
| try | ||
| { | ||
| var parts = appUserModelId.Split('!', 2); | ||
| if (parts.Length != 2) return null; | ||
| var package = new Windows.Management.Deployment.PackageManager() | ||
| .FindPackagesForUser(string.Empty, parts[0]).FirstOrDefault(); | ||
| var folder = package?.InstalledLocation?.Path; | ||
| if (string.IsNullOrWhiteSpace(folder)) return null; | ||
|
|
||
| var manifest = XDocument.Load(Path.Combine(folder, "AppxManifest.xml")); | ||
| var app = manifest.Descendants().FirstOrDefault(e => e.Name.LocalName == "Application" && (string?)e.Attribute("Id") == parts[1]); | ||
| var visuals = app?.Descendants().FirstOrDefault(e => e.Name.LocalName == "VisualElements"); | ||
| var logo = (string?)visuals?.Attribute("Square44x44Logo") ?? (string?)visuals?.Attribute("Square150x150Logo"); | ||
| if (string.IsNullOrWhiteSpace(logo)) return null; | ||
|
|
||
| var logoFolder = Path.Combine(folder, Path.GetDirectoryName(logo) ?? ""); | ||
| return Directory.Exists(logoFolder) | ||
| ? PackageLogo.Pick(logo, Directory.EnumerateFiles(logoFolder, Path.GetFileNameWithoutExtension(logo) + "*")) | ||
| : null; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| AppLog.Write($"Início: logo de {appUserModelId}: {ex.Message}"); | ||
| return null; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| namespace ConsoleMode.Services; | ||
|
|
||
| /// <summary> | ||
| /// Picks the sharpest file of a Store app's logo. The manifest names it as "Assets\Logo.png", but the | ||
| /// package holds variants such as "Logo.targetsize-256.png" or "Logo.scale-200.png"; the shell | ||
| /// only hands out the small one, which looks blurred on a TV tile. | ||
| /// </summary> | ||
| public static class PackageLogo | ||
| { | ||
| /// <summary>The best file among <paramref name="files"/> (names in the logo's folder), or null.</summary> | ||
| public static string? Pick(string manifestLogo, IEnumerable<string> files) | ||
| { | ||
| var stem = Path.GetFileNameWithoutExtension(manifestLogo); | ||
| var extension = Path.GetExtension(manifestLogo); | ||
| if (string.IsNullOrWhiteSpace(stem)) return null; | ||
|
|
||
| string? best = null; | ||
| var bestScore = int.MinValue; | ||
| foreach (var file in files) | ||
| { | ||
| var name = Path.GetFileName(file); | ||
| if (!name.StartsWith(stem, StringComparison.OrdinalIgnoreCase) | ||
| || !name.EndsWith(extension, StringComparison.OrdinalIgnoreCase)) continue; | ||
| var rest = name[stem.Length..^extension.Length]; | ||
| // "Logo2.png" is another file, not a variant of "Logo.png". | ||
| if (rest.Length > 0 && rest[0] != '.') continue; | ||
| var qualifiers = rest.TrimStart('.'); | ||
| if (Score(qualifiers) is not { } score || score <= bestScore) continue; | ||
| best = file; | ||
| bestScore = score; | ||
| } | ||
| return best; | ||
| } | ||
|
|
||
| /// <summary>Bigger wins; the unplated form beats the plated one at the same size. Contrast themes are skipped.</summary> | ||
| private static int? Score(string qualifiers) | ||
| { | ||
| if (qualifiers.Length == 0) return 0; | ||
| var size = 0; | ||
| var unplated = false; | ||
| foreach (var part in qualifiers.Split('_')) | ||
| { | ||
| if (part.StartsWith("contrast-", StringComparison.OrdinalIgnoreCase)) return null; | ||
| if (part.Equals("altform-unplated", StringComparison.OrdinalIgnoreCase)) unplated = true; | ||
| else if (part.StartsWith("altform-", StringComparison.OrdinalIgnoreCase)) return null; | ||
| else if (part.StartsWith("targetsize-", StringComparison.OrdinalIgnoreCase) && int.TryParse(part[11..], out var target)) size = target; | ||
| // scale-200 of a 44 px logo is 88 px. | ||
| else if (part.StartsWith("scale-", StringComparison.OrdinalIgnoreCase) && int.TryParse(part[6..], out var scale)) size = 44 * scale / 100; | ||
| } | ||
| return size * 2 + (unplated ? 1 : 0); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using ConsoleMode.Services; | ||
|
|
||
| namespace ConsoleMode.Tests; | ||
|
|
||
| public class PackageLogoTests | ||
| { | ||
| // The Xbox app's assets folder, trimmed. | ||
| private static readonly string[] XboxFiles = | ||
| [ | ||
| "Xbox_AppList.scale-200.png", | ||
| "Xbox_AppList.scale-200_contrast-black.png", | ||
| "Xbox_AppList.targetsize-16.png", | ||
| "Xbox_AppList.targetsize-48.png", | ||
| "Xbox_AppList.targetsize-256.png", | ||
| "Xbox_AppList.targetsize-256_altform-lightunplated.png", | ||
| "Xbox_AppList.targetsize-256_contrast-white.png", | ||
| "Xbox_MedTile.scale-200.png", | ||
| ]; | ||
|
|
||
| [Fact] | ||
| public void The_biggest_plain_logo_wins() => | ||
| Assert.Equal("Xbox_AppList.targetsize-256.png", PackageLogo.Pick(@"assets\Xbox_AppList.png", XboxFiles)); | ||
|
|
||
| [Fact] | ||
| public void The_unplated_form_beats_the_plated_one_at_the_same_size() => | ||
| Assert.Equal("Logo.targetsize-256_altform-unplated.png", | ||
| PackageLogo.Pick("Logo.png", ["Logo.targetsize-256.png", "Logo.targetsize-256_altform-unplated.png", "Logo.targetsize-48_altform-unplated.png"])); | ||
|
|
||
| [Fact] | ||
| public void Contrast_themes_are_never_picked() => | ||
| Assert.Null(PackageLogo.Pick("Logo.png", ["Logo.targetsize-256_contrast-black.png", "Logo.scale-400_contrast-white.png"])); | ||
|
|
||
| [Fact] | ||
| public void Scaled_logos_count_by_their_scale() => | ||
| Assert.Equal("Logo.scale-400.png", PackageLogo.Pick("Logo.png", ["Logo.scale-100.png", "Logo.scale-400.png", "Logo.scale-200.png"])); | ||
|
|
||
| [Fact] | ||
| public void A_logo_without_variants_is_used_as_is() => | ||
| Assert.Equal("StoreLogo.png", PackageLogo.Pick(@"Assets\StoreLogo.png", ["StoreLogo.png", "Other.png"])); | ||
|
|
||
| [Fact] | ||
| public void Other_logos_and_extensions_are_ignored() => | ||
| Assert.Null(PackageLogo.Pick("Logo.png", ["Logo.targetsize-256.jpg", "Logo2.png", "Splash.png"])); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.