Compare commits

...

4 Commits

Author SHA1 Message Date
Yaqing Mi (from Dev Box)
b32c75e1d0 Add enable button for settings-UI 2025-03-03 21:31:50 +08:00
Yaqing Mi (from Dev Box)
0ebfbca2a7 Update the interface logic 2025-03-03 15:43:57 +08:00
Yaqing Mi (from Dev Box)
79403667ef Add GPO 2025-02-27 19:40:09 +08:00
Yaqing Mi (from Dev Box)
7850f5eb79 Add CharacterMap Module Interface 2025-02-27 19:09:27 +08:00
29 changed files with 832 additions and 0 deletions

View File

@@ -646,6 +646,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hosts.FuzzTests", "src\modu
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hosts.UITests", "src\modules\Hosts\Hosts.UITests\Hosts.UITests.csproj", "{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CharacterMap", "CharacterMap", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CharacterMapModuleInterface", "src\modules\CharacterMap\CharacterMapModuleInterface\CharacterMapModuleInterface.vcxproj", "{4D6155E2-055B-4B0F-85E8-C3A1AAA54C82}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
@@ -2294,6 +2298,14 @@ Global
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0}.Release|ARM64.Build.0 = Release|ARM64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0}.Release|x64.ActiveCfg = Release|x64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0}.Release|x64.Build.0 = Release|x64
{4D6155E2-055B-4B0F-85E8-C3A1AAA54C82}.Debug|ARM64.ActiveCfg = Debug|ARM64
{4D6155E2-055B-4B0F-85E8-C3A1AAA54C82}.Debug|ARM64.Build.0 = Debug|ARM64
{4D6155E2-055B-4B0F-85E8-C3A1AAA54C82}.Debug|x64.ActiveCfg = Debug|x64
{4D6155E2-055B-4B0F-85E8-C3A1AAA54C82}.Debug|x64.Build.0 = Debug|x64
{4D6155E2-055B-4B0F-85E8-C3A1AAA54C82}.Release|ARM64.ActiveCfg = Release|ARM64
{4D6155E2-055B-4B0F-85E8-C3A1AAA54C82}.Release|ARM64.Build.0 = Release|ARM64
{4D6155E2-055B-4B0F-85E8-C3A1AAA54C82}.Release|x64.ActiveCfg = Release|x64
{4D6155E2-055B-4B0F-85E8-C3A1AAA54C82}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -2534,6 +2546,8 @@ Global
{4382A954-179A-4078-92AF-715187DFFF50} = {38BDB927-829B-4C65-9CD9-93FB05D66D65}
{EBED240C-8702-452D-B764-6DB9DA9179AF} = {F05E590D-AD46-42BE-9C25-6A63ADD2E3EA}
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0} = {F05E590D-AD46-42BE-9C25-6A63ADD2E3EA}
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC}
{4D6155E2-055B-4B0F-85E8-C3A1AAA54C82} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}

View File

@@ -184,6 +184,10 @@ namespace winrt::PowerToys::GPOWrapper::implementation
{
return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredWorkspacesEnabledValue());
}
GpoRuleConfigured GPOWrapper::GetConfiguredCharacterMapEnabledValue()
{
return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredCharacterMapEnabledValue());
}
GpoRuleConfigured GPOWrapper::GetConfiguredMwbClipboardSharingEnabledValue()
{
return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredMwbClipboardSharingEnabledValue());

View File

@@ -52,6 +52,7 @@ namespace winrt::PowerToys::GPOWrapper::implementation
static GpoRuleConfigured GetAllowedAdvancedPasteOnlineAIModelsValue();
static GpoRuleConfigured GetConfiguredNewPlusEnabledValue();
static GpoRuleConfigured GetConfiguredWorkspacesEnabledValue();
static GpoRuleConfigured GetConfiguredCharacterMapEnabledValue();
static GpoRuleConfigured GetConfiguredMwbClipboardSharingEnabledValue();
static GpoRuleConfigured GetConfiguredMwbFileTransferEnabledValue();
static GpoRuleConfigured GetConfiguredMwbUseOriginalUserInterfaceValue();

View File

