-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
AppInfo.shared.cs
136 lines (113 loc) · 4.18 KB
/
AppInfo.shared.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#nullable enable
using System;
namespace Microsoft.Maui.ApplicationModel
{
/// <summary>
/// Represents information about the application.
/// </summary>
public interface IAppInfo
{
/// <summary>
/// Gets the application package name or identifier.
/// </summary>
/// <remarks>On Android and iOS, this is the application package name. On Windows, this is the application GUID.</remarks>
string PackageName { get; }
/// <summary>
/// Gets the application name.
/// </summary>
string Name { get; }
/// <summary>
/// Gets the application version as a string representation.
/// </summary>
string VersionString { get; }
/// <summary>
/// Gets the application version as a <see cref="Version"/> object.
/// </summary>
Version Version { get; }
/// <summary>
/// Gets the application build number.
/// </summary>
string BuildString { get; }
/// <summary>
/// Open the settings menu or page for this application.
/// </summary>
void ShowSettingsUI();
/// <summary>
/// Gets the detected theme of the system or application.
/// </summary>
/// <remarks>For platforms or platform versions which do not support themes, <see cref="AppTheme.Unspecified"/> is returned.</remarks>
AppTheme RequestedTheme { get; }
/// <summary>
/// Gets the packaging model of this application.
/// </summary>
/// <remarks>On other platforms than Windows, this will always return <see cref="AppPackagingModel.Packaged"/>.</remarks>
AppPackagingModel PackagingModel { get; }
/// <summary>
/// Gets the requested layout direction of the system or application.
/// </summary>
LayoutDirection RequestedLayoutDirection { get; }
}
/// <summary>
/// Represents information about the application.
/// </summary>
public static class AppInfo
{
/// <summary>
/// Gets the application package name or identifier.
/// </summary>
/// <remarks>On Android and iOS, this is the application package name. On Windows, this is the application GUID.</remarks>
public static string PackageName => Current.PackageName;
/// <summary>
/// Gets the application name.
/// </summary>
public static string Name => Current.Name;
/// <summary>
/// Gets the application version as a string representation.
/// </summary>
public static string VersionString => Current.VersionString;
/// <summary>
/// Gets the application version as a <see cref="Version"/> object.
/// </summary>
public static Version Version => Current.Version;
/// <summary>
/// Gets the application build number.
/// </summary>
public static string BuildString => Current.BuildString;
/// <summary>
/// Open the settings menu or page for this application.
/// </summary>
public static void ShowSettingsUI() => Current.ShowSettingsUI();
/// <summary>
/// Gets the detected theme of the system or application.
/// </summary>
/// <remarks>For platforms or platform versions which do not support themes, <see cref="AppTheme.Unspecified"/> is returned.</remarks>
public static AppTheme RequestedTheme => Current.RequestedTheme;
/// <summary>
/// Gets the packaging model of this application.
/// </summary>
/// <remarks>On other platforms than Windows, this will always return <see cref="AppPackagingModel.Packaged"/>.</remarks>
public static AppPackagingModel PackagingModel => Current.PackagingModel;
/// <summary>
/// Gets the requested layout direction of the system or application.
/// </summary>
public static LayoutDirection RequestedLayoutDirection => Current.RequestedLayoutDirection;
static IAppInfo? currentImplementation;
/// <summary>
/// Provides the default implementation for static usage of this API.
/// </summary>
public static IAppInfo Current =>
currentImplementation ??= new AppInfoImplementation();
internal static void SetCurrent(IAppInfo? implementation) =>
currentImplementation = implementation;
}
/// <summary>
/// Describes packaging options for a Windows app.
/// </summary>
public enum AppPackagingModel
{
/// <summary>The app is packaged and can be distributed through an MSIX or the store.</summary>
Packaged,
/// <summary>The app is unpcakged and can be distributed as a collection of executable files.</summary>
Unpackaged,
}
}