Fixed PPT exiting

This commit is contained in:
WolverinDEV 2020-08-23 21:52:57 +02:00
parent bc9f313aeb
commit a8b1299c4e
5 changed files with 25 additions and 9 deletions

View File

@ -113,6 +113,14 @@ NAN_MODULE_INIT(init) {
NAN_EXPORT(target, RegisterCallback);
NAN_EXPORT(target, UnregisterCallback);
node::AtExit([](auto){
hook->detach();
std::unique_lock lock{callback_lock};
callbacks.clear();
queued_events.clear();
});
}
NODE_MODULE(MODULE_NAME, init)

View File

@ -6,19 +6,18 @@ using namespace std;
KeyboardHook::KeyboardHook(KeyboardHookType type) : type_{type} {};
KeyboardHook::~KeyboardHook() {
if(this->_attached)
this->detach();
assert(!this->attached_);
}
bool KeyboardHook::attach() {
assert(!this->_attached);
this->_attached = true;
assert(!this->attached_);
this->attached_ = true;
return true;
}
void KeyboardHook::detach() {
assert(this->_attached);
this->_attached = false;
assert(this->attached_);
this->attached_ = false;
}
void KeyboardHook::trigger_key_event(const enum KeyEvent::type& type, const std::string &key) {

View File

@ -48,7 +48,7 @@ class KeyboardHook {
[[nodiscard]] virtual bool keytype_supported() const = 0;
[[nodiscard]] virtual bool attach();
[[nodiscard]] inline bool attached() const { return this->_attached; }
[[nodiscard]] inline bool attached() const { return this->attached_; }
virtual void detach();
void trigger_key_event(const enum KeyEvent::type&, const std::string& /* key */);
@ -59,5 +59,5 @@ class KeyboardHook {
std::map<KeyID, bool> map_key;
std::map<KeyType, KeyID> map_special;
bool _attached = false;
bool attached_ = false;
};

View File

@ -12,6 +12,7 @@ namespace hooks {
class Win32RawHook : public KeyboardHook {
public:
Win32RawHook();
~Win32RawHook() override;
bool attach() override;
void detach() override;
@ -20,6 +21,8 @@ namespace hooks {
private:
static LRESULT CALLBACK window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
void do_detach();
std::thread window_thread;
void window_loop();

View File

@ -8,6 +8,9 @@
namespace hooks {
Win32RawHook::Win32RawHook() : KeyboardHook{KeyboardHookType::RAW_INPUT} {}
Win32RawHook::~Win32RawHook() noexcept {
this->do_detach();
}
bool Win32RawHook::attach() {
if(!KeyboardHook::attach())
@ -26,6 +29,10 @@ namespace hooks {
}
void Win32RawHook::detach() {
this->do_detach();
}
void Win32RawHook::do_detach() {
this->wactive = false;
if(this->hwnd) {
@ -36,7 +43,6 @@ namespace hooks {
this->window_thread.join();
this->set_wstatus(WorkerStatus::STOPPED);
KeyboardHook::detach();
}