Added impl for ApiInformation for Win8/8.1

Disabled SMTC on Win8.1
This commit is contained in:
Yoshi Askharoun
2022-08-04 23:32:36 -05:00
parent 5b42ae5a72
commit ec3437f8e6
3 changed files with 54 additions and 2 deletions
@@ -0,0 +1,41 @@
#if WINDOWS
using Microsoft.Win32;
using System;
namespace Microsoft.WinRT
{
/// <summary>
/// Polyfills for <c>Windows.Foundation.Metadata.ApiInformation</c>
/// </summary>
internal static class ApiInformation
{
private static readonly Version Win8Version = new(6, 2, 0, 0);
private static readonly Version Win81Version = new(6, 3, 0, 0);
private static readonly Version Win10Version = new(10, 0, 0, 0);
/// <summary>
/// Returns <see langword="true"/> or <see langword="false"/> to indicate whether a specified type is present.
/// </summary>
/// <param name="typeName">
/// The namespace-qualified name of the type.
/// </param>
/// <returns>
/// <see langword="true"/> if the specified type is present; otherwise, <see langword="false"/>.
/// </returns>
public static bool IsTypePresent(string typeName)
{
if (Environment.OSVersion.Version >= Win10Version)
{
return Windows.Foundation.Metadata.ApiInformation.IsTypePresent(typeName);
}
else
{
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId\" + typeName, false);
return key != null;
}
}
}
}
#endif
+8
View File
@@ -20,5 +20,13 @@ namespace ZuneUI
return true;
return Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor >= 1;
}
#if NET6_0_OR_GREATER
public static bool IsLessThanWin8() => !OperatingSystem.IsWindowsVersionAtLeast(6, 2);
public static bool IsLessThanWin81() => !OperatingSystem.IsWindowsVersionAtLeast(6, 3);
public static bool IsLessThanWin10() => !OperatingSystem.IsWindowsVersionAtLeast(10, 0);
#endif
}
}
+5 -2
View File
@@ -826,8 +826,11 @@ namespace ZuneUI
}
#if WINDOWS
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Media.SystemMediaTransportControls"))
if (Microsoft.WinRT.ApiInformation.IsTypePresent("Windows.Media.SystemMediaTransportControls")
&& !OSVersion.IsLessThanWin10())
{
// Windows 8.1 doesn't seem to support non-Metro apps using this API.
// On Windows 8.1 / 10 / 11
var _systemMediaTransportControls = Windows.Media.SystemMediaTransportControlsInterop.GetForWindow(Application.Window.Handle);
_systemMediaTransportControls.PlaybackStatus = stateNew switch
@@ -1770,7 +1773,7 @@ namespace ZuneUI
// Use SMTC when available
#if WINDOWS
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Media.SystemMediaTransportControls"))
if (Microsoft.WinRT.ApiInformation.IsTypePresent("Windows.Media.SystemMediaTransportControls"))
{
// On Windows 8.1 / 10 / 11
var _systemMediaTransportControls = Windows.Media.SystemMediaTransportControlsInterop.GetForWindow(Application.Window.Handle);