2019-09-05 00:26:26 +08:00
|
|
|
#pragma once
|
|
|
|
#include "powertoys_events.h"
|
2019-11-12 18:48:14 +08:00
|
|
|
#include "system_menu_helper.h"
|
2019-09-05 00:26:26 +08:00
|
|
|
#include <interface/powertoy_module_interface.h>
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include <vector>
|
|
|
|
#include <functional>
|
|
|
|
|
2019-12-06 16:40:23 +08:00
|
|
|
#include <common/json.h>
|
2019-09-05 00:26:26 +08:00
|
|
|
|
2019-12-27 00:26:11 +08:00
|
|
|
struct PowertoyModuleDeleter
|
|
|
|
{
|
|
|
|
void operator()(PowertoyModuleIface* module) const
|
|
|
|
{
|
|
|
|
if (module)
|
|
|
|
{
|
|
|
|
powertoys_events().unregister_system_menu_action(module);
|
|
|
|
powertoys_events().unregister_receiver(module);
|
|
|
|
module->destroy();
|
|
|
|
}
|
2019-09-05 00:26:26 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-27 00:26:11 +08:00
|
|
|
struct PowertoyModuleDLLDeleter
|
|
|
|
{
|
|
|
|
using pointer = HMODULE;
|
|
|
|
void operator()(HMODULE handle) const
|
|
|
|
{
|
|
|
|
FreeLibrary(handle);
|
|
|
|
}
|
2019-09-05 00:26:26 +08:00
|
|
|
};
|
|
|
|
|
2019-12-27 00:26:11 +08:00
|
|
|
class PowertoyModule
|
|
|
|
{
|
2019-09-05 00:26:26 +08:00
|
|
|
public:
|
2020-03-13 17:55:15 +08:00
|
|
|
PowertoyModule(PowertoyModuleIface* module, HMODULE handle);
|
2019-12-27 00:26:11 +08:00
|
|
|
|
2020-03-13 17:55:15 +08:00
|
|
|
inline PowertoyModuleIface* operator->()
|
2019-12-27 00:26:11 +08:00
|
|
|
{
|
2020-03-13 17:55:15 +08:00
|
|
|
return module.get();
|
2019-09-05 00:26:26 +08:00
|
|
|
}
|
2019-12-27 00:26:11 +08:00
|
|
|
|
|
|
|
json::JsonObject json_config() const;
|
|
|
|
|
2019-09-05 00:26:26 +08:00
|
|
|
private:
|
2019-12-27 00:26:11 +08:00
|
|
|
std::unique_ptr<HMODULE, PowertoyModuleDLLDeleter> handle;
|
|
|
|
std::unique_ptr<PowertoyModuleIface, PowertoyModuleDeleter> module;
|
2019-09-05 00:26:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
PowertoyModule load_powertoy(const std::wstring& filename);
|
2019-10-22 14:11:23 +08:00
|
|
|
std::unordered_map<std::wstring, PowertoyModule>& modules();
|