1
0
mirror of synced 2024-11-28 17:40:51 +01:00

impr: Automatically remove null provider if another one is opened

This commit is contained in:
WerWolv 2023-12-07 11:20:37 +01:00
parent 00a24bc84b
commit bfb2c6ab5f

View File

@ -1,13 +1,24 @@
#pragma once #pragma once
#include <hex/providers/provider.hpp> #include <hex/providers/provider.hpp>
#include <hex/api/event_manager.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
class NullProvider : public hex::prv::Provider { class NullProvider : public hex::prv::Provider {
public: public:
explicit NullProvider() = default; NullProvider() {
~NullProvider() override = default; EventManager::subscribe<EventProviderOpened>([this](auto *newProvider) {
if (newProvider == this)
return;
ImHexApi::Provider::remove(this, true);
});
}
~NullProvider() override {
EventManager::unsubscribe<EventProviderOpened>(this);
}
[[nodiscard]] bool isAvailable() const override { return true; } [[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool isReadable() const override { return true; } [[nodiscard]] bool isReadable() const override { return true; }