Skip to content

Commit

Permalink
Merge pull request #18984 from unoplatform/dev/spouliot/macos-bundle-…
Browse files Browse the repository at this point in the history
…awareness

feat(macOS): override ms-appx location when app is bundled
  • Loading branch information
jeromelaban authored Dec 6, 2024
2 parents 2482f84 + 05f21e6 commit 40847a9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Uno.UI.Runtime.Skia.MacOS/MacOSWindowNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Uno.UI.Runtime.Skia.MacOS/NativeUno.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]<nint, double, double, nint, void> metalCallback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/Uno.UWP/Storage/StorageFile.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Windows.Storage
{
partial class StorageFile
{
internal static string ResourcePathBase { get; set; } = Package.Current.InstalledPath;

private static async Task<StorageFile> GetFileFromApplicationUri(CancellationToken ct, Uri uri)
{
if (uri.Scheme != "ms-appx")
Expand All @@ -22,7 +24,7 @@ private static async Task<StorageFile> 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)
{
Expand Down

0 comments on commit 40847a9

Please sign in to comment.