Skip to content

Commit

Permalink
Merge pull request unoplatform#163 from unoplatform/pj/windows-appico…
Browse files Browse the repository at this point in the history
…n-path

Make Uno.Resizetizer respects windows appicon path
  • Loading branch information
pictos authored Sep 22, 2023
2 parents 7a24b3d + 5d52110 commit de9cc13
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 44 deletions.
2 changes: 1 addition & 1 deletion doc/uno-resizetizer-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Properties that can be used across all items
| Link | Used to specify a custom path for your image, this path should be used inside your application when you want to reference the image |
| Resize | Boolean value to say if the asset should Resized or not. By default just vectors asset are resized by default |
| TintColor | Color that will be used to tint the image during the resize phase. You can use a Hex value or a named value like `Fuchsia` |
| Color | Color that will be used as a background color |
| Color | Color that will be used as a background color |

## UnoIcon

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0-ios;net7.0-android;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<SingleProject>true</SingleProject>
<OutputType>Exe</OutputType>
<!-- Display name -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
Expand Down Expand Up @@ -77,7 +77,7 @@
<_ResizetizerManifestPath>$(_UnoIntermediateManifest)Package.appxmanifest</_ResizetizerManifestPath>
<_ResizetizerSplashScreenPath>$(_UnoIntermediateSplashScreen)splash_screen.scale-150.png</_ResizetizerSplashScreenPath>
<_ResizetizerAppIconPath>$(_UnoIntermediateImages)iconapp.ico</_ResizetizerAppIconPath>
<_ResizetizerAppIconImagesPath>$(_UnoIntermediateImages)Images\iconappLogo.scale-150.png</_ResizetizerAppIconImagesPath>
<_ResizetizerAppIconImagesPath>$(_UnoIntermediateImages)Icons\iconappLogo.scale-150.png</_ResizetizerAppIconImagesPath>
</PropertyGroup>
<Message Text="Validating local assets at '$(_ResizetizerIntermediateOutputRoot)'" Importance="high" />
<Error Condition="!Exists('$(_ResizetizerManifestPath)')" Text="Manifest file wasn't created." />
Expand Down
51 changes: 31 additions & 20 deletions src/.nuspec/Uno.Resizetizer.targets
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,35 @@
<_WindowIconExtension Include="$(_UnoResizetizerIntermediateOutputRoot)Uno.Resizetizer.WindowIconExtensions.g.cs"/>
</ItemGroup>


<Target Name="ValidateAvailableItems"
BeforeTargets="UnoResizetizeCollectItems">

<Warning
Condition="'%(UnoIcon.Link)' != ''"
Text="The UnoIcon.Link property will be ignored."/>

<Warning
Condition="'@(UnoIcon->Count())' &gt; '1'"
Text="More than one 'UnoIcon' is defined; only the first will be used." />

<Warning
Condition="'@(UnoSplashScreen->Count())' &gt; '1'"
Text="More than one 'UnoSplashScreen' is defined; only the first will be used." />

<Warning
Condition="'%(UnoSplashScreen.Link)' != ''"
Text="The UnoSplashScreen.Link property will be ignored."/>

<Error
Condition="'@(UnoSplashScreen)' == '@(UnoIcon)'"
Text="The value of UnoSplashScreen and UnoIcon cannot be the same."/>

<Error
Condition="'@(UnoSplashScreen)' == '%(UnoIcon.ForegroundFile)'"
Text="The value of UnoSplashScreen and UnoIcon.ForegroundFile cannot be the same."/>
</Target>

<!-- Finds absolute paths to any UnoImage in this project -->
<!-- App head projects will invoke this target on their project references to collect images -->
<Target Name="GetUnoItems" Outputs="@(ExportedUnoItem)">
Expand Down Expand Up @@ -312,12 +341,10 @@
<UnoImage Update="@(UnoImage)" Resize="False" Condition="'%(UnoImage.Extension)' == '.gif' and '%(UnoImage.Resize)' == ''"/>
</ItemGroup>

<Warning Condition="'%(UnoIcon.Link)' != ''"
Text="The UnoIcon.Link property will be ignored."/>

<!-- Map @(UnoIcon) to @(UnoImage IsAppIcon=true) -->
<ItemGroup>
<UnoImage Include="@(UnoIcon)" IsAppIcon="True" Link=""/>
<UnoImage Include="@(UnoIcon)" IsAppIcon="True" Link="%(UnoIcon.Link)" />
</ItemGroup>

<!-- Write out item spec and metadata to a file we can use as an inputs for the resize target -->
Expand Down Expand Up @@ -372,23 +399,6 @@
Inputs="$(_UnoSplashInputsFile);@(UnoSplashScreen)"
Outputs="$(_UnoSplashStampFile)">

<Warning
Condition="'@(UnoSplashScreen->Count())' &gt; '1'"
Text="More than one 'UnoSplashScreen' is defined; only the first will be used."
/>

<Error
Condition="'@(UnoSplashScreen)' == '@(UnoIcon)'"
Text="The value of UnoSplashScreen and UnoIcon cannot be the same."/>

