Skip to content

Commit

Permalink
Merge pull request #2186 from unoplatform/dev/nr/platformcheck
Browse files Browse the repository at this point in the history
fix: Adding platform check before invoking dllimport method
  • Loading branch information
nickrandolph authored Mar 4, 2024
2 parents 51c9c1e + 5b7d0c9 commit 024d12b
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/Uno.Extensions.Core/PlatformHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,26 @@ private static void EnsureInitialized()
|| RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER"));

// If wasm, then can assume app isn't packaged, so skip this check
if (!IsWebAssembly)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
try
{
// Application is MSIX packaged if it has an identity: https://learn.microsoft.com/en-us/windows/msix/detect-package-identity
int length = 0;
var sb = new System.Text.StringBuilder(0);
int result = GetCurrentPackageFullName(ref length, sb);
_isAppPackaged = result != AppModelErrorNoPackage;
}
catch
{
_isAppPackaged = false;
}
_isAppPackaged = IsWindowsAppPackaged();
}
}
}

private static bool IsWindowsAppPackaged()
{
try
{
// Application is MSIX packaged if it has an identity: https://learn.microsoft.com/en-us/windows/msix/detect-package-identity
int length = 0;
var sb = new System.Text.StringBuilder(0);
int result = GetCurrentPackageFullName(ref length, sb);
return result != AppModelErrorNoPackage;
}
catch
{
return false;
}
}
}

0 comments on commit 024d12b

Please sign in to comment.