Skip to content

Commit

Permalink
Add WinRTHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Jul 19, 2024
1 parent 50ec7c1 commit 7ca4455
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 69 deletions.
2 changes: 1 addition & 1 deletion source/iNKORE.UI.WPF.Modern.Gallery/ItemPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private void OnContentRootSizeChanged(object sender, SizeChangedEventArgs e)

private void Page_Loaded(object sender, RoutedEventArgs e)
{
if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Xbox")
if (WinRTHelper.GetCurrentDeviceFamilyType() == DeviceFamilyType.Xbox)
{
svPanel.Margin = new Thickness(0, 0, 48, 27);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public NavigationView NavigationView

public Action NavigationViewLoaded { get; set; }

public DeviceType DeviceFamily { get; set; }
public DeviceFamilyType DeviceFamily { get; set; }

public bool IsFocusSupported
{
get
{
return DeviceFamily == DeviceType.Xbox || _isGamePadConnected || _isKeyboardConnected;
return DeviceFamily == DeviceFamilyType.Xbox || _isGamePadConnected || _isKeyboardConnected;
}
}

Expand All @@ -92,17 +92,20 @@ public NavigationRootPage()

_navHelper = new RootFrameNavigationHelper(rootFrame, NavigationViewControl);

SetDeviceFamily();
DeviceFamily = WinRTHelper.GetCurrentDeviceFamilyType() ?? DeviceFamilyType.Other;
AddNavigationMenuItems();
Current = this;
RootFrame = rootFrame;

try
{
Gamepad.GamepadAdded += OnGamepadAdded;
Gamepad.GamepadRemoved += OnGamepadRemoved;
if (WinRTHelper.IsSupported)
{
Gamepad.GamepadAdded += OnGamepadAdded;
Gamepad.GamepadRemoved += OnGamepadRemoved;

_isKeyboardConnected = Convert.ToBoolean(new KeyboardCapabilities().KeyboardPresent);
_isKeyboardConnected = Convert.ToBoolean(new KeyboardCapabilities().KeyboardPresent);
}
}
catch { _isKeyboardConnected = true; }

Expand All @@ -120,18 +123,20 @@ public static string GetAppTitleFromSystem
{
if (PackagedAppHelper.IsPackagedApp)
{
return Windows.ApplicationModel.Package.Current.DisplayName;
try
{
return Windows.ApplicationModel.Package.Current.DisplayName;
}
catch { }
}

if (Application.Current.MainWindow != null)
{
return Application.Current.MainWindow.Title;
}
else
{
if (Application.Current.MainWindow != null)
{
return Application.Current.MainWindow.Title;
}
else
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString();
}
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString();
}
}
}
Expand Down Expand Up @@ -238,25 +243,6 @@ private static IconElement GetIcon(string imagePath)
};
}

private void SetDeviceFamily()
{
try
{
var familyName = AnalyticsInfo.VersionInfo.DeviceFamily;

if (!Enum.TryParse(familyName.Replace("Windows.", string.Empty), out DeviceType parsedDeviceType))
{
parsedDeviceType = DeviceType.Other;
}

DeviceFamily = parsedDeviceType;
}
catch
{
DeviceFamily = DeviceType.Other;
}
}

private void OnNewControlsMenuItemLoaded(object sender, RoutedEventArgs e)
{
if (IsFocusSupported && NavigationViewControl.DisplayMode == NavigationViewDisplayMode.Expanded)
Expand Down Expand Up @@ -521,14 +507,10 @@ private void UpdateHeaderMargin(NavigationView sender)

private void Page_Loaded(object sender, RoutedEventArgs e)
{
try
if (WinRTHelper.GetCurrentDeviceFamilyType() == DeviceFamilyType.Xbox)
{
if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Xbox")
{
XboxContentSafeRect.Visibility = Visibility.Visible;
}
XboxContentSafeRect.Visibility = Visibility.Visible;
}
catch { }
}

private void rootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
Expand All @@ -548,12 +530,4 @@ private void OnRootFrameNavigating(object sender, NavigatingCancelEventArgs e)
}
}
}

