PowerToys/src/runner/powertoy_module.h

50 lines
1.0 KiB
C
Raw Normal View History

#pragma once
#include <interface/powertoy_module_interface.h>
#include <string>
#include <memory>
#include <mutex>
#include <vector>
#include <functional>
#include <common/json.h>
2019-12-27 00:26:11 +08:00
struct PowertoyModuleDeleter
{
void operator()(PowertoyModuleIface* module) const
{
if (module)
{
module->destroy();
}
}
};
2019-12-27 00:26:11 +08:00
struct PowertoyModuleDLLDeleter
{
using pointer = HMODULE;
void operator()(HMODULE handle) const
{
FreeLibrary(handle);
}
};
2019-12-27 00:26:11 +08:00
class PowertoyModule
{
public:
PowertoyModule(PowertoyModuleIface* module, HMODULE handle);
2019-12-27 00:26:11 +08:00
inline PowertoyModuleIface* operator->()
2019-12-27 00:26:11 +08:00
{
return module.get();
}
2019-12-27 00:26:11 +08:00
json::JsonObject json_config() const;
private:
2019-12-27 00:26:11 +08:00
std::unique_ptr<HMODULE, PowertoyModuleDLLDeleter> handle;
std::unique_ptr<PowertoyModuleIface, PowertoyModuleDeleter> module;
};
PowertoyModule load_powertoy(const std::wstring_view filename);
std::map<std::wstring, PowertoyModule>& modules();