diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index d5ae1ea7f70f..70977c5f562d 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -45,6 +45,9 @@ public class GeneratePackageAppxManifest_v0 : Task public override bool Execute() { +#if DEBUG_RESIZETIZER + System.Diagnostics.Debugger.Launch(); +#endif try { Directory.CreateDirectory(IntermediateOutputPath); @@ -143,7 +146,9 @@ void UpdateManifest(XDocument appx) var xname = xmlns + "DisplayName"; var xelem = properties.Element(xname); if (xelem == null || string.IsNullOrEmpty(xelem.Value) || xelem.Value == DefaultPlaceholder) + { properties.SetElementValue(xname, ApplicationTitle); + } } // @@ -208,7 +213,9 @@ void UpdateManifest(XDocument appx) var xname = "DisplayName"; var attr = visual.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == DefaultPlaceholder) + { visual.SetAttributeValue(xname, ApplicationTitle); + } } // Description="" @@ -216,7 +223,9 @@ void UpdateManifest(XDocument appx) var xname = "Description"; var attr = visual.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == DefaultPlaceholder) + { visual.SetAttributeValue(xname, ApplicationTitle); + } } } @@ -224,8 +233,18 @@ void UpdateManifest(XDocument appx) { var xname = "BackgroundColor"; var attr = visual.Attribute(xname); - if (attr == null || string.IsNullOrEmpty(attr.Value)) - visual.SetAttributeValue(xname, "transparent"); + + if (attr is null || string.IsNullOrEmpty(attr.Value)) + { + if (splashInfo?.Color is not null) + { + visual.SetAttributeValue(xname, Utils.SkiaColorWithoutAlpha(splashInfo.Color)); + } + else + { + visual.SetAttributeValue(xname, "transparent"); + } + } } if (appIconInfo != null) @@ -309,7 +328,9 @@ void UpdateManifest(XDocument appx) var xname = "ShortName"; var attr = tile.Attribute(xname); if (attr == null || string.IsNullOrEmpty(attr.Value)) + { tile.SetAttributeValue(xname, ApplicationTitle); + } } // @@ -325,9 +346,14 @@ void UpdateManifest(XDocument appx) var xshowon = xmlnsUap + "ShowOn"; var showons = showname.Elements(xshowon).ToArray(); if (showons.All(x => x.Attribute("Tile")?.Value != "square150x150Logo")) + { showname.Add(new XElement(xshowon, new XAttribute("Tile", "square150x150Logo"))); + } + if (showons.All(x => x.Attribute("Tile")?.Value != "wide310x150Logo")) + { showname.Add(new XElement(xshowon, new XAttribute("Tile", "wide310x150Logo"))); + } if (splashInfo != null) { diff --git a/src/Resizetizer/src/GenerateWasmSplashAssets.cs b/src/Resizetizer/src/GenerateWasmSplashAssets.cs index 34570f514770..a213c794e511 100644 --- a/src/Resizetizer/src/GenerateWasmSplashAssets.cs +++ b/src/Resizetizer/src/GenerateWasmSplashAssets.cs @@ -118,19 +118,7 @@ static Dictionary FindWhatINeed(string fileToProcess) static string ProcessSplashScreenColor(ResizeImageInfo info) { - var color = ColorWithoutAlpha(info.Color); + var color = Utils.SkiaColorWithoutAlpha(info.Color); return $"\"{color}\""; } - - // Wasm doesn't support alpha - static string ColorWithoutAlpha(SKColor? color) - { - var result = color?.ToString() ?? "transparent"; - if (!result.StartsWith("#")) - return result; - - // Getting everything after '#ff' - result = result.Substring(3); - return "#" + result; - } } diff --git a/src/Resizetizer/src/Utils.cs b/src/Resizetizer/src/Utils.cs index 756580f6fba9..84f208a46585 100644 --- a/src/Resizetizer/src/Utils.cs +++ b/src/Resizetizer/src/Utils.cs @@ -91,6 +91,15 @@ public static ResizedImageInfo GenerateIcoFile(string intermediateOutputPath, IL return new ResizedImageInfo { Dpi = dpi, Filename = destination }; } + public static string SkiaColorWithoutAlpha(SKColor? skColor) + { + var result = skColor?.ToString() ?? "transparent"; + if (!result.StartsWith("#")) + return result; + // Getting everything after '#ff' + result = result.Substring(3); + return "#" + result; + } } } diff --git a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs index e97e7d4ff070..513d27b8c094 100644 --- a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs +++ b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs @@ -78,11 +78,45 @@ public void ManifestTakesPriority() Assert.Equal(expectedDoc.ToString(), outputDoc.ToString()); } - [Theory] - [InlineData("typical", "typical")] - [InlineData("empty", "typical")] - public void CorrectGeneration(string input, string expected) + [Fact] + public void CorrectGenerationWhenUserSpecifyBackgroundColor() + { + var input = "empty"; + var expected = "typicalWithNoBackground"; + var appIcon = new TaskItem("images/appicon.svg"); + appIcon.SetMetadata("ForegroundFile", "images/appiconfg.svg"); + appIcon.SetMetadata("IsAppIcon", "true"); + + var splashScreen = new TaskItem("images/dotnet_bot.svg"); + splashScreen.SetMetadata("Color", "#FFFFFF"); + + var inputFilename = $"testdata/appxmanifest/{input}.appxmanifest"; + var task = GetNewTask(inputFilename, + guid: "f9e4fa3e-3505-4742-9b2b-d1acdaff4ec8", + displayVersion: "1.0.0", + version: "1", + displayName: "Sample App", + appIcon: appIcon, + splashScreen: splashScreen); + + var success = task.Execute(); + Assert.True(success, $"{task.GetType()}.Execute() failed: " + LogErrorEvents.FirstOrDefault()?.Message); + + var outputFilename = Path.Combine(DestinationDirectory, "Package.appxmanifest"); + var expectedFilename = $"testdata/appxmanifest/{expected}.appxmanifest"; + + var outputDoc = XDocument.Load(outputFilename); + var expectedDoc = XDocument.Load(expectedFilename); + + if (!XNode.DeepEquals(outputDoc, expectedDoc)) + Assert.Equal(expectedDoc.ToString(), outputDoc.ToString()); + } + + [Fact] + public void CorrectGenerationWhitOutBackgroundColor() { + var input = "typical"; + var expected = "typical"; var appIcon = new TaskItem("images/appicon.svg"); appIcon.SetMetadata("ForegroundFile", "images/appiconfg.svg"); appIcon.SetMetadata("IsAppIcon", "true"); diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/typicalWithNoBackground.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/typicalWithNoBackground.appxmanifest new file mode 100644 index 000000000000..42681d519fe6 --- /dev/null +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/typicalWithNoBackground.appxmanifest @@ -0,0 +1,36 @@ + + + + + .NET Foundation + Sample App + Images/appiconStoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file