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

Add to SystemInformation class #1533

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
await RunAppInitialization(e?.Arguments);
}

SystemInformation.TrackAppUse(e);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,28 @@
public string DeviceManufacturer => SystemInformation.DeviceManufacturer;

// To get available memory in MB
public float AvailableMemory => SystemInformation.AvailableMemory;
public float AvailableMemory => SystemInformation.AvailableMemory;

// To get if the app is being used for the first time since it was installed.
public bool IsFirstUse => SystemInformation.IsFirstRun;

// To get if the app is being used for the first time since being upgraded from an older version.
public bool IsAppUpdated => SystemInformation.IsAppUpdated;

// To get the first version installed
public PackageVersion FirstVersionInstalled => SystemInformation.FirstVersionInstalled;

// To get the first time the app was launched
public DateTime FirstUseTime => SystemInformation.FirstUseTime;

// To get the time the app was launched.
public DateTime LaunchTime => SystemInformation.LaunchTime;

// To get the time the app was previously launched, not including this instance.
public DateTime LastLaunchTime => SystemInformation.LastLaunchTime;

// To get the number of times the app has been launched.
public long LaunchCount => SystemInformation.LaunchCount;

// To get how long the app has been running
public TimeSpan AppUptime => SystemInformation.AppUptime;
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,102 @@
Text="{x:Bind AvailableMemory}"
TextWrapping="Wrap" />
</StackPanel>
<StackPanel x:Name="Stack10"
Margin="10"
Orientation="Horizontal">
<TextBlock FontSize="18"
FontWeight="Bold"
Text="Is first use:"
TextWrapping="Wrap" />
<TextBlock Margin="20,0"
FontSize="18"
Text="{x:Bind IsFirstUse}"
TextWrapping="Wrap" />
</StackPanel>
<StackPanel x:Name="Stack11"
Margin="10"
Orientation="Horizontal">
<TextBlock FontSize="18"
FontWeight="Bold"
Text="Is app updated:"
TextWrapping="Wrap" />
<TextBlock Margin="20,0"
FontSize="18"
Text="{x:Bind IsAppUpdated}"
TextWrapping="Wrap" />
</StackPanel>
<StackPanel x:Name="Stack12"
Margin="10"
Orientation="Horizontal">
<TextBlock FontSize="18"
FontWeight="Bold"
Text="First version installed:"
TextWrapping="Wrap" />
<TextBlock Margin="20,0"
FontSize="18"
Text="{x:Bind FirstVersionInstalled}"
TextWrapping="Wrap" />
</StackPanel>
<StackPanel x:Name="Stack13"
Margin="10"
Orientation="Horizontal">
<TextBlock FontSize="18"
FontWeight="Bold"
Text="First use time:"
TextWrapping="Wrap" />
<TextBlock Margin="20,0"
FontSize="18"
Text="{x:Bind FirstUseTime}"
TextWrapping="Wrap" />
</StackPanel>
<StackPanel x:Name="Stack14"
Margin="10"
Orientation="Horizontal">
<TextBlock FontSize="18"
FontWeight="Bold"
Text="Launch time:"
TextWrapping="Wrap" />
<TextBlock Margin="20,0"
FontSize="18"
Text="{x:Bind LaunchTime}"
TextWrapping="Wrap" />
</StackPanel>
<StackPanel x:Name="Stack15"
Margin="10"
Orientation="Horizontal">
<TextBlock FontSize="18"
FontWeight="Bold"
Text="Last launch time:"
TextWrapping="Wrap" />
<TextBlock Margin="20,0"
FontSize="18"
Text="{x:Bind LastLaunchTime}"
TextWrapping="Wrap" />
</StackPanel>
<StackPanel x:Name="Stack16"
Margin="10"
Orientation="Horizontal">
<TextBlock FontSize="18"
FontWeight="Bold"
Text="Launch count:"
TextWrapping="Wrap" />
<TextBlock Margin="20,0"
FontSize="18"
Text="{x:Bind LaunchCount}"
TextWrapping="Wrap" />
</StackPanel>
<StackPanel x:Name="Stack17"
Margin="10"
Orientation="Horizontal">
<TextBlock FontSize="18"
FontWeight="Bold"
Text="App uptime:"
TextWrapping="Wrap" />
<TextBlock Margin="20,0"
FontSize="18"
Text="{x:Bind AppUptime}"
TextWrapping="Wrap" />
</StackPanel>
</StackPanel>
</ScrollViewer>
<VisualStateManager.VisualStateGroups>
Expand All @@ -156,6 +252,14 @@
<Setter Target="Stack7.Orientation" Value="Vertical" />
<Setter Target="Stack8.Orientation" Value="Vertical" />
<Setter Target="Stack9.Orientation" Value="Vertical" />
<Setter Target="Stack10.Orientation" Value="Vertical" />
<Setter Target="Stack11.Orientation" Value="Vertical" />
<Setter Target="Stack12.Orientation" Value="Vertical" />
<Setter Target="Stack13.Orientation" Value="Vertical" />
<Setter Target="Stack14.Orientation" Value="Vertical" />
<Setter Target="Stack15.Orientation" Value="Vertical" />
<Setter Target="Stack16.Orientation" Value="Vertical" />
<Setter Target="Stack17.Orientation" Value="Vertical" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed partial class SystemInformationPage : Page
public string ApplicationName => SystemInformation.ApplicationName;

