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

Change SystemInformation from static to regular class (#3168) #8

Merged
merged 1 commit into from
Mar 24, 2020
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: 1 addition & 1 deletion Microsoft.Toolkit.Uwp.SampleApp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override async void OnLaunched(LaunchActivatedEventArgs e)
await RunAppInitialization(e?.Arguments);
}

SystemInformation.TrackAppUse(e);
SystemInformation.Instance.TrackAppUse(e);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
// To get application's name:
public string ApplicationName => SystemInformation.ApplicationName;
public string ApplicationName => SystemInformation.Instance.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.Instance.ApplicationVersion.Major}.{SystemInformation.Instance.ApplicationVersion.Minor}.{SystemInformation.Instance.ApplicationVersion.Build}.{SystemInformation.Instance.ApplicationVersion.Revision}";

// To get the most preferred language by the user:
public CultureInfo Culture => SystemInformation.Culture;
public CultureInfo Culture => SystemInformation.Instance.Culture;

// To get operating syste,
public string OperatingSystem => SystemInformation.OperatingSystem;
// To get operating system
public string OperatingSystem => SystemInformation.Instance.OperatingSystem;

// To get used processor architecture
public ProcessorArchitecture OperatingSystemArchitecture => SystemInformation.OperatingSystemArchitecture;
public ProcessorArchitecture OperatingSystemArchitecture => SystemInformation.Instance.OperatingSystemArchitecture;

// To get operating system version
public OSVersion OperatingSystemVersion => SystemInformation.OperatingSystemVersion;
public OSVersion OperatingSystemVersion => SystemInformation.Instance.OperatingSystemVersion;

// To get device family
public string DeviceFamily => SystemInformation.DeviceFamily;
public string DeviceFamily => SystemInformation.Instance.DeviceFamily;

// To get device model
public string DeviceModel => SystemInformation.DeviceModel;
public string DeviceModel => SystemInformation.Instance.DeviceModel;

// To get device manufacturer
public string DeviceManufacturer => SystemInformation.DeviceManufacturer;
public string DeviceManufacturer => SystemInformation.Instance.DeviceManufacturer;

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

// To get if the app is being used for the first time since it was installed.
public bool IsFirstUse => SystemInformation.IsFirstRun;
public bool IsFirstUse => SystemInformation.Instance.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;
public bool IsAppUpdated => SystemInformation.Instance.IsAppUpdated;

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

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

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

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

// To get the time the launch count was reset, not including this instance
public string LastResetTime => SystemInformation.LastResetTime.ToString(Culture.DateTimeFormat);
public string LastResetTime => SystemInformation.Instance.LastResetTime.ToString(Culture.DateTimeFormat);

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

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

// To get how long the app has been running
public TimeSpan AppUptime => SystemInformation.AppUptime;
public TimeSpan AppUptime => SystemInformation.Instance.AppUptime;
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.ComponentModel;
using System.Globalization;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Uwp.Helpers;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
Expand All @@ -19,52 +16,52 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
public sealed partial class SystemInformationPage : Page
{
// To get application's name:
public string ApplicationName => SystemInformation.ApplicationName;
public string ApplicationName => SystemInformation.Instance.ApplicationName;

// To get application's version:
public string ApplicationVersion => SystemInformation.ApplicationVersion.ToFormattedString();
public string ApplicationVersion => SystemInformation.Instance.ApplicationVersion.ToFormattedString();

// To get the most preferred language by the user:
public CultureInfo Culture => SystemInformation.Culture;
public CultureInfo Culture => SystemInformation.Instance.Culture;

// To get operating syste,
public string OperatingSystem => SystemInformation.OperatingSystem;
// To get operating system
public string OperatingSystem => SystemInformation.Instance.OperatingSystem;

// To get used processor architecture
public ProcessorArchitecture OperatingSystemArchitecture => SystemInformation.OperatingSystemArchitecture;
public ProcessorArchitecture OperatingSystemArchitecture => SystemInformation.Instance.OperatingSystemArchitecture;

// To get operating system version
public OSVersion OperatingSystemVersion => SystemInformation.OperatingSystemVersion;
public OSVersion OperatingSystemVersion => SystemInformation.Instance.OperatingSystemVersion;

// To get device family
public string DeviceFamily => SystemInformation.DeviceFamily;
public string DeviceFamily => SystemInformation.Instance.DeviceFamily;

// To get device model
public string DeviceModel => SystemInformation.DeviceModel;
public string DeviceModel => SystemInformation.Instance.DeviceModel;

// To get device manufacturer
public string DeviceManufacturer => SystemInformation.DeviceManufacturer;
public string DeviceManufacturer => SystemInformation.Instance.DeviceManufacturer;

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

// To get if the app is being used for the first time since it was installed.
public string IsFirstUse => SystemInformation.IsFirstRun.ToString();
public string IsFirstUse => SystemInformation.Instance.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();
public string IsAppUpdated => SystemInformation.Instance.IsAppUpdated.ToString();

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

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

// To get the time the app was launched
public string LaunchTime => SystemInformation.LaunchTime.ToString(Culture.DateTimeFormat);
public string LaunchTime => SystemInformation.Instance.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);
public string LastLaunchTime => SystemInformation.Instance.LastLaunchTime.ToString(Culture.DateTimeFormat);

// To get the time the launch count was reset, not including this instance
public string LastResetTime
Expand All @@ -87,10 +84,10 @@ public long LaunchCount
DependencyProperty.Register(nameof(LaunchCount), typeof(long), typeof(SystemInformationPage), new PropertyMetadata(0));

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

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

public SystemInformationPage()
{
Expand All @@ -100,15 +97,15 @@ public SystemInformationPage()

SampleController.Current.RegisterNewCommand("Reset launch count", (sender, args) =>
{
SystemInformation.ResetLaunchCount();
SystemInformation.Instance.ResetLaunchCount();
RefreshProperties();
});
}

private void RefreshProperties()
{
LaunchCount = SystemInformation.LaunchCount;
LastResetTime = SystemInformation.LastResetTime.ToString(Culture.DateTimeFormat);
LaunchCount = SystemInformation.Instance.LaunchCount;
LastResetTime = SystemInformation.Instance.LastResetTime.ToString(Culture.DateTimeFormat);
}
}
}
21 changes: 7 additions & 14 deletions Microsoft.Toolkit.Uwp.UI/Extensions/Markup/OnDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Windows.ApplicationModel;
using Windows.System.Profile;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Markup;

Expand All @@ -22,6 +21,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions.Markup
[Bindable]
public class OnDevice : MarkupExtension
{
/// <summary>
/// Gets the current device family.
/// </summary>
private string DeviceFamily { get; } = AnalyticsInfo.VersionInfo.DeviceFamily;

/// <summary>
/// Gets or sets the default value for this property
/// </summary>
Expand Down Expand Up @@ -58,18 +62,7 @@ public class OnDevice : MarkupExtension
/// <returns>The object value to set on the property where the extension is applied.</returns>
protected override object ProvideValue()
{
string deviceFamily = null;
if (DesignMode.DesignMode2Enabled)
{
// TODO: detect DeviceFamily in XAML Designer (device dropdown)
// deviceFamily = ???
}
else
{
deviceFamily = Uwp.Helpers.SystemInformation.DeviceFamily;
}

switch (deviceFamily)
switch (DeviceFamily)
{
case "Windows.Desktop":
return this.Desktop ?? this.Default;
Expand Down
Loading