mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
FancyZones and Shortcut Guide initial commit
Co-authored-by: Alexis Campailla <alexis@janeasystems.com> Co-authored-by: Bret Anderson <bretan@microsoft.com> Co-authored-by: Enrico Giordani <enrico.giordani@gmail.com> Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Jeff Bogdan <jeffbog@microsoft.com> Co-authored-by: March Rogers <marchr@microsoft.com> Co-authored-by: Mike Harsh <mharsh@microsoft.com> Co-authored-by: Nachum Bundak <Nachum.Bundak@microsoft.com> Co-authored-by: Oliver Jones <ojones@microsoft.com> Co-authored-by: Patrick Little <plittle@microsoft.com>
This commit is contained in:
committed by
Bartosz Sosnowski
parent
10c5396099
commit
8431b80e48
83
src/runner/powertoy_module.h
Normal file
83
src/runner/powertoy_module.h
Normal file
@@ -0,0 +1,83 @@
|
||||
#pragma once
|
||||
#include "powertoys_events.h"
|
||||
#include <interface/powertoy_module_interface.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
class PowertoyModule;
|
||||
|
||||
struct PowertoyModuleDeleter {
|
||||
void operator()(PowertoyModuleIface* module) {
|
||||
if (module) {
|
||||
powertoys_events().unregister_receiver(module);
|
||||
module->disable();
|
||||
module->destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct PowertoyModuleDLLDeleter {
|
||||
using pointer = HMODULE;
|
||||
void operator()(HMODULE handle) {
|
||||
FreeLibrary(handle);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class PowertoyModule {
|
||||
public:
|
||||
PowertoyModule(PowertoyModuleIface* module, HMODULE handle) : handle(handle), module(module) {
|
||||
if (!module)
|
||||
throw std::runtime_error("Module not initialized");
|
||||
name = module->get_name();
|
||||
auto want_signals = module->get_events();
|
||||
if (want_signals) {
|
||||
for (; *want_signals; ++want_signals) {
|
||||
powertoys_events().register_receiver(*want_signals, module);
|
||||
}
|
||||
}
|
||||
}
|
||||
const std::wstring& get_name() const {
|
||||
return name;
|
||||
}
|
||||
const std::wstring get_config() const {
|
||||
std::wstring result;
|
||||
int size = 0;
|
||||
module->get_config(nullptr, &size);
|
||||
wchar_t *buffer = new wchar_t[size];
|
||||
if (module->get_config(buffer, &size)) {
|
||||
result.assign(buffer);
|
||||
}
|
||||
delete[] buffer;
|
||||
return result;
|
||||
}
|
||||
void set_config(const std::wstring& config) {
|
||||
module->set_config(config.c_str());
|
||||
}
|
||||
void call_custom_action(const std::wstring& action) {
|
||||
module->call_custom_action(action.c_str());
|
||||
}
|
||||
intptr_t signal_event(const std::wstring& signal_event, intptr_t data) {
|
||||
return module->signal_event(signal_event.c_str(), data);
|
||||
}
|
||||
bool is_enabled() {
|
||||
return module->is_enabled();
|
||||
}
|
||||
void enable() {
|
||||
module->enable();
|
||||
}
|
||||
void disable() {
|
||||
module->disable();
|
||||
}
|
||||
private:
|
||||
std::unique_ptr<HMODULE, PowertoyModuleDLLDeleter> handle;
|
||||
std::unique_ptr<PowertoyModuleIface, PowertoyModuleDeleter> module;
|
||||
std::wstring name;
|
||||
};
|
||||
|
||||
|
||||
PowertoyModule load_powertoy(const std::wstring& filename);
|
||||
std::unordered_map<std::wstring, PowertoyModule>& modules();
|
||||
Reference in New Issue
Block a user