@@ -56,6 +56,7 @@ namespace PowerToys
static GpoRuleConfigured GetAllowedAdvancedPasteOnlineAIModelsValue();
static GpoRuleConfigured GetConfiguredNewPlusEnabledValue();
static GpoRuleConfigured GetConfiguredWorkspacesEnabledValue();
static GpoRuleConfigured GetConfiguredCharacterMapEnabledValue();
static GpoRuleConfigured GetConfiguredMwbClipboardSharingEnabledValue();
static GpoRuleConfigured GetConfiguredMwbFileTransferEnabledValue();
static GpoRuleConfigured GetConfiguredMwbUseOriginalUserInterfaceValue();

View File

@@ -128,6 +128,9 @@ namespace CommonSharedConstants
const wchar_t ZOOMIT_REFRESH_SETTINGS_EVENT[] = L"Local\\PowerToysZoomIt-RefreshSettingsEvent-f053a563-d519-4b0d-8152-a54489c13324";
const wchar_t ZOOMIT_EXIT_EVENT[] = L"Local\\PowerToysZoomIt-ExitEvent-36641ce6-df02-4eac-abea-a3fbf9138220";
// Path to the events used by CharacterMap
const wchar_t CHARACTER_MAP_TRIGGER_EVENT[] = L"Local\\PowerToysCharacterMap-TriggerEvent-4c45960f-1b0f-40b9-85a6-789cf45efde1";
// Max DWORD for key code to disable keys.
const DWORD VK_DISABLED = 0x100;
}

View File

@@ -77,6 +77,7 @@ struct LogSettings
inline const static std::string workspacesSnapshotToolLoggerName = "workspaces-snapshot-tool";
inline const static std::wstring workspacesSnapshotToolLogPath = L"workspaces-snapshot-tool-log.txt";
inline const static std::string zoomItLoggerName = "zoom-it";
inline const static std::string characterMapLoggerName = "CharacterMap";
inline const static int retention = 30;
std::wstring logLevel;
LogSettings();

View File