<Error
Condition="'@(UnoSplashScreen)' == '%(UnoIcon.ForegroundFile)'"
Text="The value of UnoSplashScreen and UnoIcon cannot be the same."/>

<Warning Condition="'%(UnoSplashScreen.Link)' != ''"
Text="The UnoSplashScreen.Link property will be ignored."/>


<!--If not Windows-->
<ItemGroup Condition="$(_UnoResizetizerIsWasmApp) == 'True' Or $(_UnoResizetizerIsSkiaApp) == 'True' or '$(_UnoResizetizerIsAndroidApp)' == 'True' or ('$(_UnoResizetizerIsiOSApp)' == 'True' and '$(TargetPlatformIdentifier)' != 'maccatalyst')">
<UnoImage Include="@(UnoSplashScreen)" IsSplashScreen="True" Link=""/>
Expand Down Expand Up @@ -423,6 +433,7 @@
IntermediateOutputIconPath="$(_UnoIntermediateAppIcon)"
PWAManifestPath="$(_WasmPwaManifestPath)"
InputsFile="$(_UnoResizetizerInputsFile);$(_UnoSplashInputsFile)"
TargetFramework="$(_UnoResizetizerPlatformIdentifier)"
Images="@(UnoImage->Distinct())">

<Output PropertyName="AppIconPath"
Expand Down
17 changes: 17 additions & 0 deletions src/.nuspec/Uno.Resizetizer.windows.skia.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
<Project>

<Target
Name="UpdatePathOfUnoIcon"
BeforeTargets="UnoResizetizeCollectItems"
DependsOnTargets="ValidateAvailableItems"
Condition="'$(_UnoResizetizerIsWindowsAppSdk)' == 'True'">

<AssignLinkMetadata Items="@(UnoIcon)">
<Output TaskParameter="OutputItems" ItemName="_UnoIconLinked"/>
</AssignLinkMetadata>

<ItemGroup>
<UnoIcon Remove="@(UnoIcon)"/>
<UnoIcon Include="@(_UnoIconLinked)"/>
</ItemGroup>
</Target>

<Target
Name="GenerateUnoSplashWindowsSkia"
AfterTargets="GenerateUnoSplashScreens"
Expand Down Expand Up @@ -65,6 +81,7 @@
ApplicationVersion="$(ApplicationVersion)"
ApplicationTitle="$(ApplicationTitle)"
AppIcon="@(UnoImage->WithMetadataValue('IsAppIcon', 'true'))"
TargetFramework="$(_UnoResizetizerPlatformIdentifier)"
SplashScreen="@(UnoSplashScreen)"/>

