mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
* Move KBM engine into separate process (#10672) * [KBM] Migrate KBM UI out of the runner (#10709) * Clean up keyboard hook handles (#10817) * [C++ common] Unhandled exception handler (#10821) * [KBM] Use icon in the KeyboardManagerEditor (#10845) * [KBM] Move resources from the Common project to the Editor. (#10844) * KBM Editor tests (#10858) * Rename engine executable (#10868) * clean up (#10870) * [KBM] Changed Editor and libraries output folders (#10871) * [KBM] New logs structure (#10872) * Add unhandled exception handling to the editor (#10874) * [KBM] Trace for edit keyboard window * Logging for XamlBridge message loop * [KBM] Added Editor and Engine to the installer (#10876) * Fix spelling * Interprocess communication logs, remove unnecessary windows message logs * [KBM] Separated telemetry for the engine and editor. (#10889) * [KBM] Editor test project (#10891) * Versions for the engine and the editor (#10897) * Add the editor's and the engine's executables to signing process (#10900) * [KBM editor] Run only one instance, exit when parent process exits (#10890) * [KBM] Force kill editor process to avoid XAML crash (#10907) * [KBM] Force kill editor process to avoid XAML crash * Fix event releasing Co-authored-by: mykhailopylyp <17161067+mykhailopylyp@users.noreply.github.com> * Make the editor dpi aware (#10908) * [KBM] KeyboardManagerCommon refactoring (#10909) * Do not start the process if it is already started (#10910) * logs * Update src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditKeyboardWindow.cpp * Update src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditKeyboardWindow.cpp * [KBM] Rename InitUnhandledExceptionHandler to make it explicit that is for x64 only. We will fix it properly when adding support for ARM64 and add a header with the proper conditional building. * [KBM] rename file/class/variables using camel case * [KBM] Rename "event_locker" -> "EventLocker" * [KBM] rename process_waiter Add a TODO comment * [KBM] rename methods Add TODO comment * [KBM] use uppercase for function names * [KBM] use uppercase for methos, lowercase for properties * [KBM] rename method, make methods private, formatting * [KBM] rename private variables * [KBM] use uppercase for function names * [KBM] Added support to run the editor stand-alone when built in debug mode * Update src/modules/keyboardmanager/KeyboardManagerEditor/KeyboardManagerEditor.cpp * Check success of event creation, comment (#10947) * [KBM] code formatting (#10951) * [KBM] code formatting * Update src/modules/keyboardmanager/KeyboardManagerEditorLibrary/BufferValidationHelpers.cpp * [KBM] tracing * [KBM] Remappings not showing fix. (#10954) * removed mutex * retry loop for reading * retry on reading config once * log error Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> Co-authored-by: Seraphima Zykova <zykovas91@gmail.com> Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> Co-authored-by: Enrico Giordani <enrico.giordani@gmail.com>
160 lines
4.4 KiB
C++
160 lines
4.4 KiB
C++
#include "pch.h"
|
|
|
|
#include <msclr/marshal.h>
|
|
#include <msclr/marshal_cppstd.h>
|
|
#include <functional>
|
|
#include "keyboard_layout.h"
|
|
#include "two_way_pipe_message_ipc.h"
|
|
#include "shared_constants.h"
|
|
|
|
// We cannot use C++/WinRT APIs when compiled with /clr (we'll get a runtime crash). os-detect API is used
|
|
// in both native C++ and C++/CX.
|
|
// We also cannot compile it as a library, since we use different cppruntime linkage in C++/CX and native C++.
|
|
// Therefore the simplest way is to compile these functions as native using the pragmas below.
|
|
#pragma managed(push, off)
|
|
#include "../utils/os-detect.h"
|
|
#pragma managed(pop)
|
|
|
|
#include <common/version/version.h>
|
|
|
|
using namespace System;
|
|
using namespace System::Runtime::InteropServices;
|
|
|
|
// https://docs.microsoft.com/en-us/cpp/dotnet/how-to-wrap-native-class-for-use-by-csharp?view=vs-2019
|
|
namespace interop
|
|
{
|
|
public
|
|
ref class LayoutMapManaged
|
|
{
|
|
public:
|
|
LayoutMapManaged() :
|
|
_map(new LayoutMap) {}
|
|
|
|
~LayoutMapManaged()
|
|
{
|
|
delete _map;
|
|
}
|
|
|
|
String ^ GetKeyName(DWORD key) {
|
|
return gcnew String(_map->GetKeyName(key).c_str());
|
|
}
|
|
|
|
void Updatelayout()
|
|
{
|
|
_map->UpdateLayout();
|
|
}
|
|
|
|
protected:
|
|
!LayoutMapManaged()
|
|
{
|
|
delete _map;
|
|
}
|
|
|
|
private:
|
|
LayoutMap* _map;
|
|
};
|
|
|
|
public
|
|
ref class TwoWayPipeMessageIPCManaged
|
|
{
|
|
public:
|
|
delegate void ReadCallback(String ^ message);
|
|
|
|
TwoWayPipeMessageIPCManaged(String ^ inputPipeName, String ^ outputPipeName, ReadCallback ^ callback)
|
|
{
|
|
_wrapperCallback = gcnew InternalReadCallback(this, &TwoWayPipeMessageIPCManaged::ReadCallbackHelper);
|
|
_callback = callback;
|
|
|
|
TwoWayPipeMessageIPC::callback_function cb = nullptr;
|
|
if (callback != nullptr)
|
|
{
|
|
cb = (TwoWayPipeMessageIPC::callback_function)(void*)Marshal::GetFunctionPointerForDelegate(_wrapperCallback);
|
|
}
|
|
_pipe = new TwoWayPipeMessageIPC(
|
|
msclr::interop::marshal_as<std::wstring>(inputPipeName),
|
|
msclr::interop::marshal_as<std::wstring>(outputPipeName),
|
|
cb);
|
|
}
|
|
|
|
~TwoWayPipeMessageIPCManaged()
|
|
{
|
|
delete _pipe;
|
|
}
|
|
|
|
void Send(String ^ msg)
|
|
{
|
|
_pipe->send(msclr::interop::marshal_as<std::wstring>(msg));
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
_pipe->start(nullptr);
|
|
}
|
|
|
|
void End()
|
|
{
|
|
_pipe->end();
|
|
}
|
|
|
|
protected:
|
|
!TwoWayPipeMessageIPCManaged()
|
|
{
|
|
delete _pipe;
|
|
}
|
|
|
|
private:
|
|
delegate void InternalReadCallback(const std::wstring& msg);
|
|
|
|
TwoWayPipeMessageIPC* _pipe;
|
|
ReadCallback ^ _callback;
|
|
InternalReadCallback ^ _wrapperCallback;
|
|
|
|
void ReadCallbackHelper(const std::wstring& msg)
|
|
{
|
|
_callback(gcnew String(msg.c_str()));
|
|
}
|
|
};
|
|
|
|
public
|
|
ref class CommonManaged
|
|
{
|
|
public:
|
|
static String ^ GetProductVersion() {
|
|
return gcnew String(get_product_version().c_str());
|
|
}
|
|
};
|
|
|
|
public
|
|
ref class Constants
|
|
{
|
|
public:
|
|
literal int VK_WIN_BOTH = CommonSharedConstants::VK_WIN_BOTH;
|
|
|
|
static String ^ AppDataPath() {
|
|
auto localPath = Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData);
|
|
auto powerToysPath = gcnew String(CommonSharedConstants::APPDATA_PATH);
|
|
return System::IO::Path::Combine(localPath, powerToysPath);
|
|
}
|
|
|
|
static String ^ PowerLauncherSharedEvent() {
|
|
return gcnew String(CommonSharedConstants::POWER_LAUNCHER_SHARED_EVENT);
|
|
}
|
|
|
|
static String ^ RunSendSettingsTelemetryEvent() {
|
|
return gcnew String(CommonSharedConstants::RUN_SEND_SETTINGS_TELEMETRY_EVENT);
|
|
}
|
|
|
|
static String ^ ColorPickerSendSettingsTelemetryEvent() {
|
|
return gcnew String(CommonSharedConstants::COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT);
|
|
}
|
|
|
|
static String ^ ShowColorPickerSharedEvent() {
|
|
return gcnew String(CommonSharedConstants::SHOW_COLOR_PICKER_SHARED_EVENT);
|
|
}
|
|
|
|
static String ^ ShowShortcutGuideSharedEvent() {
|
|
return gcnew String(CommonSharedConstants::SHOW_SHORTCUT_GUIDE_SHARED_EVENT);
|
|
}
|
|
};
|
|
}
|