-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystemHelper.cs
118 lines (112 loc) · 3.86 KB
/
SystemHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation.Metadata;
using Windows.Graphics.Display;
using Windows.UI;
using Windows.UI.ViewManagement;
namespace UniversalPlatformTools
{
/// <summary>
/// Provides some useful information about the current system.
/// </summary>
public static class SystemHelper
{
private const string DARK_THEME_BCKG = "#FF000000";
private const string LIGHT_THEME_BCKG = "#FFFFFFFF";
private static readonly string[] _fontFamilies = new string[] { "Arial", "Calibri", "Cambria", "Comic Sans MS", "Courier New", "Ebrima", "Gadugi", "Georgia", "Leelawadee UI", "Lucida Console", "Malgun Gothic", "Microsoft JhengHei", "Microsoft Yahei", "Nirmala UI", "Segoe Print", "Segoe UI", "SimSun", "Times New Roman", "Trebuchet MS", "Verdana", "Yu Gothic" };
/// <summary>
/// Returns whether the system is in Tablet Mode.
/// </summary>
public static bool IsInTabletMode
{
get
{
return UIViewSettings.GetForCurrentView().UserInteractionMode == UserInteractionMode.Touch;
}
}
/// <summary>
/// Gets the resolution of the current screen. Get more display information by using <see cref="DisplayInformation"/>.
/// </summary>
public static ScreenResolution GetScreenResolution()
{
var display = DisplayInformation.GetForCurrentView();
var width = display.ScreenWidthInRawPixels;
var height = display.ScreenHeightInRawPixels;
var scale = (int)display.ResolutionScale;
return new ScreenResolution
{
Width = width,
Height = height,
ScalePercent = scale
};
}
/// <summary>
/// Gets info about the running Windows 10 Build.
/// </summary>
/// <returns></returns>
public static WindowsVersion GetOSVersion()
{
return WindowsVersion.CurrentVersion;
}
/// <summary>
/// Returns the user specific System Accent Color.
/// </summary>
public static Color GetSystemAccentColor()
{
return GetSystemColor(UIColorType.Accent);
}
/// <summary>
/// Returns the color value of the specific color type in the system.
/// </summary>
public static Color GetSystemColor(UIColorType colorType)
{
UISettings settings = new UISettings();
return settings.GetColorValue(colorType);
}
/// <summary>
/// Returns the system theme set by the user.
/// </summary>
/// <returns></returns>
public static SystemTheme GetSystemTheme()
{
var DefaultTheme = new UISettings();
var uiTheme = DefaultTheme.GetColorValue(UIColorType.Background).ToString();
if (uiTheme == DARK_THEME_BCKG)
{
return SystemTheme.Dark;
}
else if (uiTheme == LIGHT_THEME_BCKG)
{
return SystemTheme.Light;
}
return SystemTheme.Unknown;
}
/// <summary>
/// Returns a collection of font families guaranteed across all Windows 10 versions and devices.
/// </summary>
public static ICollection<string> GetStandardFontFamilies()
{
return _fontFamilies.ToArray();
}
}
/// <summary>
/// Represents the system themes
/// </summary>
public enum SystemTheme
{
/// <summary>
/// Light Theme
/// </summary>
Light,
/// <summary>
/// Dark Theme
/// </summary>
Dark,
/// <summary>
/// Unknown
/// </summary>
Unknown,
}
}