From 3932371cd12ae7ec0812fbb2db3315448e18f1a8 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Sun, 11 Oct 2020 21:17:34 +0200 Subject: Use proxy for ModList, PluginList and DownloadManager. Do not use registered callbacks when plugin is inactive. --- src/proxyutils.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/proxyutils.h (limited to 'src/proxyutils.h') diff --git a/src/proxyutils.h b/src/proxyutils.h new file mode 100644 index 00000000..4c1717d8 --- /dev/null +++ b/src/proxyutils.h @@ -0,0 +1,26 @@ +#ifndef PROXYUTILS_H +#define PROXYUTILS_H + +#include + +#include "organizerproxy.h" + +namespace MOShared { + + template + auto callIfPluginActive(OrganizerProxy* proxy, Fn&& callback, T defaultReturn = T{}) { + return [fn = std::forward(callback), proxy, defaultReturn](auto&& ...args) { + if (proxy->plugin()->isActive()) { + return fn(std::forward(args)...); + } + else { + if constexpr (!std::is_same_v, decltype(args)... >, void>) { + return defaultReturn; + } + } + }; + } + +} + +#endif -- cgit v1.3.1