Skip to content

Commit

Permalink
Improve UWP type recognition (#1762)
Browse files Browse the repository at this point in the history
Co-authored-by: Dima <[email protected]>
  • Loading branch information
MikhailSuendukov and DmitriyKirakosyan authored Nov 20, 2023
1 parent ddbf993 commit 98bbf05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#### Windows

* **[Improvement]** Improve UWP and WinUI app type checking.
* **[Improvement]** Update SQLitePCLRaw.bundle_green to version 2.1.6
___

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,28 @@ public static class WindowsHelper

private static bool _IsRunningAsUwp()
{
if (Environment.OSVersion.Version < new Version(6, 2))
try
{
return false;
return Assembly.GetEntryAssembly().GetReferencedAssemblies()
.Any(referencedAssembly => referencedAssembly.Name == "Windows.UI.Xaml");
}
catch (Exception e)
{
AppCenterLog.Error(AppCenterLog.LogTag, "Failed to determine whether this application is UWP or not.", e);
}

int length = 0;
var sb = new StringBuilder(0);
GetCurrentPackageFullName(ref length, sb);

sb = new StringBuilder(length);
int result = GetCurrentPackageFullName(ref length, sb);

return result != APPMODEL_ERROR_NO_PACKAGE;
return false;
}

#endregion

private static bool _IsRunnigAsWinUI()
private static bool _IsRunningAsWinUI()
{
try
try
{
// Get the main assembly of the application
Assembly mainAssembly = Assembly.GetEntryAssembly();

// Check if the main assembly references the Microsoft.UI.Xaml or Microsoft.WinUI assembly, which is used by WinUI applications
foreach (AssemblyName referencedAssembly in mainAssembly.GetReferencedAssemblies())
{
if (referencedAssembly.Name == "Microsoft.UI.Xaml" || referencedAssembly.Name == "Microsoft.WinUI")
{
return true;
}
}
}
catch (Exception e)
return Assembly.GetEntryAssembly().GetReferencedAssemblies()
.Any(referencedAssembly => referencedAssembly.Name == "Microsoft.UI.Xaml" || referencedAssembly.Name == "Microsoft.WinUI");
}
catch (Exception e)
{
AppCenterLog.Error(AppCenterLog.LogTag, "Failed to determine whether this application is WinUI or not.", e);
}
Expand Down Expand Up @@ -150,7 +138,7 @@ static WindowsHelper()
AppCenterLog.Warn(AppCenterLog.LogTag, "Unabled to determine whether this application is WPF or Windows Forms; proceeding as though it is Windows Forms.");
}
IsRunningAsUwp = _IsRunningAsUwp();
IsRunningAsWinUI = IsRunningAsUwp || _IsRunnigAsWinUI();
IsRunningAsWinUI = IsRunningAsUwp || _IsRunningAsWinUI();
}

// Store the int corresponding to the "Minimized" state for WPF Windows
Expand Down

0 comments on commit 98bbf05

Please sign in to comment.