Fixed PPT exiting
This commit is contained in:
parent
bc9f313aeb
commit
a8b1299c4e
@ -113,6 +113,14 @@ NAN_MODULE_INIT(init) {
|
|||||||
|
|
||||||
NAN_EXPORT(target, RegisterCallback);
|
NAN_EXPORT(target, RegisterCallback);
|
||||||
NAN_EXPORT(target, UnregisterCallback);
|
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)
|
NODE_MODULE(MODULE_NAME, init)
|
@ -6,19 +6,18 @@ using namespace std;
|
|||||||
KeyboardHook::KeyboardHook(KeyboardHookType type) : type_{type} {};
|
KeyboardHook::KeyboardHook(KeyboardHookType type) : type_{type} {};
|
||||||
|
|
||||||
KeyboardHook::~KeyboardHook() {
|
KeyboardHook::~KeyboardHook() {
|
||||||
if(this->_attached)
|
assert(!this->attached_);
|
||||||
this->detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyboardHook::attach() {
|
bool KeyboardHook::attach() {
|
||||||
assert(!this->_attached);
|
assert(!this->attached_);
|
||||||
this->_attached = true;
|
this->attached_ = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardHook::detach() {
|
void KeyboardHook::detach() {
|
||||||
assert(this->_attached);
|
assert(this->attached_);
|
||||||
this->_attached = false;
|
this->attached_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardHook::trigger_key_event(const enum KeyEvent::type& type, const std::string &key) {
|
void KeyboardHook::trigger_key_event(const enum KeyEvent::type& type, const std::string &key) {
|
||||||
|
@ -48,7 +48,7 @@ class KeyboardHook {
|
|||||||
[[nodiscard]] virtual bool keytype_supported() const = 0;
|
[[nodiscard]] virtual bool keytype_supported() const = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual bool attach();
|
[[nodiscard]] virtual bool attach();
|
||||||
[[nodiscard]] inline bool attached() const { return this->_attached; }
|
[[nodiscard]] inline bool attached() const { return this->attached_; }
|
||||||
virtual void detach();
|
virtual void detach();
|
||||||
|
|
||||||
void trigger_key_event(const enum KeyEvent::type&, const std::string& /* key */);
|
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<KeyID, bool> map_key;
|
||||||
std::map<KeyType, KeyID> map_special;
|
std::map<KeyType, KeyID> map_special;
|
||||||
|
|
||||||
bool _attached = false;
|
bool attached_ = false;
|
||||||
};
|
};
|
@ -12,6 +12,7 @@ namespace hooks {
|
|||||||
class Win32RawHook : public KeyboardHook {
|
class Win32RawHook : public KeyboardHook {
|
||||||
public:
|
public:
|
||||||
Win32RawHook();
|
Win32RawHook();
|
||||||
|
~Win32RawHook() override;
|
||||||
|
|
||||||
bool attach() override;
|
bool attach() override;
|
||||||
void detach() override;
|
void detach() override;
|
||||||
@ -20,6 +21,8 @@ namespace hooks {
|
|||||||
private:
|
private:
|
||||||
static LRESULT CALLBACK window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
|
static LRESULT CALLBACK window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
|
||||||
|
|
||||||
|
void do_detach();
|
||||||
|
|
||||||
std::thread window_thread;
|
std::thread window_thread;
|
||||||
void window_loop();
|
void window_loop();
|
||||||
|
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
namespace hooks {
|
namespace hooks {
|
||||||
Win32RawHook::Win32RawHook() : KeyboardHook{KeyboardHookType::RAW_INPUT} {}
|
Win32RawHook::Win32RawHook() : KeyboardHook{KeyboardHookType::RAW_INPUT} {}
|
||||||
|
Win32RawHook::~Win32RawHook() noexcept {
|
||||||
|
this->do_detach();
|
||||||
|
}
|
||||||
|
|
||||||
bool Win32RawHook::attach() {
|
bool Win32RawHook::attach() {
|
||||||
if(!KeyboardHook::attach())
|
if(!KeyboardHook::attach())
|
||||||
@ -26,6 +29,10 @@ namespace hooks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Win32RawHook::detach() {
|
void Win32RawHook::detach() {
|
||||||
|
this->do_detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Win32RawHook::do_detach() {
|
||||||
this->wactive = false;
|
this->wactive = false;
|
||||||
|
|
||||||
if(this->hwnd) {
|
if(this->hwnd) {
|
||||||
@ -36,7 +43,6 @@ namespace hooks {
|
|||||||
this->window_thread.join();
|
this->window_thread.join();
|
||||||
|
|
||||||
this->set_wstatus(WorkerStatus::STOPPED);
|
this->set_wstatus(WorkerStatus::STOPPED);
|
||||||
|
|
||||||
KeyboardHook::detach();
|
KeyboardHook::detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user