From 05f21e6866ce3376042de21715407344b814a822 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Mon, 2 Dec 2024 13:45:18 -0500 Subject: [PATCH] feat(macOS): override ms-appx location when app is bundled --- src/Uno.UI.Runtime.Skia.MacOS/MacOSWindowNative.cs | 4 ++++ src/Uno.UI.Runtime.Skia.MacOS/NativeUno.cs | 4 ++++ .../UnoNativeMac/UnoNativeMac/UNOApplication.h | 1 + .../UnoNativeMac/UnoNativeMac/UNOApplication.m | 5 +++++ src/Uno.UWP/Storage/StorageFile.skia.cs | 4 +++- 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Uno.UI.Runtime.Skia.MacOS/MacOSWindowNative.cs b/src/Uno.UI.Runtime.Skia.MacOS/MacOSWindowNative.cs index 89af44792c64..9d90cd34adbf 100644 --- a/src/Uno.UI.Runtime.Skia.MacOS/MacOSWindowNative.cs +++ b/src/Uno.UI.Runtime.Skia.MacOS/MacOSWindowNative.cs @@ -54,6 +54,10 @@ public MacOSWindowNative(WinUIWindow winUIWindow, Microsoft.UI.Xaml.XamlRoot xam NativeWindowReady?.Invoke(this, this); + if (NativeUno.uno_application_is_bundled()) + { + Windows.Storage.StorageFile.ResourcePathBase = IOPath.Combine(Windows.ApplicationModel.Package.Current.InstalledPath, "..", "Resources"); + } UpdateWindowPropertiesFromPackage(); UpdateWindowPropertiesFromApplicationView(); } diff --git a/src/Uno.UI.Runtime.Skia.MacOS/NativeUno.cs b/src/Uno.UI.Runtime.Skia.MacOS/NativeUno.cs index 30bb1dc9561a..47ae58701e01 100644 --- a/src/Uno.UI.Runtime.Skia.MacOS/NativeUno.cs +++ b/src/Uno.UI.Runtime.Skia.MacOS/NativeUno.cs @@ -166,6 +166,10 @@ internal static partial class NativeUno [return: MarshalAs(UnmanagedType.I1)] internal static partial bool uno_application_query_url_support(string url); + [LibraryImport("libUnoNativeMac.dylib")] + [return: MarshalAs(UnmanagedType.I1)] + internal static partial bool uno_application_is_bundled(); + [LibraryImport("libUnoNativeMac.dylib")] internal static unsafe partial void uno_set_drawing_callbacks( delegate* unmanaged[Cdecl] metalCallback, diff --git a/src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOApplication.h b/src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOApplication.h index 46f8832eb003..0fb4900ab266 100644 --- a/src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOApplication.h +++ b/src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOApplication.h @@ -22,6 +22,7 @@ void uno_application_set_badge(const char *badge); void uno_application_set_icon(const char *path); bool uno_application_open_url(const char *url); bool uno_application_query_url_support(const char *url); +bool uno_application_is_bundled(void); typedef bool (*application_can_exit_fn_ptr)(void); application_can_exit_fn_ptr uno_get_application_can_exit_callback(void); diff --git a/src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOApplication.m b/src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOApplication.m index 3a1adbc2eedc..5eac3ebf1a47 100644 --- a/src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOApplication.m +++ b/src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOApplication.m @@ -102,6 +102,11 @@ void uno_set_application_can_exit_callback(application_can_exit_fn_ptr p) application_can_exit = p; } +bool uno_application_is_bundled(void) +{ + return NSRunningApplication.currentApplication.bundleIdentifier != nil; +} + void uno_application_quit(void) { #if DEBUG diff --git a/src/Uno.UWP/Storage/StorageFile.skia.cs b/src/Uno.UWP/Storage/StorageFile.skia.cs index 67bcf2a7338c..2c004139103a 100644 --- a/src/Uno.UWP/Storage/StorageFile.skia.cs +++ b/src/Uno.UWP/Storage/StorageFile.skia.cs @@ -12,6 +12,8 @@ namespace Windows.Storage { partial class StorageFile { + internal static string ResourcePathBase { get; set; } = Package.Current.InstalledPath; + private static async Task GetFileFromApplicationUri(CancellationToken ct, Uri uri) { if (uri.Scheme != "ms-appx") @@ -22,7 +24,7 @@ private static async Task GetFileFromApplicationUri(CancellationTok var path = Uri.UnescapeDataString(uri.PathAndQuery).TrimStart('/'); - var resourcePathname = global::System.IO.Path.Combine(Package.Current.InstalledPath, uri.Host, path); + var resourcePathname = global::System.IO.Path.Combine(ResourcePathBase, uri.Host, path); if (resourcePathname != null) {