diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-10-11 21:17:34 +0200 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-10-11 21:17:34 +0200 |
| commit | 3932371cd12ae7ec0812fbb2db3315448e18f1a8 (patch) | |
| tree | 9751fce7edd8d6042f3f78bdfecedea520338b83 /src/proxyutils.h | |
| parent | 0363b73adb75714c94a7a7cea2840a9c40ee006e (diff) | |
Use proxy for ModList, PluginList and DownloadManager. Do not use registered callbacks when plugin is inactive.
Diffstat (limited to 'src/proxyutils.h')
| -rw-r--r-- | src/proxyutils.h | 26 |
1 files changed, 26 insertions, 0 deletions
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 <type_traits> + +#include "organizerproxy.h" + +namespace MOShared { + + template <class Fn, class T = int> + auto callIfPluginActive(OrganizerProxy* proxy, Fn&& callback, T defaultReturn = T{}) { + return [fn = std::forward<Fn>(callback), proxy, defaultReturn](auto&& ...args) { + if (proxy->plugin()->isActive()) { + return fn(std::forward<decltype(args)>(args)...); + } + else { + if constexpr (!std::is_same_v<std::invoke_result_t<std::decay_t<Fn>, decltype(args)... >, void>) { + return defaultReturn; + } + } + }; + } + +} + +#endif |
