From 1a29870958aa682e2964c6ac27cb03828ca1663c Mon Sep 17 00:00:00 2001 From: Alekhya Date: Tue, 5 May 2020 15:53:30 -0700 Subject: [PATCH] OS Detection and setting the old or new settings UI page accordingly (#2674) * Added code to detect os build number * To set the settings.exe according to the powerToys version that is running * Modified the description of old UI for launcher and keyboard remapper * Using API contracts instead of registry * Removing file that was included by mistake --- .../keyboardmanager/dll/KeyboardManager.rc | 2 +- .../Microsoft.Launcher/Microsoft.Launcher.rc | 25 +++++------ src/runner/pch.h | 1 + src/runner/settings_window.cpp | 45 ++++++++++++++++++- 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/modules/keyboardmanager/dll/KeyboardManager.rc b/src/modules/keyboardmanager/dll/KeyboardManager.rc index bc266ccb07..468391622c 100644 --- a/src/modules/keyboardmanager/dll/KeyboardManager.rc +++ b/src/modules/keyboardmanager/dll/KeyboardManager.rc @@ -5,7 +5,7 @@ STRINGTABLE BEGIN - IDS_SETTINGS_DESCRIPTION L"Customize your experience by remapping keys or creating new shortcuts!" + IDS_SETTINGS_DESCRIPTION L"This feature requires Windows 10, May 2019 Update" IDS_KEYBOARDMANAGER L"Keyboard Manager" END diff --git a/src/modules/launcher/Microsoft.Launcher/Microsoft.Launcher.rc b/src/modules/launcher/Microsoft.Launcher/Microsoft.Launcher.rc index 7e9f4c4be2..c870c17192 100644 --- a/src/modules/launcher/Microsoft.Launcher/Microsoft.Launcher.rc +++ b/src/modules/launcher/Microsoft.Launcher/Microsoft.Launcher.rc @@ -1,15 +1,14 @@ ÿþ#include "resource.h" -#include "../../../common/version.h" STRINGTABLE BEGIN - IDS_LAUNCHER_NAME L"Run" - IDS_LAUNCHER_SETTINGS_DESC L"<No description>" + IDS_LAUNCHER_NAME L"Launcher" + IDS_LAUNCHER_SETTINGS_DESC L"This feature requires Windows 10, May 2019 Update" END 1 VERSIONINFO - FILEVERSION FILE_VERSION - PRODUCTVERSION PRODUCT_VERSION + FILEVERSION 0,1,0,0 + PRODUCTVERSION 0,1,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -24,14 +23,14 @@ BEGIN BLOCK "040904b0" BEGIN - VALUE "CompanyName", COMPANY_NAME - VALUE "FileDescription", "Microsoft.Launcher Module" - VALUE "FileVersion", FILE_VERSION_STRING - VALUE "InternalName", "Microsoft.Launcher" - VALUE "LegalCopyright", COPYRIGHT_NOTE - VALUE "OriginalFilename", "Microsoft.Launcher.dll" - VALUE "ProductName", "Microsoft.Launcher" - VALUE "ProductVersion", PRODUCT_VERSION_STRING + VALUE "CompanyName", "Company Name" + VALUE "FileDescription", "Wox.Launcher Module" + VALUE "FileVersion", "0.1.0.0" + VALUE "InternalName", "Wox.Launcher" + VALUE "LegalCopyright", "Copyright (C) 2019 Company Name" + VALUE "OriginalFilename", "Wox.Launcher.dll" + VALUE "ProductName", "Wox.Launcher" + VALUE "ProductVersion", "0.1.0.0" END END BLOCK "VarFileInfo" diff --git a/src/runner/pch.h b/src/runner/pch.h index 07842b0166..fa35d00897 100644 --- a/src/runner/pch.h +++ b/src/runner/pch.h @@ -27,4 +27,5 @@ #include #include +#include #include \ No newline at end of file diff --git a/src/runner/settings_window.cpp b/src/runner/settings_window.cpp index e31e047eb9..e30166268a 100644 --- a/src/runner/settings_window.cpp +++ b/src/runner/settings_window.cpp @@ -207,6 +207,41 @@ BOOL run_settings_non_elevated(LPCWSTR executable_path, LPWSTR executable_args, return process_created; } +// The following three helper functions determine if the user has a build version higher than or equal to 19h1, as that is a requirement for xaml islands +// Source : Microsoft-ui-xaml github +// Link: https://github.com/microsoft/microsoft-ui-xaml/blob/c045cde57c5c754683d674634a0baccda34d58c4/dev/dll/SharedHelpers.cpp +template bool IsAPIContractVxAvailable() +{ + static bool isAPIContractVxAvailableInitialized = false; + static bool isAPIContractVxAvailable = false; + if (!isAPIContractVxAvailableInitialized) + { + isAPIContractVxAvailableInitialized = true; + isAPIContractVxAvailable = winrt::Windows::Foundation::Metadata::ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", APIVersion); + } + + return isAPIContractVxAvailable; +} + + +bool IsAPIContractV8Available() +{ + return IsAPIContractVxAvailable<8>(); +} + +bool Is19H1OrHigher() +{ + return IsAPIContractV8Available(); +} + +// This function returns true if the build is 19h1 or higher, so that we deploy the new settings. +// It returns false otherwise. +bool use_new_settings() +{ + return Is19H1OrHigher(); +} + + DWORD g_settings_process_id = 0; void run_settings_window() @@ -223,7 +258,15 @@ void run_settings_window() // Arg 1: executable path. std::wstring executable_path = get_module_folderpath(); - executable_path.append(L"\\SettingsUIRunner\\Microsoft.PowerToys.Settings.UI.Runner.exe"); + + if (use_new_settings()) + { + executable_path.append(L"\\SettingsUIRunner\\Microsoft.PowerToys.Settings.UI.Runner.exe"); + } + else + { + executable_path.append(L"\\PowerToysSettings.exe"); + } // Arg 2: pipe server. Generate unique names for the pipes, if getting a UUID is possible. std::wstring powertoys_pipe_name(L"\\\\.\\pipe\\powertoys_runner_");