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

Updating nuget packages + small cleanup #1796

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
54 changes: 3 additions & 51 deletions WinUIGallery/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using WinUIGallery.Models;
using WinUIGallery.Helpers;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Windows.AppLifecycle;
using Windows.ApplicationModel.Activation;
using WASDK = Microsoft.WindowsAppSDK;
using Microsoft.Windows.AppNotifications;
using Microsoft.Windows.AppNotifications.Builder;
using System.Collections.Generic;
using static WinUIGallery.Helpers.Win32;
using Windows.ApplicationModel.Activation;
using WinUIGallery.Helpers;
using WinUIGallery.Pages;
using static WinUIGallery.Helpers.Win32;

namespace WinUIGallery;

Expand All @@ -37,34 +33,6 @@ sealed partial class App : Application
private static int registeredKeyPressedHook = 0;
private HookProc keyEventHook;


public static string WinAppSdkDetails
{
// TODO: restore patch number and version tag when WinAppSDK supports them both
get => string.Format("Windows App SDK {0}.{1}",
WASDK.Release.Major, WASDK.Release.Minor);
}

public static string WinAppSdkRuntimeDetails
{
get
{
try
{
// Retrieve Windows App Runtime version info dynamically
IEnumerable<FileVersionInfo> windowsAppRuntimeVersion =
from module in Process.GetCurrentProcess().Modules.OfType<ProcessModule>()
where module.FileName.EndsWith("Microsoft.WindowsAppRuntime.Insights.Resource.dll")
select FileVersionInfo.GetVersionInfo(module.FileName);
return WinAppSdkDetails + ", Windows App Runtime " + windowsAppRuntimeVersion.First().FileVersion;
}
catch
{
return WinAppSdkDetails + $", Windows App Runtime {WASDK.Runtime.Version.Major}.{WASDK.Runtime.Version.Minor}";
}
}
}

/// <summary>
/// Get the initial window created for this app.
/// </summary>
Expand All @@ -83,22 +51,6 @@ public App()
UnhandledException += HandleExceptions;
}

/// <summary>
/// Converts a string into a enum.
/// </summary>
/// <typeparam name="TEnum">The output enum type.</typeparam>
/// <param name="text">The input text.</param>
/// <returns>The parsed enum.</returns>
/// <exception cref="InvalidOperationException">Thrown when the TEnum type is not a enum.</exception>
public static TEnum GetEnum<TEnum>(string text) where TEnum : struct
{
if (!typeof(TEnum).GetTypeInfo().IsEnum)
{
throw new InvalidOperationException("Generic parameter 'TEnum' must be an enum.");
}
return (TEnum)Enum.Parse(typeof(TEnum), text);
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
Expand Down
22 changes: 22 additions & 0 deletions WinUIGallery/Helpers/EnumHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Reflection;

namespace WinUIGallery.Helpers;
internal static class EnumHelper
{
/// <summary>
/// Converts a string into a enum.
/// </summary>
/// <typeparam name="TEnum">The output enum type.</typeparam>
/// <param name="text">The input text.</param>
/// <returns>The parsed enum.</returns>
/// <exception cref="InvalidOperationException">Thrown when the TEnum type is not a enum.</exception>
public static TEnum GetEnum<TEnum>(string text) where TEnum : struct
{
if (!typeof(TEnum).GetTypeInfo().IsEnum)
{
throw new InvalidOperationException("Generic parameter 'TEnum' must be an enum.");
}
return (TEnum)Enum.Parse(typeof(TEnum), text);
}
}
4 changes: 2 additions & 2 deletions WinUIGallery/Helpers/ThemeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static ElementTheme ActualTheme
}
}

return WinUIGallery.App.GetEnum<ElementTheme>(App.Current.RequestedTheme.ToString());
return EnumHelper.GetEnum<ElementTheme>(App.Current.RequestedTheme.ToString());
}
}

Expand Down Expand Up @@ -75,7 +75,7 @@ public static void Initialize()

