Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve UWP type recognition #1762

Merged
merged 7 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]** Improved UWP and WinUI app type checking.
MikhailSuendukov marked this conversation as resolved.
Show resolved Hide resolved
* **[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
Loading