public enum DeviceType
{
Desktop,
Mobile,
Other,
Xbox
}
}
39 changes: 20 additions & 19 deletions source/iNKORE.UI.WPF.Modern.Gallery/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" xmlns:uc="clr-namespace:iNKORE.UI.WPF.Modern.Gallery.Controls.UserControls"
Title="Settings Page"
d:DesignWidth="800"
DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}"
DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}" FontSize="14"
mc:Ignorable="d">
<Grid>
<ScrollViewer
Expand Down Expand Up @@ -120,24 +120,25 @@
Margin="0,40,0,0"
Style="{DynamicResource SubtitleTextBlockStyle}"
Text="About" />
<FlowDocumentScrollViewer MaxWidth="840" Margin="0,10,0,0" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<FlowDocument FontFamily="{DynamicResource ContentControlThemeFontFamily}" FontSize="{DynamicResource ContentControlFontSize}">
<Paragraph>
<Run Text="This app is the interactive companion to the " />
<Run FontWeight="SemiBold">iNKORE.UI.WPF.Modern</Run>
<Run Text="." />
</Paragraph>
<Paragraph Margin="0,10,0,0">
<Run Text="Source code: " />
<Hyperlink x:Name="Hyperlink_github">GitHub</Hyperlink>
</Paragraph>
<Paragraph Margin="0,10,0,0">
<Run Text="To clone the source repository: " />
<Run FontStyle="Italic">git clone</Run>
<Run Text="{x:Static ui:ThemeManager.Link_GithubRepo}"/>
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
<TextBlock LineHeight="20" Margin="0,16">

<Run Text="This app is the interactive companion to the " />
<Run FontWeight="SemiBold">iNKORE.UI.WPF.Modern</Run>
<Run Text="." />

<LineBreak/>
<LineBreak/>

<Run Text="Source code: " />
<Hyperlink x:Name="Hyperlink_github">GitHub</Hyperlink>

<LineBreak/>

<Run Text="To clone the source repository: " />
<Run FontStyle="Italic">git clone</Run>
<Run Text="{x:Static ui:ThemeManager.Link_GithubRepo}"/>

</TextBlock>
<TextBlock Margin="0,10,0,0">
Version:<Run FontWeight="Bold" Text="{Binding Version, Mode=OneWay}" />
</TextBlock>
Expand Down
66 changes: 66 additions & 0 deletions source/iNKORE.UI.WPF.Modern/Helpers/WinRTHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace iNKORE.UI.WPF.Modern.Helpers
{
public static class WinRTHelper
{
public static bool IsSupported
{
get
{
try { return Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"); }
catch { }

return false;
}
}

public static string GetCurrentDeviceFamily()
{
try
{
if (IsSupported && Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.System.Profile.AnalyticsInfo"))
{
return Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily;
}
}
catch { }

return null;
}

public static DeviceFamilyType? GetCurrentDeviceFamilyType()
{
try
{
var familyName = GetCurrentDeviceFamily();

if (!string.IsNullOrWhiteSpace(familyName))
{
if (!Enum.TryParse(familyName.Replace("Windows.", string.Empty), out DeviceFamilyType parsedDeviceType))
{
parsedDeviceType = DeviceFamilyType.Other;
}

return parsedDeviceType;
}
}
catch { }

return null;
}
}

public enum DeviceFamilyType
{
Desktop,
Mobile,
Other,
Xbox
}

}
2 changes: 1 addition & 1 deletion source/iNKORE.UI.WPF.Modern/ThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ private void Set<T>(ref T storage, T value, [CallerMemberName]string propertyNam
RaisePropertyChanged(propertyName);
}
}

private ApplicationTheme _actualApplicationTheme;
}
}
Expand Down

0 comments on commit 7ca4455

Please sign in to comment.