From 8a22c72e8fee1c38e947ef09875930a80b1b2e05 Mon Sep 17 00:00:00 2001 From: Nick Randolph Date: Thu, 29 Jun 2023 16:44:23 +1000 Subject: [PATCH 1/3] fix: Adjust reading package to return null if Logo not specified --- src/Uno.UWP/ApplicationModel/Package.Other.cs | 61 ++++++++++--------- src/Uno.UWP/ApplicationModel/Package.cs | 2 +- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/Uno.UWP/ApplicationModel/Package.Other.cs b/src/Uno.UWP/ApplicationModel/Package.Other.cs index b463a2a480c7..30ddbaf69c0f 100644 --- a/src/Uno.UWP/ApplicationModel/Package.Other.cs +++ b/src/Uno.UWP/ApplicationModel/Package.Other.cs @@ -49,57 +49,60 @@ public string DisplayName } } - public Uri Logo - { - get - { - TryParsePackageManifest(); - return new Uri(_logo, UriKind.RelativeOrAbsolute); - } - } + public Uri? Logo => + TryParsePackageManifest() && !string.IsNullOrWhiteSpace(_logo) ? new Uri(_logo, UriKind.RelativeOrAbsolute) : default; internal static void SetEntryAssembly(Assembly entryAssembly) { _entryAssembly = entryAssembly; } - private void TryParsePackageManifest() + private bool TryParsePackageManifest() { if (_entryAssembly != null && !_manifestParsed) { - var manifest = _entryAssembly.GetManifestResourceStream(PackageManifestName); - - if (manifest != null) + try { - try - { - var doc = new XmlDocument(); - doc.Load(manifest); + var manifest = _entryAssembly.GetManifestResourceStream(PackageManifestName); - var nsmgr = new XmlNamespaceManager(doc.NameTable); - nsmgr.AddNamespace("d", "http://schemas.microsoft.com/appx/manifest/foundation/windows10"); + if (manifest != null) + { + try + { + var doc = new XmlDocument(); + doc.Load(manifest); - _displayName = doc.SelectSingleNode("/d:Package/d:Properties/d:DisplayName", nsmgr)?.InnerText ?? ""; - _logo = doc.SelectSingleNode("/d:Package/d:Properties/d:Logo", nsmgr)?.InnerText ?? ""; + var nsmgr = new XmlNamespaceManager(doc.NameTable); + nsmgr.AddNamespace("d", "http://schemas.microsoft.com/appx/manifest/foundation/windows10"); - _manifestParsed = true; + _displayName = doc.SelectSingleNode("/d:Package/d:Properties/d:DisplayName", nsmgr)?.InnerText ?? ""; + _logo = doc.SelectSingleNode("/d:Package/d:Properties/d:Logo", nsmgr)?.InnerText ?? ""; + return true; + } + catch (Exception ex) + { + if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Error)) + { + this.Log().Error($"Failed to read manifest [{PackageManifestName}]", ex); + } + } } - catch (Exception ex) + else { - if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Error)) + if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug)) { - this.Log().Error($"Failed to read manifest [{PackageManifestName}]", ex); + this.Log().Debug($"Skipping manifest reading, unable to find [{PackageManifestName}]"); } } } - else + finally { - if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug)) - { - this.Log().Debug($"Skipping manifest reading, unable to find [{PackageManifestName}]"); - } + // Make sure this is set to true even if we failed to read the manifest + // to prevent multiple attempts to read the manifest + _manifestParsed = true; } } + return false; } } } diff --git a/src/Uno.UWP/ApplicationModel/Package.cs b/src/Uno.UWP/ApplicationModel/Package.cs index e7cff2d4e40d..afea1841ea26 100644 --- a/src/Uno.UWP/ApplicationModel/Package.cs +++ b/src/Uno.UWP/ApplicationModel/Package.cs @@ -56,7 +56,7 @@ internal Package() #if (__IOS__ || __ANDROID__ || __MACOS__) [global::Uno.NotImplemented] - public global::System.Uri Logo => new Uri("http://example.com"); + public global::System.Uri? Logo => default; #endif [Uno.NotImplemented] From 1025db7ac4ccbee1b3aae66aed52305dc6caca7a Mon Sep 17 00:00:00 2001 From: Nick Randolph Date: Thu, 29 Jun 2023 16:55:21 +1000 Subject: [PATCH 2/3] fix: Correcting loading behaviour for subsequent calls to Logo --- src/Uno.UWP/ApplicationModel/Package.Other.cs | 57 +++++++++---------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/src/Uno.UWP/ApplicationModel/Package.Other.cs b/src/Uno.UWP/ApplicationModel/Package.Other.cs index 30ddbaf69c0f..e06f2f3510e4 100644 --- a/src/Uno.UWP/ApplicationModel/Package.Other.cs +++ b/src/Uno.UWP/ApplicationModel/Package.Other.cs @@ -20,7 +20,7 @@ public partial class Package private static Assembly? _entryAssembly; private string _displayName = ""; private string _logo = "ms-appx://logo"; - private bool _manifestParsed; + private bool? _manifestParsed; private bool GetInnerIsDevelopmentMode() => false; @@ -59,50 +59,45 @@ internal static void SetEntryAssembly(Assembly entryAssembly) private bool TryParsePackageManifest() { - if (_entryAssembly != null && !_manifestParsed) + if (_entryAssembly != null && + !_manifestParsed.HasValue) { - try - { - var manifest = _entryAssembly.GetManifestResourceStream(PackageManifestName); + var manifest = _entryAssembly.GetManifestResourceStream(PackageManifestName); - if (manifest != null) + if (manifest != null) + { + try { - try - { - var doc = new XmlDocument(); - doc.Load(manifest); + var doc = new XmlDocument(); + doc.Load(manifest); - var nsmgr = new XmlNamespaceManager(doc.NameTable); - nsmgr.AddNamespace("d", "http://schemas.microsoft.com/appx/manifest/foundation/windows10"); + var nsmgr = new XmlNamespaceManager(doc.NameTable); + nsmgr.AddNamespace("d", "http://schemas.microsoft.com/appx/manifest/foundation/windows10"); - _displayName = doc.SelectSingleNode("/d:Package/d:Properties/d:DisplayName", nsmgr)?.InnerText ?? ""; - _logo = doc.SelectSingleNode("/d:Package/d:Properties/d:Logo", nsmgr)?.InnerText ?? ""; - return true; - } - catch (Exception ex) - { - if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Error)) - { - this.Log().Error($"Failed to read manifest [{PackageManifestName}]", ex); - } - } + _displayName = doc.SelectSingleNode("/d:Package/d:Properties/d:DisplayName", nsmgr)?.InnerText ?? ""; + _logo = doc.SelectSingleNode("/d:Package/d:Properties/d:Logo", nsmgr)?.InnerText ?? ""; + _manifestParsed = true; } - else + catch (Exception ex) { - if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug)) + _manifestParsed = false; + if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Error)) { - this.Log().Debug($"Skipping manifest reading, unable to find [{PackageManifestName}]"); + this.Log().Error($"Failed to read manifest [{PackageManifestName}]", ex); } } } - finally + else { - // Make sure this is set to true even if we failed to read the manifest - // to prevent multiple attempts to read the manifest - _manifestParsed = true; + _manifestParsed = false; + if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug)) + { + this.Log().Debug($"Skipping manifest reading, unable to find [{PackageManifestName}]"); + } } } - return false; + + return _manifestParsed ?? false; } } } From 340af1a00d7cdfa0a0dd97350174f1de1925c0a0 Mon Sep 17 00:00:00 2001 From: Nick Randolph Date: Thu, 29 Jun 2023 23:04:42 +1000 Subject: [PATCH 3/3] fix: Correct nullable usage --- src/Uno.UWP/ApplicationModel/Package.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Uno.UWP/ApplicationModel/Package.cs b/src/Uno.UWP/ApplicationModel/Package.cs index afea1841ea26..b73607976c20 100644 --- a/src/Uno.UWP/ApplicationModel/Package.cs +++ b/src/Uno.UWP/ApplicationModel/Package.cs @@ -56,7 +56,7 @@ internal Package() #if (__IOS__ || __ANDROID__ || __MACOS__) [global::Uno.NotImplemented] - public global::System.Uri? Logo => default; + public global::System.Uri Logo => default; #endif [Uno.NotImplemented]