Skip to content

Commit

Permalink
Merge pull request unoplatform#85 from unoplatform/pj/add-background-…
Browse files Browse the repository at this point in the history
…on-manifest

Added background color on appxmanifest and refactoring.
  • Loading branch information
pictos authored Mar 15, 2023
2 parents b2bc204 + 9c9ae6f commit dd8a6a7
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 19 deletions.
30 changes: 28 additions & 2 deletions src/Resizetizer/src/GeneratePackageAppxManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

// <Logo>
Expand Down Expand Up @@ -208,24 +213,38 @@ 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=""
{
var xname = "Description";
var attr = visual.Attribute(xname);
if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == DefaultPlaceholder)
{
visual.SetAttributeValue(xname, ApplicationTitle);
}
}
}

// BackgroundColor=""
{
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)
Expand Down Expand Up @@ -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);
}
}

// <uap:ShowNameOnTiles>
Expand All @@ -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)
{
Expand Down
14 changes: 1 addition & 13 deletions src/Resizetizer/src/GenerateWasmSplashAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,7 @@ static Dictionary<string, string> 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;
}
}
9 changes: 9 additions & 0 deletions src/Resizetizer/src/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
42 changes: 38 additions & 4 deletions src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">
<Identity Publisher="CN=.NET Foundation" Name="f9e4fa3e-3505-4742-9b2b-d1acdaff4ec8" Version="1.0.0.1" />
<Properties>
<PublisherDisplayName>.NET Foundation</PublisherDisplayName>
<DisplayName>Sample App</DisplayName>
<Logo>Images/appiconStoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements DisplayName="Sample App" Description="Sample App" BackgroundColor="#ffffff" Square150x150Logo="Images/appiconMediumTile.png" Square44x44Logo="Images/appiconLogo.png">
<uap:DefaultTile Wide310x150Logo="Images/appiconWideTile.png" Square71x71Logo="Images/appiconSmallTile.png" Square310x310Logo="Images/appiconLargeTile.png" ShortName="Sample App">
<uap:ShowNameOnTiles>
<uap:ShowOn Tile="square150x150Logo" />
<uap:ShowOn Tile="wide310x150Logo" />
</uap:ShowNameOnTiles>
</uap:DefaultTile>
<uap:SplashScreen Image="dotnet_botSplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<rescap:Capability Name="runFullTrust" />
<DeviceCapability Name="location" />
</Capabilities>
</Package>

0 comments on commit dd8a6a7

Please sign in to comment.