@@ -62,6 +62,7 @@ namespace powertoys_gpo {
const std::wstring POLICY_CONFIGURE_ENABLED_QOI_THUMBNAILS = L"ConfigureEnabledUtilityFileExplorerQOIThumbnails";
const std::wstring POLICY_CONFIGURE_ENABLED_NEWPLUS = L"ConfigureEnabledUtilityNewPlus";
const std::wstring POLICY_CONFIGURE_ENABLED_WORKSPACES = L"ConfigureEnabledUtilityWorkspaces";
const std::wstring POLICY_CONFIGURE_ENABLED_CHARACTERMAP = L"ConfigureEnabledUtilityCharacterMap";
// The registry value names for PowerToys installer and update policies.
const std::wstring POLICY_DISABLE_PER_USER_INSTALLATION = L"PerUserInstallationDisabled";
@@ -455,6 +456,11 @@ namespace powertoys_gpo {
{
return getUtilityEnabledValue(POLICY_CONFIGURE_ENABLED_NEWPLUS);
}
inline gpo_rule_configured_t getConfiguredCharacterMapEnabledValue()
{
return getUtilityEnabledValue(POLICY_CONFIGURE_ENABLED_CHARACTERMAP);
}
#pragma endregion UtilityEnabledStatePolicies
// Individual module setting policies

View File

@@ -465,6 +465,16 @@
<disabledValue>
<decimal value="0" />
</disabledValue>
</policy>
<policy name="ConfigureEnabledUtilityCharacterMap" class="Both" displayName="$(string.ConfigureEnabledUtilityCharacterMap)" explainText="$(string.ConfigureEnabledUtilityDescription)" key="Software\Policies\PowerToys" valueName="ConfigureEnabledUtilityCharacterMap">
<parentCategory ref="PowerToys" />
<supportedOn ref="SUPPORTED_POWERTOYS_0_88_0" />
<enabledValue>
<decimal value="1" />
</enabledValue>
<disabledValue>
<decimal value="0" />
</disabledValue>
</policy>
<policy name="DisablePerUserInstallation" class="Machine" displayName="$(string.DisablePerUserInstallation)" explainText="$(string.DisablePerUserInstallationDescription)" key="Software\Policies\PowerToys" valueName="PerUserInstallationDisabled">
<parentCategory ref="InstallerUpdates" />

View File

@@ -267,6 +267,7 @@ If you don't configure this policy, the user takes control over the setting and
<string id="ConfigureEnabledUtilityTextExtractor">Text Extractor: Configure enabled state</string>
<string id="ConfigureEnabledUtilityVideoConferenceMute">Video Conference Mute: Configure enabled state</string>
<string id="ConfigureEnabledUtilityZoomIt">Zoom It: Configure enabled state</string>
<string id="ConfigureEnabledUtilityCharacterMap">Character Map: Configure enabled state</string>
<string id="DisablePerUserInstallation">Disable per-user installation</string>
<string id="DisableAutomaticUpdateDownload">Disable automatic downloads</string>
<string id="DoNotShowWhatsNewAfterUpdates">Do not show the release notes after updates</string>

View File

@@ -0,0 +1,40 @@
#include <windows.h>
#include "resource.h"
#include "../../../common/version/version.h"
#define APSTUDIO_READONLY_SYMBOLS
#include "winres.h"
#undef APSTUDIO_READONLY_SYMBOLS
1 VERSIONINFO
FILEVERSION FILE_VERSION
PRODUCTVERSION PRODUCT_VERSION
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0" // US English (0x0409), Unicode (0x04B0) charset
BEGIN
VALUE "CompanyName", COMPANY_NAME
VALUE "FileDescription", FILE_DESCRIPTION
VALUE "FileVersion", FILE_VERSION_STRING
VALUE "InternalName", INTERNAL_NAME
VALUE "LegalCopyright", COPYRIGHT_NOTE
VALUE "OriginalFilename", ORIGINAL_FILENAME
VALUE "ProductName", PRODUCT_NAME
VALUE "ProductVersion", PRODUCT_VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200 // US English (0x0409), Unicode (1200) charset
END
END

View File

@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" />
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{4D6155E2-055B-4B0F-85E8-C3A1AAA54C82}</ProjectGuid>
<RootNamespace>CharacterMapModuleInterface</RootNamespace>
<ProjectName>CharacterMapModuleInterface</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets">
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<OutDir>..\..\..\..\$(Platform)\$(Configuration)\</OutDir>
<TargetName>PowerToys.CharacterMapModuleInterface</TargetName>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>..\;$(SolutionDir)src\common\Telemetry;$(SolutionDir)src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="trace.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="CharacterMapModuleInterface.rc" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="trace.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\logger\logger.vcxproj">
<Project>{d9b8fc84-322a-4f9f-bbb9-20915c47ddfd}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\common\SettingsAPI\SettingsAPI.vcxproj">
<Project>{6955446d-23f7-4023-9bb3-8657f904af99}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
</ImportGroup>
<Import Project="..\..\..\..\deps\spdlog.props" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
</Target>
</Project>

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{f5f15d18-c8fd-4f95-9bdd-d7229f26bcfe}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{cf528697-5153-4e00-802d-18b371bbe659}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{88e6c746-6a4b-47a4-b5da-a78a9b3e92f6}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h">
<Filter>Resource Files</Filter>
</ClInclude>
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="trace.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="CharacterMapModuleInterface.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="trace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,270 @@
#include "pch.h"
#include <modules/interface/powertoy_module_interface.h>
#include <common/SettingsAPI/settings_objects.h>
#include "trace.h"
#include <common/logger/logger.h>
#include <common/utils/logger_helper.h>
#include <common/utils/EventWaiter.h>
#include <common/utils/resources.h>
#include <common/utils/winapi_error.h>
#include <shellapi.h>
#include <common/interop/shared_constants.h>
namespace NonLocalizable
{
//const wchar_t ModulePath[] = L"PowerToys.CharacterMap.exe";
const inline wchar_t ModuleKey[] = L"CharacterMap";
}
BOOL APIENTRY DllMain( HMODULE /*hModule*/,
DWORD ul_reason_for_call,
LPVOID /*lpReserved*/
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
Trace::RegisterProvider();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
Trace::UnregisterProvider();
break;
}
return TRUE;
}
class CharacterMapModuleInterface : public PowertoyModuleIface
{
public:
// Return the localized display name of the powertoy
virtual PCWSTR get_name() override
{
return app_name.c_str();
}
// Return the non localized key of the powertoy, this will be cached by the runner
virtual const wchar_t* get_key() override
{
return app_key.c_str();
}
// Return the configured status for the gpo policy for the module
virtual powertoys_gpo::gpo_rule_configured_t gpo_policy_enabled_configuration() override
{
return powertoys_gpo::getConfiguredCharacterMapEnabledValue();
}
// Return JSON with the configuration options.
// These are the settings shown on the settings page along with their current values.
virtual bool get_config(wchar_t* buffer, int* buffer_size) override
{
HINSTANCE hinstance = reinterpret_cast<HINSTANCE>(&__ImageBase);
// TODO: Read settings from Registry.
// Create a Settings object.
PowerToysSettings::Settings settings(hinstance, get_name());
return settings.serialize_to_buffer(buffer, buffer_size);
}
// Passes JSON with the configuration settings for the powertoy.
// This is called when the user hits Save on the settings page.
virtual void set_config(const wchar_t*) override
{
try
{
// Parse the input JSON string.
// TODO: Save settings to registry.
}
catch (std::exception&)
{
// Improper JSON.
}
}
// Enable the powertoy
virtual void enable()
{
Logger::info("CharacterMap enabling");
Enable();
}
// Disable the powertoy
virtual void disable()
{
Logger::info("CharacterMap disabling");
Disable(true);
}
// Returns if the powertoy is enabled
virtual bool is_enabled() override
{
return m_enabled;
}
// Destroy the powertoy and free memory
virtual void destroy() override
{
Disable(false);
delete this;
}
CharacterMapModuleInterface()
{
app_name = L"CharacterMap";
app_key = NonLocalizable::ModuleKey;
LoggerHelpers::init_logger(app_key, L"ModuleInterface", LogSettings::characterMapLoggerName);
//m_reload_settings_event_handle = CreateDefaultEvent(CommonSharedConstants::ZOOMIT_REFRESH_SETTINGS_EVENT);
//m_exit_event_handle = CreateDefaultEvent(CommonSharedConstants::ZOOMIT_EXIT_EVENT);
triggerEvent = CreateEvent(nullptr, false, false, CommonSharedConstants::CHARACTER_MAP_TRIGGER_EVENT);
triggerEventWaiter = EventWaiter(CommonSharedConstants::CHARACTER_MAP_TRIGGER_EVENT, [this](int) {
on_hotkey(0);
});
}
~CharacterMapModuleInterface()
{
if (m_enabled)
{
terminate_process();
}
m_enabled = false;
}
private:
bool is_process_running()
{
return WaitForSingleObject(m_hProcess, 0) == WAIT_TIMEOUT;
}
void launch_process()
{
if (m_enabled)
{
Logger::trace(L"Starting Character Map process");
//Get current process id
unsigned long powertoys_pid = GetCurrentProcessId();
std::wstring executable_args = std::to_wstring(powertoys_pid);
// Initiate SHELLEXECUTEINFOW structure
SHELLEXECUTEINFOW sei{ sizeof(sei) };
sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
sei.lpFile = L"shell:AppsFolder\\PowerToys.CharacterMap_8wekyb3d8bbwe!App"; // UWP App ID
sei.nShow = SW_SHOWNORMAL;
sei.lpParameters = executable_args.c_str();
// start the app
if (ShellExecuteExW(&sei) == FALSE)
{
Logger::error(L"Character Map failed to start. {}", get_last_error_or_default(GetLastError()));
}
else
{
Logger::trace("PowerToys.CharacterMap started successfully!");
m_hProcess = sei.hProcess;
}
}
}
virtual void call_custom_action(const wchar_t* action) override
{
try
{
PowerToysSettings::CustomActionObject action_object =
PowerToysSettings::CustomActionObject::from_json_string(action);
if (action_object.get_name() == L"Launch")
{
launch_process();
Trace::ActivateEditor();
}
}
catch (std::exception&)
{
Logger::error(L"Failed to parse action. {}", action);
}
}
void terminate_process()
{
TerminateProcess(m_hProcess, 1);
}
bool is_enabled_by_default() const override
{
return false;
}
void Enable()
{
m_enabled = true;
// Log telemetry
Trace::EnableCharacterMap(true);
}
void Disable(bool const traceEvent)
{
m_enabled = false;
// Log telemetry
if (traceEvent)
{
Trace::EnableCharacterMap(false);
}
if (m_enabled)
{
// let the DLL disable the app
terminate_process();
Logger::trace(L"Disabling Registry Preview...");
}
m_enabled = false;
}
virtual bool on_hotkey(size_t /*hotkeyId*/) override
{
if (m_enabled)
{
Logger::trace(L"Character Map hotkey pressed");
if (is_process_running())
{
terminate_process();
}
else
{
launch_process();
}
return true;
}
return false;
}
std::wstring app_name;
std::wstring app_key; //contains the non localized key of the powertoy
bool m_enabled = false;
HANDLE m_hProcess = nullptr;
HANDLE triggerEvent;
EventWaiter triggerEventWaiter;
//HANDLE m_reload_settings_event_handle = NULL;
//HANDLE m_exit_event_handle = NULL;
};
extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create()
{
return new CharacterMapModuleInterface();
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Windows.CppWinRT" version="2.0.240111.5" targetFramework="native" />
</packages>

View File

@@ -0,0 +1,5 @@
// pch.cpp: source file corresponding to the pre-compiled header
#include "pch.h"
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.

View File

@@ -0,0 +1,10 @@
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <Unknwn.h>
#include <winrt/base.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <ProjectTelemetry.h>
#include <TraceLoggingActivity.h>

View File

@@ -0,0 +1,13 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by ZoomItModuleInterface.rc
//////////////////////////////
// Non-localizable
#define FILE_DESCRIPTION "PowerToys CharacterMapModuleInterface"
#define INTERNAL_NAME "PowerToys.CharacterMapModuleInterface"
#define ORIGINAL_FILENAME "PowerToys.CharacterMapModuleInterface.dll"
// Non-localizable
//////////////////////////////

View File

@@ -0,0 +1,40 @@
#include "pch.h"
#include "trace.h"
TRACELOGGING_DEFINE_PROVIDER(
g_hProvider,
"Microsoft.PowerToys",
// {38e8889b-9731-53f5-e901-e8a7c1753074}
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
TraceLoggingOptionProjectTelemetry());
void Trace::RegisterProvider()
{
TraceLoggingRegister(g_hProvider);
}
void Trace::UnregisterProvider()
{
TraceLoggingUnregister(g_hProvider);
}
// Log if the user has ZoomIt enabled or disabled
void Trace::EnableCharacterMap(const bool enabled) noexcept
{
TraceLoggingWrite(
g_hProvider,
"EnableCharacterMap_EnableZoomIt",
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
TraceLoggingBoolean(enabled, "Enabled"));
}
// Log that the user tried to activate the app
void Trace::ActivateEditor() noexcept
{
TraceLoggingWrite(
g_hProvider,
"EnableCharacterMap_Activate",
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
}

View File

@@ -0,0 +1,13 @@
#pragma once
class Trace
{
public:
static void RegisterProvider();
static void UnregisterProvider();
// Log if the user has ZoomIt enabled or disabled
static void EnableCharacterMap(const bool enabled) noexcept;
// Log that the user tried to activate the app
static void ActivateEditor() noexcept;
};

View File

@@ -168,12 +168,18 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
{
for (const auto& enabled_element : general_configs.GetNamedObject(L"enabled"))
{
const auto value = enabled_element.Value();
if (value.ValueType() != json::JsonValueType::Boolean)
{
continue;
}
const std::wstring name{ enabled_element.Key().c_str() };
const std::wstring constantTest = L"CharacterMap";
if (name == constantTest)
{
Logger::info(L"apply_general_settings: Disabling powertoy {}", name);
}
const bool found = modules().find(name) != modules().end();
if (!found)
{

View File

@@ -174,6 +174,7 @@ int runner(bool isProcessElevated, bool openSettings, std::string settingsWindow
L"PowerToys.CmdNotFoundModuleInterface.dll",
L"PowerToys.WorkspacesModuleInterface.dll",
L"PowerToys.ZoomItModuleInterface.dll",
L"PowerToys.CharacterMapModuleInterface.dll",
};
for (auto moduleSubdir : knownModules)

View File

@@ -497,6 +497,23 @@ namespace Microsoft.PowerToys.Settings.UI.Library
}
}
private bool characterMap;
[JsonPropertyName("CharacterMap")]
public bool CharacterMap
{
get => characterMap;
set
{
if (characterMap != value)
{
LogTelemetryEvent(value);
characterMap = value;
NotifyChange();
}
}
}
private void NotifyChange()
{
notifyEnabledChangedAction?.Invoke();

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 KiB

View File

@@ -0,0 +1,51 @@
<Page
x:Class="Microsoft.PowerToys.Settings.UI.Views.CharacterMapPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
xmlns:ui="using:CommunityToolkit.WinUI"
AutomationProperties.LandmarkType="Main"
mc:Ignorable="d">
<controls:SettingsPageControl x:Uid="CharacterMap" ModuleImageSource="ms-appx:///Assets/Settings/Modules/CharacterMap.png">
<controls:SettingsPageControl.ModuleContent>
<StackPanel ChildrenTransitions="{StaticResource SettingsCardsAnimations}" Orientation="Vertical">
<tkcontrols:SettingsCard
x:Uid="CharacterMap_Enable_CharacterMap"
HeaderIcon="{ui:BitmapIcon Source=/Assets/Settings/Icons/CharacterMap.png}"
IsEnabled="{x:Bind ViewModel.IsEnabledGpoConfigured, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}">
<ToggleSwitch IsOn="{x:Bind ViewModel.IsCharacterMapEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</tkcontrols:SettingsCard>
<InfoBar
x:Uid="GPO_SettingIsManaged"
IsClosable="False"
IsOpen="{x:Bind ViewModel.IsEnabledGpoConfigured, Mode=OneWay}"
IsTabStop="{x:Bind ViewModel.IsEnabledGpoConfigured, Mode=OneWay}"
Severity="Informational">
<InfoBar.IconSource>
<FontIconSource FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE72E;" />
</InfoBar.IconSource>
</InfoBar>
<controls:SettingsGroup x:Uid="CharacterMap_Launch_GroupSettings" IsEnabled="{x:Bind ViewModel.IsCharacterMapEnabled, Mode=OneWay}">
<tkcontrols:SettingsCard
x:Uid="CharacterMap_LaunchButtonControl"
ActionIcon="{ui:FontIcon Glyph=&#xE8A7;}"
Command="{x:Bind ViewModel.LaunchEventHandler}"
HeaderIcon="{ui:FontIcon Glyph=&#xEA37;}"
IsClickEnabled="True" />
</controls:SettingsGroup>
</StackPanel>
</controls:SettingsPageControl.ModuleContent>
<controls:SettingsPageControl.PrimaryLinks>
<controls:PageLink x:Uid="LearnMore_CharacterMap" Link="https://aka.ms/PowerToysOverview_RegistryPreview" />
</controls:SettingsPageControl.PrimaryLinks>
</controls:SettingsPageControl>
</Page>

View File

@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
{
public sealed partial class CharacterMapPage : Page, IRefreshablePage
{
private CharacterMapViewModel ViewModel { get; set; }
public CharacterMapPage()
{
var settingsUtils = new SettingsUtils();
ViewModel = new CharacterMapViewModel(
settingsUtils,
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
ShellPage.SendDefaultIPCMessage);
DataContext = ViewModel;
InitializeComponent();
}
public void RefreshEnabledState()
{
ViewModel.RefreshEnabledState();
}
}
}

View File

@@ -254,6 +254,10 @@
x:Uid="Shell_RegistryPreview"
helpers:NavHelper.NavigateTo="views:RegistryPreviewPage"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/RegistryPreview.png}" />
<NavigationViewItem
x:Uid="Shell_CharacterMap"
helpers:NavHelper.NavigateTo="views:CharacterMapPage"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/CharacterMap.png}" />
</NavigationViewItem.MenuItems>
</NavigationViewItem>
</NavigationView.MenuItems>

View File

@@ -4008,6 +4008,28 @@ Activate by holding the key for the character you want to add an accent to, then
<data name="Launch_RegistryPreview.Content" xml:space="preserve">
<value>Launch Registry Preview</value>
<comment>"Registry Preview" is the name of the utility</comment>
</data>
<data name="CharacterMap.ModuleDescription" xml:space="preserve">
<value>A utility to find, preview, and insert special characters, Unicode symbols and glyphs.</value>
</data>
<data name="CharacterMap.ModuleTitle" xml:space="preserve">
<value>Character Map</value>
</data>
<data name="Shell_CharacterMap.Content" xml:space="preserve">
<value>Character Map</value>
<comment>Product name: Character Map</comment>
</data>
<data name="CharacterMap_Enable_RegistryPreview.Header" xml:space="preserve">
<value>Enable Character Map</value>
<comment>Character Map is the name of the utility</comment>
</data>
<data name="LearnMore_CharacterMap.Text" xml:space="preserve">
<value>Learn more about Character Map</value>
<comment>Character Map is a product name, do not loc</comment>
</data>
<data name="Launch_CharacterMap.Content" xml:space="preserve">
<value>Launch Character Map</value>
<comment>"Character Map" is the name of the utility</comment>
</data>
<data name="MouseUtils_MouseJump.Header" xml:space="preserve">
<value>Mouse Jump</value>

View File

@@ -0,0 +1,105 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization;
using System.Text.Json;
using global::PowerToys.GPOWrapper;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
using Microsoft.PowerToys.Settings.UI.SerializationContext;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public partial class CharacterMapViewModel : Observable
{
private ISettingsUtils SettingsUtils { get; set; }
private GeneralSettings GeneralSettingsConfig { get; set; }
public ButtonClickCommand LaunchEventHandler => new ButtonClickCommand(Launch);
public CharacterMapViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
{
ArgumentNullException.ThrowIfNull(settingsUtils);
SettingsUtils = settingsUtils;
// To obtain the general settings configurations of PowerToys Settings.
ArgumentNullException.ThrowIfNull(settingsRepository);
GeneralSettingsConfig = settingsRepository.SettingsConfig;
InitializeEnabledValue();
// set the callback functions value to handle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
}
private void InitializeEnabledValue()
{
_enabledGpoRuleConfiguration = GPOWrapper.GetConfiguredCharacterMapEnabledValue();
if (_enabledGpoRuleConfiguration == GpoRuleConfigured.Disabled || _enabledGpoRuleConfiguration == GpoRuleConfigured.Enabled)
{
// Get the enabled state from GPO.
_enabledStateIsGPOConfigured = true;
_isCharacterMapEnabled = _enabledGpoRuleConfiguration == GpoRuleConfigured.Enabled;
}
else
{
_isCharacterMapEnabled = GeneralSettingsConfig.Enabled.CharacterMap;
}
}
public bool IsCharacterMapEnabled
{
get => _isCharacterMapEnabled;
set
{
if (_enabledStateIsGPOConfigured)
{
// If it's GPO configured, shouldn't be able to change this state.
return;
}
if (_isCharacterMapEnabled != value)
{
_isCharacterMapEnabled = value;
OnPropertyChanged(nameof(IsCharacterMapEnabled));
GeneralSettingsConfig.Enabled.CharacterMap = value;
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
SendConfigMSG(outgoing.ToString());
}
}
}
public bool IsEnabledGpoConfigured
{
get => _enabledStateIsGPOConfigured;
}
public void Launch()
{
var actionName = "Launch";
SendConfigMSG("{\"action\":{\"CharacterMap\":{\"action_name\":\"" + actionName + "\", \"value\":\"\"}}}");
}
private Func<string, int> SendConfigMSG { get; }
private GpoRuleConfigured _enabledGpoRuleConfiguration;
private bool _enabledStateIsGPOConfigured;
private bool _isCharacterMapEnabled;
public void RefreshEnabledState()
{
InitializeEnabledValue();
OnPropertyChanged(nameof(IsCharacterMapEnabled));
}
}
}