From 9fa0f100850f69c8f39b6e24486f1e0371e4b10a Mon Sep 17 00:00:00 2001 From: Luke Blevins Date: Tue, 23 Jan 2024 11:51:57 -0500 Subject: [PATCH 01/11] fix: Set AppWindow.Title --- .../src/WindowIconGeneratorTask.cs | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/Resizetizer/src/WindowIconGeneratorTask.cs b/src/Resizetizer/src/WindowIconGeneratorTask.cs index 01b56d3c..22893f25 100644 --- a/src/Resizetizer/src/WindowIconGeneratorTask.cs +++ b/src/Resizetizer/src/WindowIconGeneratorTask.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using System.IO; +using System.Xml.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -31,6 +31,17 @@ public override bool Execute() return false; } + var windowTitle = string.Empty; + + if (Directory.Exists(IntermediateOutputDirectory)) + { + windowTitle = GetDisplayName(); + } + else + { + Directory.CreateDirectory(IntermediateOutputDirectory); + } + var iconPath = UnoIcons[0].ItemSpec; var iconName = Path.GetFileNameWithoutExtension(iconPath); @@ -68,19 +79,41 @@ public static void SetWindowIcon(this global::Microsoft.UI.Xaml.Window window) global::Microsoft.UI.Windowing.AppWindow appWindow = global::Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId); appWindow.SetIcon(""{iconName}.ico""); + appWindow.Title = ""{windowTitle}""; #endif }} }} }}"; - if(!Directory.Exists(IntermediateOutputDirectory)) - { - Directory.CreateDirectory(IntermediateOutputDirectory); - } - var item = new TaskItem(Path.Combine(IntermediateOutputDirectory, FileName)); File.WriteAllText(item.ItemSpec, code); GeneratedClass = new [] { item }; return true; } + + string GetDisplayName() + { + string manifestOutputPath = Path.Combine(IntermediateOutputDirectory, "m", "Package.appxmanifest"); + + if (File.Exists(manifestOutputPath)) + { + var appx = XDocument.Load(manifestOutputPath); + var xmlns = appx.Root!.GetDefaultNamespace(); + + var properties = appx.Root.Element(xmlns + "Properties"); + + if (properties != null) + { + var xname = xmlns + "DisplayName"; + var xelem = properties.Element(xname); + + if (xelem != null) + { + return xelem.Value ?? string.Empty; + } + } + } + + return string.Empty; + } } From c32c306957adc8bb76b8100d6c821de0e3cab1f8 Mon Sep 17 00:00:00 2001 From: Luke Blevins Date: Wed, 24 Jan 2024 11:57:39 -0500 Subject: [PATCH 02/11] fix: address pr feedback --- src/.nuspec/Uno.Resizetizer.targets | 1 + .../src/WindowIconGeneratorTask.cs | 48 ++++--------------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/src/.nuspec/Uno.Resizetizer.targets b/src/.nuspec/Uno.Resizetizer.targets index 33e2d126..38e9b8c0 100644 --- a/src/.nuspec/Uno.Resizetizer.targets +++ b/src/.nuspec/Uno.Resizetizer.targets @@ -513,6 +513,7 @@ Outputs="@(_WindowIconExtension)"> diff --git a/src/Resizetizer/src/WindowIconGeneratorTask.cs b/src/Resizetizer/src/WindowIconGeneratorTask.cs index 22893f25..425736b1 100644 --- a/src/Resizetizer/src/WindowIconGeneratorTask.cs +++ b/src/Resizetizer/src/WindowIconGeneratorTask.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Xml.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -15,6 +14,9 @@ public class WindowIconGeneratorTask_V0 : Task [Required] public string IntermediateOutputDirectory { get; set; } + [Required] + public string WindowTitle { get; set; } + [Output] public ITaskItem[] GeneratedClass { get; private set; } = Array.Empty(); @@ -31,17 +33,6 @@ public override bool Execute() return false; } - var windowTitle = string.Empty; - - if (Directory.Exists(IntermediateOutputDirectory)) - { - windowTitle = GetDisplayName(); - } - else - { - Directory.CreateDirectory(IntermediateOutputDirectory); - } - var iconPath = UnoIcons[0].ItemSpec; var iconName = Path.GetFileNameWithoutExtension(iconPath); @@ -79,41 +70,20 @@ public static void SetWindowIcon(this global::Microsoft.UI.Xaml.Window window) global::Microsoft.UI.Windowing.AppWindow appWindow = global::Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId); appWindow.SetIcon(""{iconName}.ico""); - appWindow.Title = ""{windowTitle}""; + appWindow.Title = ""{WindowTitle}""; #endif }} }} }}"; + if(!Directory.Exists(IntermediateOutputDirectory)) + { + Directory.CreateDirectory(IntermediateOutputDirectory); + } + var item = new TaskItem(Path.Combine(IntermediateOutputDirectory, FileName)); File.WriteAllText(item.ItemSpec, code); GeneratedClass = new [] { item }; return true; - } - - string GetDisplayName() - { - string manifestOutputPath = Path.Combine(IntermediateOutputDirectory, "m", "Package.appxmanifest"); - - if (File.Exists(manifestOutputPath)) - { - var appx = XDocument.Load(manifestOutputPath); - var xmlns = appx.Root!.GetDefaultNamespace(); - - var properties = appx.Root.Element(xmlns + "Properties"); - - if (properties != null) - { - var xname = xmlns + "DisplayName"; - var xelem = properties.Element(xname); - - if (xelem != null) - { - return xelem.Value ?? string.Empty; - } - } - } - - return string.Empty; } } From 68f1dec8b215a99c66aea73c9881e434bb84edb4 Mon Sep 17 00:00:00 2001 From: Luke Blevins Date: Mon, 29 Jan 2024 11:13:52 -0500 Subject: [PATCH 03/11] fix: Obtain title from package manifest --- src/.nuspec/Uno.Resizetizer.targets | 3 ++- .../Uno.Resizetizer.windows.skia.targets | 7 +++-- .../src/GeneratePackageAppxManifest.cs | 26 ++++++++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/.nuspec/Uno.Resizetizer.targets b/src/.nuspec/Uno.Resizetizer.targets index 38e9b8c0..180a6118 100644 --- a/src/.nuspec/Uno.Resizetizer.targets +++ b/src/.nuspec/Uno.Resizetizer.targets @@ -509,11 +509,12 @@ diff --git a/src/.nuspec/Uno.Resizetizer.windows.skia.targets b/src/.nuspec/Uno.Resizetizer.windows.skia.targets index 9f2e0415..c459d328 100644 --- a/src/.nuspec/Uno.Resizetizer.windows.skia.targets +++ b/src/.nuspec/Uno.Resizetizer.windows.skia.targets @@ -71,7 +71,7 @@ - + SplashScreen="@(UnoSplashScreen)"> + + diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index b3f4e7c9..4746ca36 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -45,6 +45,9 @@ public class GeneratePackageAppxManifest_v0 : Task [Output] public ITaskItem GeneratedAppxManifest { get; set; } = null!; + [Output] + public string DisplayName { get; private set; } = null!; + public override bool Execute() { #if DEBUG_RESIZETIZER @@ -143,19 +146,22 @@ void UpdateManifest(XDocument appx) appx.Root.Add(properties); } - // - if (!string.IsNullOrEmpty(ApplicationTitle)) + // + var xDisplayName = xmlns + "DisplayName"; + var xDisplayNameElem = properties.Element(xDisplayName); + + if (!string.IsNullOrEmpty(ApplicationTitle)) { - var xname = xmlns + "DisplayName"; - var xelem = properties.Element(xname); - if (xelem == null || string.IsNullOrEmpty(xelem.Value) || xelem.Value == DefaultPlaceholder) + if (xDisplayNameElem == null || string.IsNullOrEmpty(xDisplayNameElem.Value) || xDisplayNameElem.Value == DefaultPlaceholder) { - properties.SetElementValue(xname, ApplicationTitle); - } - } + properties.SetElementValue(xDisplayName, ApplicationTitle); + } + } - // - if (appIconInfo != null) + DisplayName = xDisplayNameElem.Value; + + // + if (appIconInfo != null) { var xname = xmlns + "Logo"; var xelem = properties.Element(xname); From d464d6c08fdfa9aa50ce808ed016eddf6d6cd9b8 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Mon, 29 Jan 2024 13:27:13 -0300 Subject: [PATCH 04/11] fix: fix my mistake changing Itemname to PropertyName --- src/.nuspec/Uno.Resizetizer.windows.skia.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.nuspec/Uno.Resizetizer.windows.skia.targets b/src/.nuspec/Uno.Resizetizer.windows.skia.targets index c459d328..db33f5e9 100644 --- a/src/.nuspec/Uno.Resizetizer.windows.skia.targets +++ b/src/.nuspec/Uno.Resizetizer.windows.skia.targets @@ -82,7 +82,7 @@ AppIcon="@(UnoImage->WithMetadataValue('IsAppIcon', 'true'))" TargetFramework="$(_UnoResizetizerPlatformIdentifier)" SplashScreen="@(UnoSplashScreen)"> - From 15fa6dba30c12cf100e13adfdfb0847008e8c5f7 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Mon, 29 Jan 2024 13:42:01 -0300 Subject: [PATCH 05/11] fix: reading DisplayName from the property node the xml nodes are immutable, so after setting the value we should read it again --- src/Resizetizer/src/GeneratePackageAppxManifest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index 4746ca36..cb9632cf 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -158,7 +158,7 @@ void UpdateManifest(XDocument appx) } } - DisplayName = xDisplayNameElem.Value; + DisplayName = properties.Element(xDisplayName).Value; // if (appIconInfo != null) From 3193ae6207a40f81ad0acbfe8265aaecda6c4bb1 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Mon, 29 Jan 2024 13:42:41 -0300 Subject: [PATCH 06/11] chore: format --- .../Uno.Resizetizer.windows.skia.targets | 10 +++++----- .../src/GeneratePackageAppxManifest.cs | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/.nuspec/Uno.Resizetizer.windows.skia.targets b/src/.nuspec/Uno.Resizetizer.windows.skia.targets index db33f5e9..71f76cdb 100644 --- a/src/.nuspec/Uno.Resizetizer.windows.skia.targets +++ b/src/.nuspec/Uno.Resizetizer.windows.skia.targets @@ -1,10 +1,10 @@ - - + @@ -71,7 +71,7 @@ - - - + diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index cb9632cf..897aefd3 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -51,7 +51,7 @@ public class GeneratePackageAppxManifest_v0 : Task public override bool Execute() { #if DEBUG_RESIZETIZER - // System.Diagnostics.Debugger.Launch(); + System.Diagnostics.Debugger.Launch(); #endif try { @@ -146,22 +146,22 @@ void UpdateManifest(XDocument appx) appx.Root.Add(properties); } - // - var xDisplayName = xmlns + "DisplayName"; - var xDisplayNameElem = properties.Element(xDisplayName); + // + var xDisplayName = xmlns + "DisplayName"; + var xDisplayNameElem = properties.Element(xDisplayName); - if (!string.IsNullOrEmpty(ApplicationTitle)) + if (!string.IsNullOrEmpty(ApplicationTitle)) { if (xDisplayNameElem == null || string.IsNullOrEmpty(xDisplayNameElem.Value) || xDisplayNameElem.Value == DefaultPlaceholder) { properties.SetElementValue(xDisplayName, ApplicationTitle); - } - } + } + } DisplayName = properties.Element(xDisplayName).Value; - // - if (appIconInfo != null) + // + if (appIconInfo != null) { var xname = xmlns + "Logo"; var xelem = properties.Element(xname); From 4e8d9719904e6f8a62b7d88cd1cb540e24f3d951 Mon Sep 17 00:00:00 2001 From: Luke Blevins Date: Mon, 29 Jan 2024 11:59:27 -0500 Subject: [PATCH 07/11] chore: improve code quality after 15fa6dba30c12cf100e13adfdfb0847008e8c5f7 --- src/Resizetizer/src/GeneratePackageAppxManifest.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index 897aefd3..8f536ed9 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -147,18 +147,17 @@ void UpdateManifest(XDocument appx) } // - var xDisplayName = xmlns + "DisplayName"; - var xDisplayNameElem = properties.Element(xDisplayName); - + var xdisplayname = xmlns + "DisplayName"; if (!string.IsNullOrEmpty(ApplicationTitle)) { - if (xDisplayNameElem == null || string.IsNullOrEmpty(xDisplayNameElem.Value) || xDisplayNameElem.Value == DefaultPlaceholder) + var xelem = properties.Element(xdisplayname); + if (xelem == null || string.IsNullOrEmpty(xelem.Value) || xelem.Value == DefaultPlaceholder) { - properties.SetElementValue(xDisplayName, ApplicationTitle); + properties.SetElementValue(xdisplayname, ApplicationTitle); } } - DisplayName = properties.Element(xDisplayName).Value; + DisplayName = properties.Element(xdisplayname).Value; // if (appIconInfo != null) From d5d4e15d91b32c8f62cffe8ad99271651ee11295 Mon Sep 17 00:00:00 2001 From: Luke Blevins Date: Mon, 29 Jan 2024 12:01:48 -0500 Subject: [PATCH 08/11] chore: re-comment debugger launch --- src/Resizetizer/src/GeneratePackageAppxManifest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index 8f536ed9..d0a44571 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -51,7 +51,7 @@ public class GeneratePackageAppxManifest_v0 : Task public override bool Execute() { #if DEBUG_RESIZETIZER - System.Diagnostics.Debugger.Launch(); + //System.Diagnostics.Debugger.Launch(); #endif try { From 69765585ab768b39f9b0dfaf5267a0c3c829163f Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Mon, 29 Jan 2024 18:46:23 -0300 Subject: [PATCH 09/11] fix: remove the RequiredAtrribute and change the dependency chain UnoGeneratePackageAppxManifest doesn't exist on other targets, so we changed the UnoGeneratePackageAppxManifest to depend on _GenerateWindowUnoIconExtension target instead --- src/.nuspec/Uno.Resizetizer.targets | 1 - src/.nuspec/Uno.Resizetizer.windows.skia.targets | 3 ++- src/Resizetizer/src/WindowIconGeneratorTask.cs | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/.nuspec/Uno.Resizetizer.targets b/src/.nuspec/Uno.Resizetizer.targets index 180a6118..12a2b9e3 100644 --- a/src/.nuspec/Uno.Resizetizer.targets +++ b/src/.nuspec/Uno.Resizetizer.targets @@ -509,7 +509,6 @@ + diff --git a/src/Resizetizer/src/WindowIconGeneratorTask.cs b/src/Resizetizer/src/WindowIconGeneratorTask.cs index 425736b1..bd602513 100644 --- a/src/Resizetizer/src/WindowIconGeneratorTask.cs +++ b/src/Resizetizer/src/WindowIconGeneratorTask.cs @@ -14,7 +14,6 @@ public class WindowIconGeneratorTask_V0 : Task [Required] public string IntermediateOutputDirectory { get; set; } - [Required] public string WindowTitle { get; set; } [Output] From 1ff42a5ceb01c077101d49a0c2844c5607b93503 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Mon, 29 Jan 2024 18:58:43 -0300 Subject: [PATCH 10/11] chore: format --- src/.nuspec/Uno.Resizetizer.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.nuspec/Uno.Resizetizer.targets b/src/.nuspec/Uno.Resizetizer.targets index 12a2b9e3..fcb69676 100644 --- a/src/.nuspec/Uno.Resizetizer.targets +++ b/src/.nuspec/Uno.Resizetizer.targets @@ -513,7 +513,7 @@ Outputs="@(_WindowIconExtension)"> From a8390e2ef25900a14c355b346eceb0d8fa9ccd00 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Mon, 29 Jan 2024 18:59:06 -0300 Subject: [PATCH 11/11] feat: Use ApplicationTitle if there's no WindowTitle --- src/.nuspec/Uno.Resizetizer.targets | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/.nuspec/Uno.Resizetizer.targets b/src/.nuspec/Uno.Resizetizer.targets index fcb69676..e123bf4b 100644 --- a/src/.nuspec/Uno.Resizetizer.targets +++ b/src/.nuspec/Uno.Resizetizer.targets @@ -511,6 +511,11 @@ BeforeTargets="Build;CoreCompile;XamlPreCompile" Inputs="@(UnoIcon)" Outputs="@(_WindowIconExtension)"> + + + $(ApplicationTitle) + +