From ec3437f8e69ed38ee8cdfde4d167e717cccb00cd Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Thu, 4 Aug 2022 23:32:36 -0500 Subject: [PATCH] Added impl for ApiInformation for Win8/8.1 Disabled SMTC on Win8.1 --- ZuneShell/Microsoft/WinRT/ApiInformation.cs | 41 +++++++++++++++++++++ ZuneShell/ZuneUI/OSVersion.cs | 8 ++++ ZuneShell/ZuneUI/TransportControls.cs | 7 +++- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 ZuneShell/Microsoft/WinRT/ApiInformation.cs diff --git a/ZuneShell/Microsoft/WinRT/ApiInformation.cs b/ZuneShell/Microsoft/WinRT/ApiInformation.cs new file mode 100644 index 0000000..2f1465a --- /dev/null +++ b/ZuneShell/Microsoft/WinRT/ApiInformation.cs @@ -0,0 +1,41 @@ +#if WINDOWS + +using Microsoft.Win32; +using System; + +namespace Microsoft.WinRT +{ + /// + /// Polyfills for Windows.Foundation.Metadata.ApiInformation + /// + 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); + + /// + /// Returns or to indicate whether a specified type is present. + /// + /// + /// The namespace-qualified name of the type. + /// + /// + /// if the specified type is present; otherwise, . + /// + 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 diff --git a/ZuneShell/ZuneUI/OSVersion.cs b/ZuneShell/ZuneUI/OSVersion.cs index 4dd7d04..15f45d1 100644 --- a/ZuneShell/ZuneUI/OSVersion.cs +++ b/ZuneShell/ZuneUI/OSVersion.cs @@ -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 } } diff --git a/ZuneShell/ZuneUI/TransportControls.cs b/ZuneShell/ZuneUI/TransportControls.cs index 54889a8..8905990 100644 --- a/ZuneShell/ZuneUI/TransportControls.cs +++ b/ZuneShell/ZuneUI/TransportControls.cs @@ -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);