<!-- replace user manifest -->
Expand Down
2 changes: 1 addition & 1 deletion src/Resizetizer/src/DpiPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static DpiPath[] AppIcon
public static class Windows
{
public const string OutputPath = "";
public const string IconOutputPath = "Images/";
public const string IconOutputPath = "";

public static DpiPath Original =>
new DpiPath(OutputPath, 1.0m, null, ".scale-100");
Expand Down
15 changes: 9 additions & 6 deletions src/Resizetizer/src/GeneratePackageAppxManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class GeneratePackageAppxManifest_v0 : Task
[Required]
public ITaskItem AppxManifest { get; set; } = null!;

public string? TargetFramework { get; set; }

public string? GeneratedFilename { get; set; }

public string? ApplicationId { get; set; }
Expand All @@ -50,6 +52,7 @@ public override bool Execute()
#endif
try
{
ResizetizeImages_v0._TargetFramework = TargetFramework;
Directory.CreateDirectory(IntermediateOutputPath);

var filename = Path.Combine(IntermediateOutputPath, GeneratedFilename ?? "Package.appxmanifest");
Expand Down Expand Up @@ -159,7 +162,7 @@ void UpdateManifest(XDocument appx)
if (xelem == null || string.IsNullOrEmpty(xelem.Value) || xelem.Value == PngPlaceholder)
{
var dpi = DpiPath.Windows.StoreLogo[0];
var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
var path = Path.Combine(dpi.Path + appIconInfo.OutputPath, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
properties.SetElementValue(xname, path);
}
}
Expand Down Expand Up @@ -252,7 +255,7 @@ void UpdateManifest(XDocument appx)
if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PngPlaceholder)
{
var dpi = DpiPath.Windows.MediumTile[0];
var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
var path = Path.Combine(dpi.Path + appIconInfo.OutputPath, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
visual.SetAttributeValue(xname, path);
}
}
Expand All @@ -264,7 +267,7 @@ void UpdateManifest(XDocument appx)
if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PngPlaceholder)
{
var dpi = DpiPath.Windows.Logo[0];
var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
var path = Path.Combine(dpi.Path + appIconInfo.OutputPath, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
visual.SetAttributeValue(xname, path);
}
}
Expand All @@ -288,7 +291,7 @@ void UpdateManifest(XDocument appx)
if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PngPlaceholder)
{
var dpi = DpiPath.Windows.WideTile[0];
var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
var path = Path.Combine(dpi.Path + appIconInfo.OutputPath, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
tile.SetAttributeValue(xname, path);
}
}
Expand All @@ -300,7 +303,7 @@ void UpdateManifest(XDocument appx)
if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PngPlaceholder)
{
var dpi = DpiPath.Windows.SmallTile[0];
var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
var path = Path.Combine(dpi.Path + appIconInfo.OutputPath, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
tile.SetAttributeValue(xname, path);
}
}
Expand All @@ -312,7 +315,7 @@ void UpdateManifest(XDocument appx)
if (attr == null || string.IsNullOrEmpty(attr.Value) || attr.Value == PngPlaceholder)
{
var dpi = DpiPath.Windows.LargeTile[0];
var path = Path.Combine(dpi.Path, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
var path = Path.Combine(dpi.Path + appIconInfo.OutputPath, appIconInfo.OutputName + dpi.NameSuffix + imageExtension);
tile.SetAttributeValue(xname, path);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Resizetizer/src/ResizetizeImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class ResizetizeImages_v0 : UnoAsyncTask, ILogger

public string[] InputsFile { get; set; }

public string TargetFramework { get; set; }

internal static string _TargetFramework { get; set; }

internal static string TargetPlatform { get; private set; }

public ITaskItem[] Images { get; set; }
Expand Down Expand Up @@ -55,6 +59,7 @@ public override System.Threading.Tasks.Task ExecuteAsync()

#endif
TargetPlatform = PlatformType;
_TargetFramework = TargetFramework;
var images = ResizeImageInfo.Parse(Images);

var dpis = DpiPath.GetDpis();
Expand Down
19 changes: 13 additions & 6 deletions src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#nullable enable
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Xunit;

namespace Uno.Resizetizer.Tests
Expand All @@ -18,8 +19,9 @@ protected GeneratePackageAppxManifest_v0 GetNewTask(
string? version = null,
string? displayName = null,
ITaskItem? appIcon = null,
ITaskItem? splashScreen = null) =>
new()
ITaskItem? splashScreen = null)
{
return new()
{
IntermediateOutputPath = DestinationDirectory,
BuildEngine = this,
Expand All @@ -31,7 +33,9 @@ protected GeneratePackageAppxManifest_v0 GetNewTask(
ApplicationTitle = displayName,
AppIcon = appIcon == null ? null : new[] { appIcon },
SplashScreen = splashScreen == null ? null : new[] { splashScreen },
TargetFramework = "windows"
};
}

[Theory]
[InlineData(null, "Package.appxmanifest")]
Expand Down Expand Up @@ -85,8 +89,9 @@ public void CorrectGenerationWhenUserSpecifyBackgroundColor()
{
var input = "empty";
var expected = "typicalWithNoBackground";
var appIcon = new TaskItem("images/appicon.svg");
appIcon.SetMetadata("ForegroundFile", "images/appiconfg.svg");
var appIcon = new TaskItem("images\\appicon.svg");
appIcon.SetMetadata("ForegroundFile", "images\\appiconfg.svg");
appIcon.SetMetadata("Link", "images\\appicon.svg");
appIcon.SetMetadata("IsAppIcon", "true");

var splashScreen = new TaskItem("images/dotnet_bot.svg");
Expand All @@ -102,6 +107,8 @@ public void CorrectGenerationWhenUserSpecifyBackgroundColor()
appIcon: appIcon,
splashScreen: splashScreen);



var success = task.Execute();
Assert.True(success, $"{task.GetType()}.Execute() failed: " + LogErrorEvents.FirstOrDefault()?.Message);

Expand Down
2 changes: 1 addition & 1 deletion src/Resizetizer/test/UnitTests/ResizetizeImagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ public void AppIconWithBackgroundSucceedsWithVectors(string fg, string bg)
var task = GetNewTask(items);
var success = task.Execute();
Assert.True(success, LogErrorEvents.FirstOrDefault()?.Message);
bg = "Images\\" + bg;

AssertFileSize($"{bg}Logo.scale-100.png", 44, 44);
AssertFileSize($"{bg}Logo.scale-125.png", 55, 55);
AssertFileSize($"{bg}Logo.scale-200.png", 88, 88);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Properties>
<PublisherDisplayName>.NET Foundation</PublisherDisplayName>
<DisplayName>Sample App</DisplayName>
<Logo>Images/appiconStoreLogo.png</Logo>
<Logo>images\appiconStoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
Expand All @@ -18,8 +18,8 @@
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements DisplayName="Sample App" Description="Sample App" BackgroundColor="transparent" 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:VisualElements DisplayName="Sample App" Description="Sample App" BackgroundColor="transparent" 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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Properties>
<PublisherDisplayName>.NET Foundation</PublisherDisplayName>
<DisplayName>Sample App</DisplayName>
<Logo>Images/appiconStoreLogo.png</Logo>
<Logo>images\appiconStoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
Expand All @@ -18,8 +18,8 @@
</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: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" />
Expand Down

0 comments on commit de9cc13

Please sign in to comment.