// To get application's version:
public string ApplicationVersion => $"{SystemInformation.ApplicationVersion.Major}.{SystemInformation.ApplicationVersion.Minor}.{SystemInformation.ApplicationVersion.Build}.{SystemInformation.ApplicationVersion.Revision}";
public string ApplicationVersion => SystemInformation.ApplicationVersion.ToFormattedString();

// To get the most preferred language by the user:
public CultureInfo Culture => SystemInformation.Culture;
Expand All @@ -52,6 +52,30 @@ public sealed partial class SystemInformationPage : Page
// To get available memory in MB
public float AvailableMemory => SystemInformation.AvailableMemory;

// To get if the app is being used for the first time since it was installed.
public string IsFirstUse => SystemInformation.IsFirstRun.ToString();

// To get if the app is being used for the first time since being upgraded from an older version.
public string IsAppUpdated => SystemInformation.IsAppUpdated.ToString();

// To get the first version installed
public string FirstVersionInstalled => SystemInformation.FirstVersionInstalled.ToFormattedString();

// To get the first time the app was launched
public string FirstUseTime => SystemInformation.FirstUseTime.ToString(Culture.DateTimeFormat);

// To get the time the app was launched
public string LaunchTime => SystemInformation.LaunchTime.ToString(Culture.DateTimeFormat);

// To get the time the app was previously launched, not including this instance
public string LastLaunchTime => SystemInformation.LastLaunchTime.ToString(Culture.DateTimeFormat);

// To get the number of times the app has been launched.
public long LaunchCount => SystemInformation.LaunchCount;

// To get how long the app has been running
public string AppUptime => SystemInformation.AppUptime.ToString();

public SystemInformationPage()
{
InitializeComponent();
Expand Down
50 changes: 50 additions & 0 deletions Microsoft.Toolkit.Uwp/Helpers/PackageVersionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

using Windows.ApplicationModel;

namespace Microsoft.Toolkit.Uwp.Helpers
{
/// <summary>
/// This class provides static helper methods for <see cref="PackageVersion" />.
/// </summary>
public static class PackageVersionHelper
{
/// <summary>
/// Returns a string representing the version number, of the format 'Major.Minor.Build.Revision'
/// </summary>
/// <param name="packageVersion">The PackageVersion to convert to a string</param>
/// <returns>String of the format 'Major.Minor.Build.Revision'</returns>
public static string ToFormattedString(this PackageVersion packageVersion)
{
return $"{packageVersion.Major}.{packageVersion.Minor}.{packageVersion.Build}.{packageVersion.Revision}";
}

/// <summary>
/// Convert a formatted string representing a version number as a PackageVersion object
/// </summary>
/// <param name="formattedVersionNumber">String of the format 'Major.Minor.Build.Revision'</param>
/// <returns>A Package Version object</returns>
public static PackageVersion ToPackageVersion(this string formattedVersionNumber)
{
var parts = formattedVersionNumber.Split('.');

return new PackageVersion
{
Major = ushort.Parse(parts[0]),
Minor = ushort.Parse(parts[1]),
Build = ushort.Parse(parts[2]),
Revision = ushort.Parse(parts[3])
};
}
}
}
Loading