if (savedTheme != null)
{
RootTheme = WinUIGallery.App.GetEnum<ElementTheme>(savedTheme);
RootTheme = EnumHelper.GetEnum<ElementTheme>(savedTheme);
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions WinUIGallery/Helpers/VersionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using WASDK = Microsoft.WindowsAppSDK;

namespace WinUIGallery.Helpers;
internal static class VersionHelper
{
public static string WinAppSdkDetails
{
// TODO: restore patch number and version tag when WinAppSDK supports them both
get => string.Format("Windows App SDK {0}.{1}",
WASDK.Release.Major, WASDK.Release.Minor);
}

public static string WinAppSdkRuntimeDetails
{
get
{
try
{
// Retrieve Windows App Runtime version info dynamically
IEnumerable<FileVersionInfo> windowsAppRuntimeVersion =
from module in Process.GetCurrentProcess().Modules.OfType<ProcessModule>()
where module.FileName.EndsWith("Microsoft.WindowsAppRuntime.Insights.Resource.dll")
select FileVersionInfo.GetVersionInfo(module.FileName);
return WinAppSdkDetails + ", Windows App Runtime " + windowsAppRuntimeVersion.First().FileVersion;
}
catch
{
return WinAppSdkDetails + $", Windows App Runtime {WASDK.Runtime.Version.Major}.{WASDK.Runtime.Version.Minor}";
}
}
}
}
2 changes: 1 addition & 1 deletion WinUIGallery/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public HomePage()
this.InitializeComponent();
}

public string WinAppSdkDetails => App.WinAppSdkDetails;
public string WinAppSdkDetails => VersionHelper.WinAppSdkDetails;

protected override void OnNavigatedTo(NavigationEventArgs e)
{
Expand Down
4 changes: 2 additions & 2 deletions WinUIGallery/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public string Version
}
}

public string WinAppSdkRuntimeDetails => App.WinAppSdkRuntimeDetails;
public string WinAppSdkRuntimeDetails => VersionHelper.WinAppSdkRuntimeDetails;
private int lastNavigationSelectionMode = 0;

public SettingsPage()
Expand Down Expand Up @@ -89,7 +89,7 @@ private void themeMode_SelectionChanged(object sender, RoutedEventArgs e)
string color;
if (selectedTheme != null)
{
ThemeHelper.RootTheme = App.GetEnum<ElementTheme>(selectedTheme);
ThemeHelper.RootTheme = EnumHelper.GetEnum<ElementTheme>(selectedTheme);
if (selectedTheme == "Dark")
{
TitleBarHelper.SetCaptionButtonColors(window, Colors.White);
Expand Down
2 changes: 1 addition & 1 deletion WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void TitleBarHeightComboBox_SelectionChanged(object sender, SelectionCha

if (selectedHeight != null && window != null && window.ExtendsContentIntoTitleBar)
{
window.AppWindow.TitleBar.PreferredHeightOption = App.GetEnum<TitleBarHeightOption>(selectedHeight);
window.AppWindow.TitleBar.PreferredHeightOption = EnumHelper.GetEnum<TitleBarHeightOption>(selectedHeight);
}
}

Expand Down
16 changes: 8 additions & 8 deletions WinUIGallery/WinUIGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@
</ItemGroup>

<ItemGroup Condition="'$(IsInWinUIRepo)' != 'true'">
<PackageReference Update="Microsoft.WindowsAppSDK" Version="$(WindowsAppSdkPackageVersion)" />
<PackageReference Update="Microsoft.WindowsAppSDK" Version="1.6.250205002" />
<PackageReference Remove="ColorCode.Core" />
<PackageReference Include="ColorCode.WinUI" Version="$(ColorCodeVersion)" />
<PackageReference Update="CommunityToolkit.WinUI.Controls.SettingsControls" Version="$(CommunityToolkitWinUIVersion)" />
<PackageReference Update="CommunityToolkit.WinUI.Converters" Version="$(CommunityToolkitWinUIVersion)" />
<PackageReference Update="CommunityToolkit.WinUI.Animations" Version="$(CommunityToolkitWinUIVersion)" />
<PackageReference Update="CommunityToolkit.WinUI.Controls.Primitives" Version="$(CommunityToolkitWinUIVersion)" />
<PackageReference Update="Microsoft.Graphics.Win2D" Version="$(GraphicsWin2DVersion)" />
<PackageReference Include="ColorCode.WinUI" Version="2.0.15" />
<PackageReference Update="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.1.240916" />
<PackageReference Update="CommunityToolkit.WinUI.Converters" Version="8.1.240916" />
<PackageReference Update="CommunityToolkit.WinUI.Animations" Version="8.1.240916" />
<PackageReference Update="CommunityToolkit.WinUI.Controls.Primitives" Version="8.1.240916" />
<PackageReference Update="Microsoft.Graphics.Win2D" Version="1.3.2" />
<!-- Get latest WinRT.Runtime.dll from C#/WinRT -->
<PackageReference Update="Microsoft.Windows.CsWinRT" Version="$(MicrosoftCsWinRTPackageVersion)" />
<PackageReference Update="Microsoft.Windows.CsWinRT" Version="2.2.0" />
<PackageReference Update="System.Private.Uri" Version="4.3.2" />
</ItemGroup>

Expand Down